mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/promql: fix corner-case calculation for ideriv
This commit is contained in:
parent
1b5b9ced27
commit
0cb66a8f95
2 changed files with 3 additions and 3 deletions
|
@ -698,7 +698,7 @@ func rollupIderiv(rfa *rollupFuncArg) float64 {
|
||||||
// It is impossible to calculate derivative on 0 or 1 values.
|
// It is impossible to calculate derivative on 0 or 1 values.
|
||||||
return nan
|
return nan
|
||||||
}
|
}
|
||||||
return (values[0] - rfa.prevValue) / float64(timestamps[0]-rfa.prevTimestamp)
|
return (values[0] - rfa.prevValue) / (float64(timestamps[0]-rfa.prevTimestamp) * 1e-3)
|
||||||
}
|
}
|
||||||
vEnd := values[len(values)-1]
|
vEnd := values[len(values)-1]
|
||||||
tEnd := timestamps[len(timestamps)-1]
|
tEnd := timestamps[len(timestamps)-1]
|
||||||
|
@ -722,7 +722,7 @@ func rollupIderiv(rfa *rollupFuncArg) float64 {
|
||||||
}
|
}
|
||||||
dv := vEnd - vStart
|
dv := vEnd - vStart
|
||||||
dt := tEnd - tStart
|
dt := tEnd - tStart
|
||||||
return dv / (float64(dt) / 1000)
|
return dv / (float64(dt) * 1e-3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rollupChanges(rfa *rollupFuncArg) float64 {
|
func rollupChanges(rfa *rollupFuncArg) float64 {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestRollupIderivDuplicateTimestamps(t *testing.T) {
|
||||||
timestamps: []int64{100},
|
timestamps: []int64{100},
|
||||||
}
|
}
|
||||||
n = rollupIderiv(rfa)
|
n = rollupIderiv(rfa)
|
||||||
if n != 0.5 {
|
if n != 500 {
|
||||||
t.Fatalf("unexpected value; got %v; want %v", n, 0.5)
|
t.Fatalf("unexpected value; got %v; want %v", n, 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue