Merge pull request #8828 from roidelapluie/fix_prometheus_sd_discovered_targets

Fix the computation of prometheus_sd_discovered_targets
This commit is contained in:
Julien Pivotto 2021-05-20 21:17:15 +02:00 committed by GitHub
commit ac49c1be4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -279,15 +279,17 @@ func (m *Manager) allGroups() map[string][]*targetgroup.Group {
defer m.mtx.RUnlock() defer m.mtx.RUnlock()
tSets := map[string][]*targetgroup.Group{} tSets := map[string][]*targetgroup.Group{}
n := map[string]int{}
for pkey, tsets := range m.targets { for pkey, tsets := range m.targets {
var n int
for _, tg := range tsets { for _, tg := range tsets {
// Even if the target group 'tg' is empty we still need to send it to the 'Scrape manager' // Even if the target group 'tg' is empty we still need to send it to the 'Scrape manager'
// to signal that it needs to stop all scrape loops for this target set. // to signal that it needs to stop all scrape loops for this target set.
tSets[pkey.setName] = append(tSets[pkey.setName], tg) tSets[pkey.setName] = append(tSets[pkey.setName], tg)
n += len(tg.Targets) n[pkey.setName] += len(tg.Targets)
} }
discoveredTargets.WithLabelValues(m.name, pkey.setName).Set(float64(n)) }
for setName, v := range n {
discoveredTargets.WithLabelValues(m.name, setName).Set(float64(v))
} }
return tSets return tSets
} }