lib/promscrape/targetstatus: fix crash during droppedTarget registration (#3595)

* lib/promscrape/targetstatus: fix crash during droppedTarget registration in case original labels are not present

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

* lib/promscrape/targetstatus: address review comment

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
This commit is contained in:
Zakhar Bessarab 2023-01-05 14:39:31 +04:00 committed by Aliaksandr Valialkin
parent 802febab74
commit 52226c392f
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -1186,7 +1186,9 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
}
if labels.Len() == 0 {
// Drop target without labels.
droppedTargetsMap.Register(originalLabels, swc.relabelConfigs)
if !*dropOriginalLabels {
droppedTargetsMap.Register(originalLabels, swc.relabelConfigs)
}
return nil, nil
}
// See https://www.robustperception.io/life-of-a-label
@ -1201,7 +1203,9 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
address := labels.Get("__address__")
if len(address) == 0 {
// Drop target without scrape address.
droppedTargetsMap.Register(originalLabels, swc.relabelConfigs)
if !*dropOriginalLabels {
droppedTargetsMap.Register(originalLabels, swc.relabelConfigs)
}
return nil, nil
}
// Usability extension to Prometheus behavior: extract optional scheme and metricsPath from __address__.