mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
app/vmselect/promql: remove rollupFuncArg.realPrevValue handling, since the corner case in increase()
is handled in another way now
See e00cfc854d
for the approach used now.
This commit is contained in:
parent
d9037b3970
commit
717c554fb0
@ -28,8 +28,8 @@ var rollupFuncs = map[string]newRollupFunc{
|
|||||||
"deriv_fast": newRollupFuncOneArg(rollupDerivFast),
|
"deriv_fast": newRollupFuncOneArg(rollupDerivFast),
|
||||||
"holt_winters": newRollupHoltWinters,
|
"holt_winters": newRollupHoltWinters,
|
||||||
"idelta": newRollupFuncOneArg(rollupIdelta),
|
"idelta": newRollupFuncOneArg(rollupIdelta),
|
||||||
"increase": newRollupFuncOneArg(rollupIncrease), // + rollupFuncsRemoveCounterResets
|
"increase": newRollupFuncOneArg(rollupDelta), // + rollupFuncsRemoveCounterResets
|
||||||
"irate": newRollupFuncOneArg(rollupIderiv), // + rollupFuncsRemoveCounterResets
|
"irate": newRollupFuncOneArg(rollupIderiv), // + rollupFuncsRemoveCounterResets
|
||||||
"predict_linear": newRollupPredictLinear,
|
"predict_linear": newRollupPredictLinear,
|
||||||
"rate": newRollupFuncOneArg(rollupDerivFast), // + rollupFuncsRemoveCounterResets
|
"rate": newRollupFuncOneArg(rollupDerivFast), // + rollupFuncsRemoveCounterResets
|
||||||
"resets": newRollupFuncOneArg(rollupResets),
|
"resets": newRollupFuncOneArg(rollupResets),
|
||||||
@ -94,7 +94,7 @@ var rollupAggrFuncs = map[string]rollupFunc{
|
|||||||
"deriv": rollupDerivSlow,
|
"deriv": rollupDerivSlow,
|
||||||
"deriv_fast": rollupDerivFast,
|
"deriv_fast": rollupDerivFast,
|
||||||
"idelta": rollupIdelta,
|
"idelta": rollupIdelta,
|
||||||
"increase": rollupIncrease, // + rollupFuncsRemoveCounterResets
|
"increase": rollupDelta, // + rollupFuncsRemoveCounterResets
|
||||||
"irate": rollupIderiv, // + rollupFuncsRemoveCounterResets
|
"irate": rollupIderiv, // + rollupFuncsRemoveCounterResets
|
||||||
"rate": rollupDerivFast, // + rollupFuncsRemoveCounterResets
|
"rate": rollupDerivFast, // + rollupFuncsRemoveCounterResets
|
||||||
"resets": rollupResets,
|
"resets": rollupResets,
|
||||||
@ -327,10 +327,6 @@ type rollupFuncArg struct {
|
|||||||
idx int
|
idx int
|
||||||
step int64
|
step int64
|
||||||
|
|
||||||
// Real previous value even if it is located too far from the current window.
|
|
||||||
// It matches prevValue if prevValue is not nan.
|
|
||||||
realPrevValue float64
|
|
||||||
|
|
||||||
tsm *timeseriesMap
|
tsm *timeseriesMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +338,6 @@ func (rfa *rollupFuncArg) reset() {
|
|||||||
rfa.currTimestamp = 0
|
rfa.currTimestamp = 0
|
||||||
rfa.idx = 0
|
rfa.idx = 0
|
||||||
rfa.step = 0
|
rfa.step = 0
|
||||||
rfa.realPrevValue = nan
|
|
||||||
rfa.tsm = nil
|
rfa.tsm = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +482,6 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu
|
|||||||
rfa := getRollupFuncArg()
|
rfa := getRollupFuncArg()
|
||||||
rfa.idx = 0
|
rfa.idx = 0
|
||||||
rfa.step = rc.Step
|
rfa.step = rc.Step
|
||||||
rfa.realPrevValue = nan
|
|
||||||
rfa.tsm = tsm
|
rfa.tsm = tsm
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
@ -514,11 +508,6 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu
|
|||||||
rfa.values = values[i:j]
|
rfa.values = values[i:j]
|
||||||
rfa.timestamps = timestamps[i:j]
|
rfa.timestamps = timestamps[i:j]
|
||||||
rfa.currTimestamp = tEnd
|
rfa.currTimestamp = tEnd
|
||||||
if i > 0 {
|
|
||||||
rfa.realPrevValue = values[i-1]
|
|
||||||
} else {
|
|
||||||
rfa.realPrevValue = nan
|
|
||||||
}
|
|
||||||
value := rc.Func(rfa)
|
value := rc.Func(rfa)
|
||||||
rfa.idx++
|
rfa.idx++
|
||||||
dstValues = append(dstValues, value)
|
dstValues = append(dstValues, value)
|
||||||
@ -1205,14 +1194,6 @@ func rollupStdvar(rfa *rollupFuncArg) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func rollupDelta(rfa *rollupFuncArg) float64 {
|
func rollupDelta(rfa *rollupFuncArg) float64 {
|
||||||
return rollupDeltaInternal(rfa, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func rollupIncrease(rfa *rollupFuncArg) float64 {
|
|
||||||
return rollupDeltaInternal(rfa, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func rollupDeltaInternal(rfa *rollupFuncArg, canUseRealPrevValue bool) float64 {
|
|
||||||
// There is no need in handling NaNs here, since they must be cleaned up
|
// There is no need in handling NaNs here, since they must be cleaned up
|
||||||
// before calling rollup funcs.
|
// before calling rollup funcs.
|
||||||
values := rfa.values
|
values := rfa.values
|
||||||
@ -1236,9 +1217,6 @@ func rollupDeltaInternal(rfa *rollupFuncArg, canUseRealPrevValue bool) float64 {
|
|||||||
}
|
}
|
||||||
if math.Abs(values[0]) < 10*(math.Abs(d)+1) {
|
if math.Abs(values[0]) < 10*(math.Abs(d)+1) {
|
||||||
prevValue = 0
|
prevValue = 0
|
||||||
if canUseRealPrevValue && !math.IsNaN(rfa.realPrevValue) {
|
|
||||||
prevValue = rfa.realPrevValue
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
prevValue = values[0]
|
prevValue = values[0]
|
||||||
values = values[1:]
|
values = values[1:]
|
||||||
|
@ -1040,15 +1040,14 @@ func testRowsEqual(t *testing.T, values []float64, timestamps []int64, valuesExp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRollupIncrease(t *testing.T) {
|
func TestRollupDelta(t *testing.T) {
|
||||||
f := func(prevValue float64, values []float64, resultExpected float64) {
|
f := func(prevValue float64, values []float64, resultExpected float64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
rfa := &rollupFuncArg{
|
rfa := &rollupFuncArg{
|
||||||
prevValue: prevValue,
|
prevValue: prevValue,
|
||||||
realPrevValue: prevValue,
|
values: values,
|
||||||
values: values,
|
|
||||||
}
|
}
|
||||||
result := rollupIncrease(rfa)
|
result := rollupDelta(rfa)
|
||||||
if math.IsNaN(result) {
|
if math.IsNaN(result) {
|
||||||
if !math.IsNaN(resultExpected) {
|
if !math.IsNaN(resultExpected) {
|
||||||
t.Fatalf("unexpected result; got %v; want %v", result, resultExpected)
|
t.Fatalf("unexpected result; got %v; want %v", result, resultExpected)
|
||||||
|
Loading…
Reference in New Issue
Block a user