Skip to content

Commit 86c2cd5

Browse files
author
Supreeth Basabattini
committed
fix: delete metric instead of the vector
1 parent fe70c68 commit 86c2cd5

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

internal/metrics/recorder.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ func NewRecorder(register bool, clusterId string) *Recorder {
8787
Name: "addon_operator_addon_health_info",
8888
Help: "Addon Health information",
8989
ConstLabels: prometheus.Labels{"_id": clusterId},
90-
}, []string{"name", "version", "reason"},
90+
}, []string{
91+
"name",
92+
"version",
93+
"reason",
94+
},
9195
)
9296

9397
// Register metrics if `register` is true
@@ -240,13 +244,14 @@ func (r *Recorder) RecordAddonMetrics(addon *addonsv1alpha1.Addon) {
240244
}
241245

242246
func (r *Recorder) recordAddonHealthInfo(addon *addonsv1alpha1.Addon) {
243-
// cleanup the gauge metric; deduplication
244-
r.addonHealthInfo.Reset()
245-
246247
var (
247248
// `healthStatus` defaults to unknown unless status conditions say otherwise
248249
healthStatus = 2
249250
healthReason = "Unknown"
251+
252+
// default value when addon version is missing
253+
// This will be recorded only once
254+
addonVersion = "0.0.0"
250255
)
251256

252257
// healthCond defines the addon's availability
@@ -265,14 +270,15 @@ func (r *Recorder) recordAddonHealthInfo(addon *addonsv1alpha1.Addon) {
265270

266271
}
267272

268-
// default value when addon version is missing
269-
// This will be recorded only once
270-
addonVersion := "0.0.0"
271-
272273
if addon.Status.ObservedVersion != "" {
273274
addonVersion = addon.Status.ObservedVersion
274275
}
275276

277+
// Drop metric when state changes of the same addon; de-duplication
278+
r.addonHealthInfo.DeletePartialMatch(prometheus.Labels{
279+
"name": addon.Name,
280+
})
281+
276282
r.addonHealthInfo.WithLabelValues(
277283
addon.Name,
278284
addonVersion,

0 commit comments

Comments
 (0)