Add flag_state gauge metric tracking flag state changes#67
Merged
Conversation
Expose a Prometheus Gauge 'flag_state' with 'flag' and 'project' labels, set to 1/0 whenever a flag is enabled or disabled via graph actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Adds a Prometheus
Gaugenamedflag_statewith two labels —flagandproject— that is set every time a flag's state changes:enable_flagsets the gauge to 1disable_flagsets the gauge to 0Since the graph actions only receive the flag UUID, a new
get_flag_metric_labels()helper infeatureflags/graph/actions.pyjoinsflagtoprojectto resolve the human-readable names used as label values.Why
Makes the current state of feature flags observable in Prometheus/Grafana, so dashboards and alerts can track when and which flags are toggled per project.
Notes for reviewers
reset_flag/delete_flagintentionally do not touch the gauge: removing series is only best-effort in a per-process registry (other replicas would keep theirs anyway), so the series simply keeps its last value. This keeps the scope to explicit enable/disable transitions.UPDATEexecutes but inside the surrounding transaction, matching how the existing action metrics behave; a rollback after the action could briefly leave the gauge ahead of the database.test_switching_flagnow asserts the gauge value matches the new flag state.