lib/promscrape: avoid copying labels when -promscrape.dropOriginalLabels command-line flag is set

This should save some CPU

This regression has been introduced in 487f6380d0
when working on https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5389
This commit is contained in:
Aliaksandr Valialkin 2024-02-14 03:24:42 +02:00
parent 9df42f000d
commit 61608b6303
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -1077,7 +1077,10 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
defer promutils.PutLabels(labels)
mergeLabels(labels, swc, target, extraLabels, metaLabels)
originalLabels := labels.Clone()
var originalLabels *promutils.Labels
if !*dropOriginalLabels {
originalLabels = labels.Clone()
}
labels.Labels = swc.relabelConfigs.Apply(labels.Labels, 0)
// Remove labels starting from "__meta_" prefix according to https://www.robustperception.io/life-of-a-label/
labels.RemoveMetaLabels()
@ -1212,7 +1215,7 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
}
func sortOriginalLabelsIfNeeded(originalLabels *promutils.Labels) *promutils.Labels {
if *dropOriginalLabels {
if originalLabels == nil {
return nil
}
originalLabels.Sort()