From f095c33da12958b5d92a7d857264fafb8d4c549a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 20 Nov 2023 19:28:05 +0000 Subject: [PATCH] scrape: simplify TargetsActive function Since everything was serialized on a single mutex, it's exactly the same if we process targets in sequence without starting goroutines. Signed-off-by: Bryan Boreham --- scrape/manager.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/scrape/manager.go b/scrape/manager.go index a0ac38f6b..96cad00c9 100644 --- a/scrape/manager.go +++ b/scrape/manager.go @@ -279,24 +279,10 @@ func (m *Manager) TargetsActive() map[string][]*Target { m.mtxScrape.Lock() defer m.mtxScrape.Unlock() - var ( - wg sync.WaitGroup - mtx sync.Mutex - ) - targets := make(map[string][]*Target, len(m.scrapePools)) - wg.Add(len(m.scrapePools)) for tset, sp := range m.scrapePools { - // Running in parallel limits the blocking time of scrapePool to scrape - // interval when there's an update from SD. - go func(tset string, sp *scrapePool) { - mtx.Lock() - targets[tset] = sp.ActiveTargets() - mtx.Unlock() - wg.Done() - }(tset, sp) + targets[tset] = sp.ActiveTargets() } - wg.Wait() return targets }