diff --git a/lib/promscrape/scraper.go b/lib/promscrape/scraper.go index 3c2651369..c0b68edc2 100644 --- a/lib/promscrape/scraper.go +++ b/lib/promscrape/scraper.go @@ -231,11 +231,17 @@ func (scfg *scrapeConfig) run() { cfg := <-scfg.cfgCh var swsPrev []*ScrapeWork updateScrapeWork := func(cfg *Config) { - startTime := time.Now() - sws := scfg.getScrapeWork(cfg, swsPrev) - sg.update(sws) - swsPrev = sws - scfg.discoveryDuration.UpdateDuration(startTime) + for { + startTime := time.Now() + sws := scfg.getScrapeWork(cfg, swsPrev) + retry := sg.update(sws) + swsPrev = sws + scfg.discoveryDuration.UpdateDuration(startTime) + if !retry { + return + } + time.Sleep(2 * time.Second) + } } updateScrapeWork(cfg) atomic.AddInt32(&PendingScrapeConfigs, -1) @@ -295,7 +301,7 @@ func (sg *scraperGroup) stop() { sg.wg.Wait() } -func (sg *scraperGroup) update(sws []*ScrapeWork) { +func (sg *scraperGroup) update(sws []*ScrapeWork) (retry bool) { sg.mLock.Lock() defer sg.mLock.Unlock() @@ -352,6 +358,7 @@ func (sg *scraperGroup) update(sws []*ScrapeWork) { sg.changesCount.Add(additionsCount + deletionsCount) logger.Infof("%s: added targets: %d, removed targets: %d; total targets: %d", sg.name, additionsCount, deletionsCount, len(sg.m)) } + return deletionsCount > 0 && len(sg.m) == 0 } type scraper struct {