From 6c41ec984f9bb19bba38e9429de7dff620cdf109 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 8 Mar 2024 10:18:18 +0000 Subject: [PATCH] [BUGFIX] Scraping: Tolerance should be max 1% of interval Previous code set it at minimum 1%, which was not intended. Signed-off-by: Bryan Boreham --- scrape/scrape.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scrape/scrape.go b/scrape/scrape.go index 11006dc24..f6f336773 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -1218,10 +1218,8 @@ mainLoop: // and .Add on time.Time behave differently (see time package docs). scrapeTime := time.Now().Round(0) if AlignScrapeTimestamps { - tolerance := ScrapeTimestampTolerance - if maxTolerance := sl.interval / 100; tolerance < maxTolerance { - tolerance = maxTolerance - } + // Tolerance is clamped to maximum 1% of the scrape interval. + tolerance := min(sl.interval/100, ScrapeTimestampTolerance) // 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 {