lib/promscrape/discovery/kubernetes: properly account the number of objects when watcher is stopped

A follow-up for b21b110b7a
This commit is contained in:
Aliaksandr Valialkin 2021-02-28 17:05:28 +02:00
parent b21b110b7a
commit e02d1ef93c

View file

@ -232,6 +232,11 @@ func (aw *apiWatcher) startWatcherForURL(role, apiURL string, parseObject parseO
resourceVersion := uw.reloadObjects()
go func() {
uw.watchForUpdates(resourceVersion)
uw.mu.Lock()
uw.objectsCount.Add(-len(uw.objectsByKey))
uw.objectsRemoved.Add(len(uw.objectsByKey))
uw.mu.Unlock()
aw.mu.Lock()
delete(aw.watchersByURL, apiURL)
aw.mu.Unlock()