Skip to content

metrics: fix stale Prometheus gauge labels after label change - #1561

Draft
RamavathChanti wants to merge 1 commit into
flatcar:mainfrom
RamavathChanti:fix-stale-gauge-labels-v2
Draft

metrics: fix stale Prometheus gauge labels after label change#1561
RamavathChanti wants to merge 1 commit into
flatcar:mainfrom
RamavathChanti:fix-stale-gauge-labels-v2

Conversation

@RamavathChanti

Copy link
Copy Markdown

Description

Nebraska's calculateMetrics() sets gauge values each tick but never
clears old label combinations. When an application is renamed, a group's
channel changes, or all instances update away from a version, the old
label series freeze at their last value forever until process restarts.

This causes sum(nebraska_application_instances_per_channel) to report
double the real count after a rename, and stale per-version rows that
never disappear from dashboards.

Fix

Add GaugeVec.Reset() before each gauge update loop. Drops all existing
series, then the loop recreates only what the current DB query returns.

Applied to:

  • nebraska_application_instances_per_channel
  • nebraska_failed_updates
  • All 8 nebraska_group_* rollout progress metrics

Changes

  • backend/pkg/metrics/metrics.go - added Reset() before each gauge update loop
  • backend/pkg/metrics/metrics_test.go (new) - 4 unit tests covering the fix

How to use

cd backend && go test -v ./pkg/metrics/

Fixes #1482

Prometheus gauges kept old label combinations indefinitely when an
application was renamed, a group's channel changed, or instances
updated away from a version. The stale labels froze at their last
value, causing incorrect sum() aggregations and misleading dashboards.

Add GaugeVec.Reset() before each metrics update loop to clear stale
label combinations. This is the standard Prometheus Go client pattern
for gauges with dynamic labels.

Applied to:
- nebraska_application_instances_per_channel
- nebraska_failed_updates
- All 8 nebraska_group_* rollout progress metrics

Fixes flatcar#1482

Signed-off-by: Chanti <chantib107@gmail.com>
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.

metrics: fix stale Prometheus gauge labels after label change

1 participant