Browse Source

Merge pull request #13167 from bboreham/simplify-TargetsActive

scrape: simplify TargetsActive function
pull/13316/head
Bryan Boreham 11 months ago committed by GitHub
parent
commit
75fc8a1535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      scrape/manager.go

16
scrape/manager.go

@ -288,24 +288,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
}

Loading…
Cancel
Save