Merge pull request #13624 from roidelapluie/tolerance

Always align scrapes even if tolerance is bigger than 1% of scrape interval
This commit is contained in:
Julien 2024-03-04 16:37:00 +01:00 committed by GitHub
commit fcdb6c2b14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1217,14 +1217,18 @@ mainLoop:
// Calling Round ensures the time used is the wall clock, as otherwise .Sub
// and .Add on time.Time behave differently (see time package docs).
scrapeTime := time.Now().Round(0)
if AlignScrapeTimestamps && sl.interval > 100*ScrapeTimestampTolerance {
if AlignScrapeTimestamps {
tolerance := ScrapeTimestampTolerance
if maxTolerance := sl.interval / 100; tolerance < maxTolerance {
tolerance = maxTolerance
}
// For some reason, a tick might have been skipped, in which case we
// would call alignedScrapeTime.Add(interval) multiple times.
for scrapeTime.Sub(alignedScrapeTime) >= sl.interval {
alignedScrapeTime = alignedScrapeTime.Add(sl.interval)
}
// Align the scrape time if we are in the tolerance boundaries.
if scrapeTime.Sub(alignedScrapeTime) <= ScrapeTimestampTolerance {
if scrapeTime.Sub(alignedScrapeTime) <= tolerance {
scrapeTime = alignedScrapeTime
}
}