mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promscrape/discovery/kubernetes: wait for 10 seconds before checking whether the urlWatcher must be stopped
This should prevent from excess urlWatcher churn on config reload, since it leads to removal of all the apiWatchers before creating new apiWatchers. So, every config reload would lead to stopping of all the previous urlWatchers and starting new urlWatchers. The new logic gives 10 seconds for config reload before stopping unused urlWatchers. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4850 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4861
This commit is contained in:
parent
76af32d869
commit
03fece44e0
1 changed files with 13 additions and 4 deletions
|
@ -446,11 +446,10 @@ func (gw *groupWatcher) registerPendingAPIWatchers() {
|
|||
func (gw *groupWatcher) unsubscribeAPIWatcher(aw *apiWatcher) {
|
||||
gw.mu.Lock()
|
||||
defer gw.mu.Unlock()
|
||||
for key, uw := range gw.m {
|
||||
for _, uw := range gw.m {
|
||||
uw.unsubscribeAPIWatcherLocked(aw)
|
||||
if (len(uw.aws) + len(uw.awsPending)) == 0 {
|
||||
uw.cancel()
|
||||
delete(gw.m, key)
|
||||
if len(uw.aws)+len(uw.awsPending) == 0 {
|
||||
time.AfterFunc(10*time.Second, uw.stopIfNoUsers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -524,6 +523,16 @@ func newURLWatcher(role, apiURL string, gw *groupWatcher) *urlWatcher {
|
|||
return uw
|
||||
}
|
||||
|
||||
func (uw *urlWatcher) stopIfNoUsers() {
|
||||
gw := uw.gw
|
||||
gw.mu.Lock()
|
||||
if len(uw.aws)+len(uw.awsPending) == 0 {
|
||||
uw.cancel()
|
||||
delete(gw.m, uw.apiURL)
|
||||
}
|
||||
gw.mu.Unlock()
|
||||
}
|
||||
|
||||
func (uw *urlWatcher) subscribeAPIWatcherLocked(aw *apiWatcher) {
|
||||
if _, ok := uw.aws[aw]; !ok {
|
||||
if _, ok := uw.awsPending[aw]; !ok {
|
||||
|
|
Loading…
Reference in a new issue