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 <roman@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2022-07-13 11:27:38 +02:00 committed by GitHub
parent f7eda4a73c
commit 93fbd0c54b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.