app/vmselect/promql: fill gaps with 0 in rate_over_sum response when the last value before the selected time window isnt empty

This commit is contained in:
Aliaksandr Valialkin 2020-07-29 11:36:51 +03:00
parent f068ea74d0
commit d9037b3970

View file

@ -516,6 +516,8 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu
rfa.currTimestamp = tEnd rfa.currTimestamp = tEnd
if i > 0 { if i > 0 {
rfa.realPrevValue = values[i-1] rfa.realPrevValue = values[i-1]
} else {
rfa.realPrevValue = nan
} }
value := rc.Func(rfa) value := rc.Func(rfa)
rfa.idx++ rfa.idx++
@ -1093,15 +1095,19 @@ func rollupRateOverSum(rfa *rollupFuncArg) float64 {
timestamps := rfa.timestamps timestamps := rfa.timestamps
prevTimestamp := rfa.prevTimestamp prevTimestamp := rfa.prevTimestamp
if math.IsNaN(rfa.prevValue) { if math.IsNaN(rfa.prevValue) {
if len(values) == 0 { if len(timestamps) == 0 {
return nan return nan
} }
prevTimestamp = timestamps[0] prevTimestamp = timestamps[0]
values = values[1:] values = values[1:]
timestamps = timestamps[1:] timestamps = timestamps[1:]
} }
if len(values) == 0 { if len(timestamps) == 0 {
return nan if math.IsNaN(rfa.prevValue) {
return nan
}
// Assume that the value didn't change since rfa.prevValue.
return 0
} }
sum := float64(0) sum := float64(0)
for _, v := range values { for _, v := range values {
@ -1235,6 +1241,7 @@ func rollupDeltaInternal(rfa *rollupFuncArg, canUseRealPrevValue bool) float64 {
} }
} else { } else {
prevValue = values[0] prevValue = values[0]
values = values[1:]
} }
} }
if len(values) == 0 { if len(values) == 0 {