lib/promscrape/discovery/kubernetes: simplify the reload logic for urlWatcher.objectsByKey

This commit is contained in:
Aliaksandr Valialkin 2021-05-18 15:40:46 +03:00
parent 0f54c0121b
commit c507faec0b

View File

@ -443,20 +443,18 @@ func (uw *urlWatcher) reloadObjects() string {
uw.gw.mu.Lock() uw.gw.mu.Lock()
var updated, removed, added int var updated, removed, added int
for key := range uw.objectsByKey { for key := range uw.objectsByKey {
if o, ok := objectsByKey[key]; ok { if _, ok := objectsByKey[key]; ok {
uw.objectsByKey[key] = o
updated++ updated++
} else { } else {
delete(uw.objectsByKey, key)
removed++ removed++
} }
} }
for key, o := range objectsByKey { for key := range objectsByKey {
if _, ok := uw.objectsByKey[key]; !ok { if _, ok := uw.objectsByKey[key]; !ok {
uw.objectsByKey[key] = o
added++ added++
} }
} }
uw.objectsByKey = objectsByKey
uw.reloadScrapeWorksForAPIWatchersLocked(uw.aws) uw.reloadScrapeWorksForAPIWatchersLocked(uw.aws)
uw.gw.mu.Unlock() uw.gw.mu.Unlock()