Skip to content

Commit fbd46e9

Browse files
committed
Remove flagger_canary_status metric after a canary is deleted
Signed-off-by: AlbertoSH <alberto.sanz.herrero@gmail.com>
1 parent 3a27fd1 commit fbd46e9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/controller/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ func (c *Controller) syncHandler(key string) error {
296296
return nil
297297
}
298298

299+
// Clean the metrics if marked for deletion
300+
if cd.ObjectMeta.DeletionTimestamp != nil {
301+
c.recorder.DeleteStatus(cd)
302+
}
303+
299304
// set status condition for new canaries
300305
if cd.Status.Conditions == nil {
301306
if err := c.setPhaseInitializing(cd); err != nil {

pkg/metrics/recorder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ func (cr *Recorder) IncFailures(labels CanaryMetricLabels) {
186186
cr.failures.WithLabelValues(labels.Values()...).Inc()
187187
}
188188

189+
// DeleteStatus deletes the canary analysis status
190+
func (cr *Recorder) DeleteStatus(cd *flaggerv1.Canary) {
191+
cr.status.DeleteLabelValues(cd.Spec.TargetRef.Name, cd.Namespace)
192+
}
193+
189194
// GetStatusMetric returns the status metric
190195
func (cr *Recorder) GetStatusMetric() *prometheus.GaugeVec {
191196
return cr.status

0 commit comments

Comments
 (0)