From a1076abcbf0f3bee2b55af4d53c6bee8e4d671c0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 5 Jan 2023 02:49:26 -0800 Subject: [PATCH] lib/promscrape: follow-up for a7e29c38bc232a633fd6a89e953f07809281380f - Document the bugfix at docs/CHANGELOG.md - Make the fix more durable against future changes when droppedTargetsMap.Register may be called from other places. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3580 --- docs/CHANGELOG.md | 1 + lib/promscrape/config.go | 8 ++------ lib/promscrape/targetstatus.go | 6 +++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6d105d2ac..a27d52716 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -27,6 +27,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly update tooltip when quickly hovering multiple lines on the graph. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3530). * BUGFIX: properly parse floating-point numbers without integer or fractional parts such as `.123` and `20.` during [data import](https://docs.victoriametrics.com/#how-to-import-time-series-data). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3544). * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly parse durations with uppercase suffixes such as `10S`, `5MS`, `1W`, etc. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3589). +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): fix a panic during target discovery when `vmagent` runs with `-promscrape.dropOriginalLabels` command-line flag. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3580). The bug has been introduced in [v1.85.0](https://docs.victoriametrics.com/CHANGELOG.html#v1850). ## [v1.85.3](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.85.3) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 8a8358288..1df85a8de 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -1186,9 +1186,7 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel } if labels.Len() == 0 { // Drop target without labels. - if !*dropOriginalLabels { - droppedTargetsMap.Register(originalLabels, swc.relabelConfigs) - } + droppedTargetsMap.Register(originalLabels, swc.relabelConfigs) return nil, nil } // See https://www.robustperception.io/life-of-a-label @@ -1203,9 +1201,7 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel address := labels.Get("__address__") if len(address) == 0 { // Drop target without scrape address. - if !*dropOriginalLabels { - droppedTargetsMap.Register(originalLabels, swc.relabelConfigs) - } + droppedTargetsMap.Register(originalLabels, swc.relabelConfigs) return nil, nil } // Usability extension to Prometheus behavior: extract optional scheme and metricsPath from __address__. diff --git a/lib/promscrape/targetstatus.go b/lib/promscrape/targetstatus.go index bf220f7c4..c9f6e32d1 100644 --- a/lib/promscrape/targetstatus.go +++ b/lib/promscrape/targetstatus.go @@ -276,6 +276,10 @@ func (dt *droppedTargets) getTargetsList() []droppedTarget { } func (dt *droppedTargets) Register(originalLabels *promutils.Labels, relabelConfigs *promrelabel.ParsedConfigs) { + if *dropOriginalLabels { + // The originalLabels must be dropped, so do not register it. + return + } // It is better to have hash collisions instead of spending additional CPU on originalLabels.String() call. key := labelsHash(originalLabels) currentTime := fasttime.UnixTimestamp() @@ -301,7 +305,7 @@ func (dt *droppedTargets) Register(originalLabels *promutils.Labels, relabelConf func labelsHash(labels *promutils.Labels) uint64 { d := xxhashPool.Get().(*xxhash.Digest) - for _, label := range labels.Labels { + for _, label := range labels.GetLabels() { _, _ = d.WriteString(label.Name) _, _ = d.WriteString(label.Value) }