grafana/contribute/feature-toggles.md
Giuseppe Guerra 3387132b9b
Build: Add "gen-feature-toggles" Makefile target (#84803)
* Add Makefile target "make gen-feature-toggles" to generate feature toggles files

* Better output for gen-feature-toggles
2024-03-21 12:04:49 +01:00

1.3 KiB

Feature toggle guide

This guide helps you get started adding your feature behind a feature flag in Grafana.

Steps to adding a feature toggle

  1. Define the feature toggle in registry.go. To see what each feature stage means, look at the comments here. If you are a community member, use the CODEOWNERS file to determine which team owns the package you are updating.
  2. Run the go tests mentioned at the top of this file. This will generate all the additional files needed: toggles_gen for the backend, grafana-data for the frontend, and docs. You can run the test by running make gen-feature-toggles.

How to use it in the code

Once your feature toggle is defined, you can then wrap your feature around a check if the feature flag is enabled on that Grafana instance. Here are examples of how to do that:

  • Backend: Use the IsEnabled function and pass in your feature toggle.
  • Frontend: Check the config for your feature toggle.