Skip to content

Add flag_state gauge metric tracking flag state changes#67

Merged
kindermax merged 1 commit into
mainfrom
claude/optimistic-pare-62e1b5
Jun 10, 2026
Merged

Add flag_state gauge metric tracking flag state changes#67
kindermax merged 1 commit into
mainfrom
claude/optimistic-pare-62e1b5

Conversation

@kindermax

Copy link
Copy Markdown
Contributor

What changed

Adds a Prometheus Gauge named flag_state with two labels — flag and project — that is set every time a flag's state changes:

  • enable_flag sets the gauge to 1
  • disable_flag sets the gauge to 0

Since the graph actions only receive the flag UUID, a new get_flag_metric_labels() helper in featureflags/graph/actions.py joins flag to project to 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_flag intentionally 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.
  • The gauge is set after the UPDATE executes 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.
  • Tests: test_switching_flag now asserts the gauge value matches the new flag state.
  • Verified: full suite (83 passed) plus ruff/black/mypy clean on the changed files.

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.
@kindermax
kindermax merged commit 3da027b into main Jun 10, 2026
1 check passed
@kindermax
kindermax deleted the claude/optimistic-pare-62e1b5 branch June 10, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant