lib/promscrape/discovery/kubernetes: limit the minimum sleep time between updating dependent ScrapeWork objects

Previously the sleep time could be dropped to nanoseconds, which could result in CPU time waste
This commit is contained in:
Aliaksandr Valialkin 2022-04-22 23:13:33 +03:00
parent a89e31b304
commit c2b13e6a04
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -304,7 +304,8 @@ func (gw *groupWatcher) startWatchersForRole(role string, aw *apiWatcher) {
// as soon as the objects they depend on are updated.
// This should fix https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1240 .
go func() {
sleepTime := 20 * time.Second
const minSleepTime = 5 * time.Second
sleepTime := minSleepTime
for {
time.Sleep(sleepTime)
startTime := time.Now()
@ -312,9 +313,12 @@ func (gw *groupWatcher) startWatchersForRole(role string, aw *apiWatcher) {
if uw.needUpdateScrapeWorks {
uw.needUpdateScrapeWorks = false
uw.updateScrapeWorksLocked(uw.objectsByKey, uw.aws)
sleepTime = time.Since(startTime)
if sleepTime < minSleepTime {
sleepTime = minSleepTime
}
}
gw.mu.Unlock()
sleepTime = time.Since(startTime)
}
}()
}