From b564729d7537e693ab5a3c825bef14e48afc6f74 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 14 Feb 2024 03:24:42 +0200 Subject: [PATCH] lib/promscrape: avoid copying labels when -promscrape.dropOriginalLabels command-line flag is set This should save some CPU This regression has been introduced in 487f6380d0b4f131fef6f5889e0b262d70f31b6e when working on https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5389 --- lib/promscrape/config.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 323395c0a..3158d0b24 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -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()