metrics: add canary label to metrics and clean up stale series on canary/namespace removal - #1961
metrics: add canary label to metrics and clean up stale series on canary/namespace removal#1961dkulchinsky wants to merge 3 commits into
Conversation
… canary/namespace removal Signed-off-by: Danny Kulchinsky <dkulchinsky@fastly.com>
4dfcd26 to
fb03c3c
Compare
|
After further review, I realized as such, I've changed my proposal in this PR to the following:
We end up with the following set of labels per metric:
Adding a label is additive, not breaking: every existing time series retains all of its current labels and values, so existing queries, dashboards, recording rules, and alerts that select on name/namespace/workload continue to match exactly as before. Prometheus treats the new label as just another dimension; nothing that previously worked stops working. What it buys us is a stable, consistent identity key across every canary metric. Today the name label actually carries the target workload name ( The canary label fixes that by exposing the Canary resource name uniformly on all six metrics. Concretely, it enables clean joins like: without having to reason about whether name means the workload or the resource in each metric. Cost is negligible: cardinality is unchanged in practice, we're simply adding an additional static label to existing metrics so no new/unbound dimensions. Net: low risk, no migration required for existing consumers, and it gives us a durable correlation key going forward. If maintainers prefer different naming (e.g. standardizing on workload for the target and reserving name for the resource), that's a separate, orthogonal discussion — this change doesn't foreclose it. the additional changes to cleanup metric registry when canaries are deleted remain largely unchanged. |
…ary resource name Signed-off-by: Danny Kulchinsky <dkulchinsky@fastly.com>
0a507f1 to
b521c9f
Compare
Signed-off-by: Danny Kulchinsky <dkulchinsky@fastly.com>
cd56016 to
260a2ad
Compare
|
folks, apologies for piling on here, but just another small commit addressing the metrics area: 260a2ad emits I'm happy to split up these changes into separate PRs if you prefer, I've kept them in separate commits for now. |
Summary
fixes #1960
ThreeFour related fixes to Flagger's Prometheus metrics:flagger_canary_*metrics gain acanarylabel. Thecanarylabel will be the Canary resource name (cd.Name) and will be consistent across all metrics, which allows for a stable key to be used across all the metrics. Final result:flagger_canary_statuscanary,name,namespaceflagger_canary_duration_secondscanary,name,namespaceflagger_canary_metric_analysiscanary,name,namespace,metricflagger_canary_weightcanary,workload,namespaceflagger_canary_successes_totalcanary,name,namespace,deployment_strategy,analysis_statusflagger_canary_failures_totalcanary,name,namespace,deployment_strategy,analysis_statusPer-canary series are cleaned up on Canary deletion. The controller's
DeleteFunconly removed the canary from an in-memory job map; the Prometheus series lived for the process lifetime. A newRecorder.DeleteFor(name, namespace)callsDeletePartialMatch({name, namespace})on every per-canary vec (duration,status,weight,analysis,successes,failures) and is invoked fromDeleteFunc.flagger_canary_totalis cleaned up when a namespace no longer has any canaries.scheduleCanariespreviously only wrote totals for namespaces that currently held canaries, so a namespace that dropped to zero kept its last value forever. The controller now tracks reported namespaces and callsRecorder.DeleteTotalFor(namespace)for any that fall out on the next tick.Emit
flagger_canary_weightin steady state so it survives restarts and appears right after initialization — previously it was only set while a canary was progressing, leaving initialized/succeeded canaries (and everything after a controller restart) without a weight series until the next rollout. The!shouldAdvancepath now also reads the current routes and callsSetWeight, with a regression test asserting the gauge is present for a freshly-initialized canary.Behaviour changes to be aware of
canarylabel is added to allflagger_canary_*metricsflagger_canary_successes_totalandflagger_canary_failures_total.flagger_canary_weightmetric is populated as soon as the canary is initialized and when flagger restarts.Tests
scheduler_metrics_test.goweight assertions for the new label.TestRecorder_DeleteForandTestRecorder_DeleteTotalForinpkg/metrics/recorder_test.go.go test ./pkg/metrics/... ./pkg/controller/...passes.