mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
discovery: updateGroup should not create targets[poolKey] in the loop (#6903)
We can assume that not all target groups are nil in normal scernarios, so we can create targets[poolKey] outside the loop. Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
ed623f69e2
commit
c67f81937c
|
@ -293,11 +293,11 @@ func (m *Manager) updateGroup(poolKey poolKey, tgs []*targetgroup.Group) {
|
||||||
m.mtx.Lock()
|
m.mtx.Lock()
|
||||||
defer m.mtx.Unlock()
|
defer m.mtx.Unlock()
|
||||||
|
|
||||||
|
if _, ok := m.targets[poolKey]; !ok {
|
||||||
|
m.targets[poolKey] = make(map[string]*targetgroup.Group)
|
||||||
|
}
|
||||||
for _, tg := range tgs {
|
for _, tg := range tgs {
|
||||||
if tg != nil { // Some Discoverers send nil target group so need to check for it to avoid panics.
|
if tg != nil { // Some Discoverers send nil target group so need to check for it to avoid panics.
|
||||||
if _, ok := m.targets[poolKey]; !ok {
|
|
||||||
m.targets[poolKey] = make(map[string]*targetgroup.Group)
|
|
||||||
}
|
|
||||||
m.targets[poolKey][tg.Source] = tg
|
m.targets[poolKey][tg.Source] = tg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue