Always align scrapes even if tolerance is bigger than 1% of scrape interval
When the scrape tolerance is bigger than 1% of the scrape interval, take 1% of the scrape interval as the tolerance instead of not aligning the scrape at all. Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
This commit is contained in:
parent
aba0071480
commit
e22b564049
|
@ -1192,14 +1192,18 @@ mainLoop:
|
||||||
// Calling Round ensures the time used is the wall clock, as otherwise .Sub
|
// Calling Round ensures the time used is the wall clock, as otherwise .Sub
|
||||||
// and .Add on time.Time behave differently (see time package docs).
|
// and .Add on time.Time behave differently (see time package docs).
|
||||||
scrapeTime := time.Now().Round(0)
|
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
|
// For some reason, a tick might have been skipped, in which case we
|
||||||
// would call alignedScrapeTime.Add(interval) multiple times.
|
// would call alignedScrapeTime.Add(interval) multiple times.
|
||||||
for scrapeTime.Sub(alignedScrapeTime) >= sl.interval {
|
for scrapeTime.Sub(alignedScrapeTime) >= sl.interval {
|
||||||
alignedScrapeTime = alignedScrapeTime.Add(sl.interval)
|
alignedScrapeTime = alignedScrapeTime.Add(sl.interval)
|
||||||
}
|
}
|
||||||
// Align the scrape time if we are in the tolerance boundaries.
|
// Align the scrape time if we are in the tolerance boundaries.
|
||||||
if scrapeTime.Sub(alignedScrapeTime) <= ScrapeTimestampTolerance {
|
if scrapeTime.Sub(alignedScrapeTime) <= tolerance {
|
||||||
scrapeTime = alignedScrapeTime
|
scrapeTime = alignedScrapeTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue