From baf88bdc7813c837a02578ab3850ee331aaed83d Mon Sep 17 00:00:00 2001 From: Dominic Evans Date: Fri, 3 Jul 2020 11:24:12 +0000 Subject: [PATCH] fix: reset gauge in-between collect() calls It looks like in the `collect()` loop the `dsl_status` gauge is latched to 1 with the current status label set ```go c.status.WithLabelValues( c.host, c.identifier, status.DSLCfg.Status, status.DSLCfg.Modulation, status.DSLCfg.DataPath).Set(1) ``` However, this means that all historically seen statuses are latched to 1 and never reset to 0: ``` dsl_status{dataPath="",host="192.168.2.1",identifier="BT",modulation="",status="EstablishingLink"} 1 dsl_status{dataPath="",host="192.168.2.1",identifier="BT",modulation="",status="Initializing"} 1 dsl_status{dataPath="",host="192.168.2.1",identifier="BT",modulation="",status="NoSignal"} 1 ``` Ideally in the `collect()` loop it would loop over all known status values and set them to 0 for the ongoing publishes when the status has changed. However, as a simpler workaround in this commit we just call `.Reset()` on the gauge before the call to `.Set(1)` and that stops publishing the metric label for the old statuses --- internal/metrics/dsl.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/metrics/dsl.go b/internal/metrics/dsl.go index e446397..5b9053d 100644 --- a/internal/metrics/dsl.go +++ b/internal/metrics/dsl.go @@ -261,6 +261,7 @@ func (c dslMetricsCollector) collect() error { return errors.Wrap(err, "error getting dsl status") } + c.status.Reset() c.status.WithLabelValues(c.host, c.identifier, status.DSLCfg.Status, status.DSLCfg.Modulation, status.DSLCfg.DataPath).Set(1) c.upCurrRate.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.UpCurrRate))