From 3f57d4d489cb0b06f6d864b4b24ca585bbfededa Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Mon, 27 Feb 2023 23:53:53 +0400 Subject: [PATCH] lib/promscrape: correctly register `vm_promscrape_config_*` metrics (#3876) * lib/promscrape: set `vm_promscrape_config_last_reload_successful` to 1 if there was no promscrape config provided Signed-off-by: Zakhar Bessarab * lib/promscrape: register `vm_promscrape_config_*` metrics only in case promscrape config is used Signed-off-by: Zakhar Bessarab --------- Signed-off-by: Zakhar Bessarab Co-authored-by: Aliaksandr Valialkin --- docs/CHANGELOG.md | 1 + lib/promscrape/scraper.go | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2058a9dd0..c3a887417 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,6 +15,7 @@ The following tip changes can be tested by building VictoriaMetrics components f ## v1.87.x long-time support release (LTS) +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): do not register `vm_promscrape_config_*` metrics if `-promscrape.config` flag is not used. Previously those metrics were registered and never updated, which was confusing and could trigger false-positive alerts. * BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl.html): skip measurements with no fields when migrating data from influxdb. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3837). ## [v1.87.2](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.87.2) diff --git a/lib/promscrape/scraper.go b/lib/promscrape/scraper.go index 0686e47c2..ff1666b78 100644 --- a/lib/promscrape/scraper.go +++ b/lib/promscrape/scraper.go @@ -102,6 +102,8 @@ func runScraper(configFile string, pushData func(at *auth.Token, wr *prompbmarsh return } + metrics.RegisterSet(configMetricsSet) + // Register SIGHUP handler for config reload before loadConfig. // This guarantees that the config will be re-read if the signal arrives just after loadConfig. // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1240 @@ -198,10 +200,11 @@ func runScraper(configFile string, pushData func(at *auth.Token, wr *prompbmarsh } var ( - configReloads = metrics.NewCounter(`vm_promscrape_config_reloads_total`) - configReloadErrors = metrics.NewCounter(`vm_promscrape_config_reloads_errors_total`) - configSuccess = metrics.NewCounter(`vm_promscrape_config_last_reload_successful`) - configTimestamp = metrics.NewCounter(`vm_promscrape_config_last_reload_success_timestamp_seconds`) + configMetricsSet = metrics.NewSet() + configReloads = configMetricsSet.NewCounter(`vm_promscrape_config_reloads_total`) + configReloadErrors = configMetricsSet.NewCounter(`vm_promscrape_config_reloads_errors_total`) + configSuccess = configMetricsSet.NewCounter(`vm_promscrape_config_last_reload_successful`) + configTimestamp = configMetricsSet.NewCounter(`vm_promscrape_config_last_reload_success_timestamp_seconds`) ) type scrapeConfigs struct {