From 2b5e1dee91666c013907e7fc05c487fb69fb1027 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Tue, 7 Jun 2022 14:46:44 +0200 Subject: [PATCH] vmagent: update SD duration histogram metric if SD is active (#2677) The change updates histogram for registering SD update duration only SD is considered as `active`. SD is active if at least one scraper for this SD has started. This change supposed to reduce metrics cardinality produced by duration histogram which gets updated even if SD isn't configured. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2671 Signed-off-by: hagen1778 --- lib/promscrape/scraper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/promscrape/scraper.go b/lib/promscrape/scraper.go index a8c7136451..a92d7e36aa 100644 --- a/lib/promscrape/scraper.go +++ b/lib/promscrape/scraper.go @@ -256,7 +256,11 @@ func (scfg *scrapeConfig) run(globalStopCh <-chan struct{}) { sws := scfg.getScrapeWork(cfg, swsPrev) sg.update(sws) swsPrev = sws - scfg.discoveryDuration.UpdateDuration(startTime) + if sg.scrapersStarted.Get() > 0 { + // update duration only if at least one scraper has started + // otherwise this SD is considered as inactive + scfg.discoveryDuration.UpdateDuration(startTime) + } } updateScrapeWork(cfg) atomic.AddInt32(&PendingScrapeConfigs, -1)