From 93fbd0c54b01fa04b6310b2048e999ed2b0c97df Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Wed, 13 Jul 2022 11:27:38 +0200 Subject: [PATCH] promql: return `step` as scrapeInterval when it can't be calculated (#2865) The change allows to specify default value for `getScrapeInterval` function when actual interval can't be calculated. Before the change, function were returning `maxSilenceInterval` (5m) in such cases, which may be not correct for instant queries processing. The specific scenario where using `maxSilenceInterval` caused issues is the following: 1. Series becomes stale; 2. Client (in this case vmalert) continues to request series every 15s; 3. Database returns empty results as expected; 4. But at some specific moment of time database returns datapoints from `now()-5m`, because lookback window was extended to `maxSilenceInterval`. Signed-off-by: hagen1778 --- app/vmselect/promql/rollup.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 952a9c6ab..267b0eaa0 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -520,7 +520,7 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu // Extend dstValues in order to remove mallocs below. dstValues = decimal.ExtendFloat64sCapacity(dstValues, len(rc.Timestamps)) - scrapeInterval := getScrapeInterval(timestamps) + scrapeInterval := getScrapeInterval(timestamps, rc.Step) maxPrevInterval := getMaxPrevInterval(scrapeInterval) if rc.LookbackDelta > 0 && maxPrevInterval > rc.LookbackDelta { maxPrevInterval = rc.LookbackDelta @@ -644,9 +644,11 @@ func binarySearchInt64(a []int64, v int64) uint { return i } -func getScrapeInterval(timestamps []int64) int64 { +func getScrapeInterval(timestamps []int64, defaultVal int64) int64 { if len(timestamps) < 2 { - return int64(maxSilenceInterval) + // can't calculate scrape interval with less than 2 timestamps + // return defaultVal + return defaultVal } // Estimate scrape interval as 0.6 quantile for the first 20 intervals.