Factory.ai

Open-Source Wikis

/

Grafana

/

Backend

/

Feature management

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

  1. Add a new entry to standardFeatureFlags in pkg/services/featuremgmt/registry.go with a name, description, owner, and stage.
  2. Run make gen-feature-toggles.
  3. 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:

  1. Change the Stage in registry.go from PublicPreview to GA.
  2. Set Expression: "true" so the toggle defaults to on.
  3. Update the toggles_gen.csv to record the date.
  4. 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.

Feature management – Grafana wiki | Factory