grafana/grafana
Feature management
pkg/services/featuremgmt/ defines and evaluates feature toggles. There are over 200 toggles at any given time (see registry.go — this is one of the largest single Go files in the repo).
Layout
pkg/services/featuremgmt/
├── registry.go # The list of toggles (source of truth)
├── manager.go # Evaluator + service entry point
├── models.go # FeatureToggle struct + stage constants
├── service.go # Wire ProvideService(...)
├── strcase/ # snake_case ↔ camelCase helpers
├── toggles_gen.go # Generated: typed constants for Go
├── toggles_gen.csv # Generated: stage tracking
├── toggles_gen.json # Generated: full export
└── ...The toggles_gen.* files (and packages/grafana-data/src/types/featureToggles.gen.ts for TS) are regenerated by make gen-feature-toggles. They are the most-churned files in the repo.
Toggle stages
A toggle is declared with a stage:
Experimental— internal, off by default, may break.PrivatePreview— Grafana Labs internal preview.PublicPreview— externally available preview, off by default.GA— generally available, on by default.Deprecated— replaced by something else; kept for backwards compatibility.
Reading toggles
// Backend
features.IsEnabled(ctx, featuremgmt.FlagFooBar)
features.IsEnabledGlobally(featuremgmt.FlagFooBar) // when no ctx is available// Frontend
import { config } from '@grafana/runtime';
if (config.featureToggles.fooBar) {
/* ... */
}Adding a toggle
- Add a new entry to
standardFeatureFlagsinpkg/services/featuremgmt/registry.gowith a name, description, owner, and stage. - Run
make gen-feature-toggles. - Commit the regenerated files.
The generator validates that the toggle name is a valid Go identifier, that the owner is a real squad, and that the stage is set.
Configuration
User overrides come from [feature_toggles] enable = a, b, c in custom.ini or via [feature_toggles] <name> = true|false per-toggle. In Grafana Cloud / Enterprise, toggles can also be controlled via the gcom integration.
Stages workflow
The CSV (toggles_gen.csv) tracks each toggle's history of stage transitions over time and is used to enforce the lifecycle: experimental → public preview → GA → deprecated/removed. Each stage transition is reflected in the Stage field of the registry entry plus a date in the CSV.
Promoting a toggle to GA
The promotion flow:
- Change the
Stageinregistry.gofromPublicPreviewtoGA. - Set
Expression: "true"so the toggle defaults to on. - Update the
toggles_gen.csvto record the date. - Run
make gen-feature-toggles.
Removing a deprecated toggle is the inverse — delete the entry, regenerate, fix any callers that still reference the constant.
Key source files
| File | Purpose |
|---|---|
pkg/services/featuremgmt/registry.go |
Source of truth for all toggles |
pkg/services/featuremgmt/manager.go |
Evaluator |
pkg/services/featuremgmt/toggles_gen.go |
Generated Flag* constants |
packages/grafana-data/src/types/featureToggles.gen.ts |
Generated TS type |
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.
Previous
Live
Next
Frontend