mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/promql: return expected increase()
result for the first point on the graph with value not exceeding 100
This commit is contained in:
parent
3f88e27d0f
commit
8d1031c29a
2 changed files with 18 additions and 4 deletions
|
@ -1308,8 +1308,11 @@ func rollupDelta(rfa *rollupFuncArg) float64 {
|
|||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/894
|
||||
return values[len(values)-1] - rfa.realPrevValue
|
||||
}
|
||||
// Assume that the previous non-existing value was 0
|
||||
// only if the first value doesn't exceed too much the delta with the next value.
|
||||
// Assume that the previous non-existing value was 0 only in the following cases:
|
||||
//
|
||||
// - If the delta with the next value equals to 0.
|
||||
// This is the case for slow-changing counter - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962
|
||||
// - If the first value doesn't exceed too much the delta with the next value.
|
||||
//
|
||||
// This should prevent from improper increase() results for os-level counters
|
||||
// such as cpu time or bytes sent over the network interface.
|
||||
|
@ -1317,12 +1320,15 @@ func rollupDelta(rfa *rollupFuncArg) float64 {
|
|||
//
|
||||
// This also should prevent from improper increase() results when a part of label values are changed
|
||||
// without counter reset.
|
||||
d := float64(10)
|
||||
var d float64
|
||||
if len(values) > 1 {
|
||||
d = values[1] - values[0]
|
||||
} else if !math.IsNaN(rfa.realNextValue) {
|
||||
d = rfa.realNextValue - values[0]
|
||||
}
|
||||
if d == 0 {
|
||||
d = 10
|
||||
}
|
||||
if math.Abs(values[0]) < 10*(math.Abs(d)+1) {
|
||||
prevValue = 0
|
||||
} else {
|
||||
|
|
|
@ -1171,8 +1171,16 @@ func TestRollupDelta(t *testing.T) {
|
|||
f(nan, nan, nan, []float64{5, 6, 8}, 8)
|
||||
f(2, nan, nan, []float64{5, 6, 8}, 6)
|
||||
|
||||
// Too big initial value must be skipped.
|
||||
// Moderate initial value with zero delta after that.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/962
|
||||
f(nan, nan, nan, []float64{100}, 100)
|
||||
f(nan, nan, nan, []float64{100, 100}, 100)
|
||||
|
||||
// Big initial value with with zero delta after that.
|
||||
f(nan, nan, nan, []float64{1000}, 0)
|
||||
f(nan, nan, nan, []float64{1000, 1000}, 0)
|
||||
|
||||
// Big initial value with small delta after that.
|
||||
f(nan, nan, nan, []float64{1000, 1001, 1002}, 2)
|
||||
|
||||
// Non-nan realPrevValue
|
||||
|
|
Loading…
Reference in a new issue