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 GitHub
parent 2460e0f51e
commit a7e29c38bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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__.