mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
f7eda4a73c
commit
93fbd0c54b
1 changed files with 5 additions and 3 deletions
|
@ -520,7 +520,7 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu
|
||||||
// Extend dstValues in order to remove mallocs below.
|
// Extend dstValues in order to remove mallocs below.
|
||||||
dstValues = decimal.ExtendFloat64sCapacity(dstValues, len(rc.Timestamps))
|
dstValues = decimal.ExtendFloat64sCapacity(dstValues, len(rc.Timestamps))
|
||||||
|
|
||||||
scrapeInterval := getScrapeInterval(timestamps)
|
scrapeInterval := getScrapeInterval(timestamps, rc.Step)
|
||||||
maxPrevInterval := getMaxPrevInterval(scrapeInterval)
|
maxPrevInterval := getMaxPrevInterval(scrapeInterval)
|
||||||
if rc.LookbackDelta > 0 && maxPrevInterval > rc.LookbackDelta {
|
if rc.LookbackDelta > 0 && maxPrevInterval > rc.LookbackDelta {
|
||||||
maxPrevInterval = rc.LookbackDelta
|
maxPrevInterval = rc.LookbackDelta
|
||||||
|
@ -644,9 +644,11 @@ func binarySearchInt64(a []int64, v int64) uint {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func getScrapeInterval(timestamps []int64) int64 {
|
func getScrapeInterval(timestamps []int64, defaultVal int64) int64 {
|
||||||
if len(timestamps) < 2 {
|
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.
|
// Estimate scrape interval as 0.6 quantile for the first 20 intervals.
|
||||||
|
|
Loading…
Reference in a new issue