From 276dbc2133b6d06f429e3c3c003e56ff6aa5b443 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 7 Apr 2021 21:54:06 +0300 Subject: [PATCH] lib/promscrape: do not spend CPU time on constructing scrapeWork key if clustering is disabled --- lib/promscrape/config.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 1f93c4be57..059291277f 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -795,12 +795,15 @@ func appendSortedKeyValuePairs(dst []byte, m map[string]string) []byte { var scrapeWorkKeyBufPool bytesutil.ByteBufferPool func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabels map[string]string) (*ScrapeWork, error) { - // Verify whether the scrape work must be skipped. - bb := scrapeWorkKeyBufPool.Get() - defer scrapeWorkKeyBufPool.Put(bb) - bb.B = appendScrapeWorkKey(bb.B[:0], target, extraLabels, metaLabels) - if needSkipScrapeWork(bytesutil.ToUnsafeString(bb.B), *clusterMembersCount, *clusterReplicationFactor, *clusterMemberNum) { - return nil, nil + // Verify whether the scrape work must be skipped because of `-promscrape.cluster.*` configs. + if *clusterMembersCount > 1 { + bb := scrapeWorkKeyBufPool.Get() + bb.B = appendScrapeWorkKey(bb.B[:0], target, extraLabels, metaLabels) + needSkip := needSkipScrapeWork(bytesutil.ToUnsafeString(bb.B), *clusterMembersCount, *clusterReplicationFactor, *clusterMemberNum) + scrapeWorkKeyBufPool.Put(bb) + if needSkip { + return nil, nil + } } labels := mergeLabels(swc.jobName, swc.scheme, target, swc.metricsPath, extraLabels, swc.externalLabels, metaLabels, swc.params)