Chuyển tới nội dung chính

Feature toggles

White-label deploy hiếm khi ship mọi capability. Feature toggles cho phép operator turn main product features on/off — at deploy time via config, or later at runtime, no redeploy. All features default enabled; deployment chỉ lists ones nó change.

Model​

  • Core.Features.FeatureFlag — enum của gateable features: Authoring, Backtesting, Execution, CopyTrading, Ai, PortfolioAgent, Alerts, PropGuard, PropFirm, Accounts, OpenApi, Mcp, Compliance. Core admin surfaces (dashboard, users, nodes, auth) never gateable, not here.
  • Core.Options.FeaturesOptions — config baseline, bound from App:Features. Mọi property defaults true.
  • Core.Features.IFeatureGate — resolves effective state: config baseline overlaid với optional owner-set runtime override. Implemented by Infrastructure.Features.FeatureGate, caches overrides briefly (FeatureSettings.OverrideCacheTtl), invalidates on change.

Runtime overrides stored as AppSetting rows keyed feature.<FeatureFlag> (value true/false). No row = "use config baseline".

Hai cách để disable a feature​

1. Deployment configuration (baseline)​

Set flag false under App:Features. Ví dụ appsettings.json:

{
"App": {
"Features": {
"CopyTrading": false,
"PropGuard": false
}
}
}

Or via env vars (double underscore):

App__Features__CopyTrading=false

Baseline gates startup registration của background workers (Nodes.AddNodes) và MCP tools (Mcp server), vì vậy feature disabled in config never starts its hosted services nor exposes its MCP tools.

2. Runtime override (owner)​

Owner có thể flip bất kỳ feature live từ Settings → Features (/settings/features) hoặc API:

GET /api/features -> [{ "flag": "CopyTrading", "enabled": true }, ...] (Owner)
PUT /api/features/{flag} body { "enabled": false } -> set override (Owner)
PUT /api/features/{flag} body { "enabled": null } -> clear override (revert) (Owner)

Runtime changes take effect immediately cho request-time gates (navigation, API). Background workers và MCP tools gated at startup, pick up runtime change on next process restart.

Mỗi gate enforce gì​

LayerMechanismTiming
HTTP APIRouteGroupBuilder.RequireFeature(flag) endpoint filter → 404 when disabledRuntime
NavigationNavMenu hides links via IFeatureGate.IsEnabledRuntime
Background workersconditional AddHostedService in Nodes.AddNodesStartup (config)
MCP toolsconditional WithTools<> in MCP serverStartup (config)

Feature reached by deep link while disabled renders empty page — its API returns 404; nav no longer surfaces it.

Flag → surface map​

FlagAPI groupsNavWorkers / MCP
Authoring/api/cbots, /api/paramsets, /api/buildercBots group → cBots (param sets per-cBot dialog)MCP CBotTools
Backtesting(shares /api/instances)cBots group → Backtest—
Execution/api/instancescBots group → RunMCP InstanceTools
CopyTrading/api/copyCopy TradingCopyEngineSupervisor, OpenApiTokenRefreshService, MCP CopyTools
Ai/api/aiAI group → AI; Settings → AI (key)AiRiskGuard, MCP AiTools
PortfolioAgent/api/agentAI group → Portfolio AgentPortfolioAgentService
Alerts/api/alertsAI group → AlertsAlertEvaluator
PropGuard/api/propProp group → Prop GuardPropGuardService
PropFirm/api/prop-firmProp group → Challenges—
Accounts/api/ctidsTrading Accounts—
OpenApi/api/openapiSettings → Open API—
Mcp/api/mcp-keysAI group → MCP Keys—
Compliance/api/complianceSettings → Legal & Privacy—

Tests​

  • Unit — UnitTests/Features/FeaturesOptionsTests.cs: baseline defaults, per-flag mapping.
  • Integration — IntegrationTests/FeatureGateTests.cs: config baseline, runtime override beats config và persists as AppSetting, clearing reverts to baseline (real Postgres).
  • E2E — E2ETests/FeatureToggleTests.cs: disabling CopyTrading at runtime hides its nav link và 404s /api/copy, re-enabling restores both.