prometheus/promql/testdata
beorn7 7f912db15a promql: Fix limiting of extrapolation to negative values
This is a bit tough to explain, but I'll try:

`rate` & friends have a sophisticated extrapolation algorithm.
Usually, we extrapolate the result to the total interval specified in
the range selector. However, if the first sample within the range is
too far away from the beginning of the interval, or if the last sample
within the range is too far away from the end of the interval, we
assume the series has just started half a sampling interval before the
first sample or after the last sample, respectively, and shorten the
extrapolation interval correspondingly. We calculate the sampling
interval by looking at the average time between samples within the
range, and we define "too far away" as "more than 110% of that
sampling interval".

However, if this algorithm leads to an extrapolated starting value
that is negative, we limit the start of the extrapolation interval to
the point where the extrapolated starting value is zero.

At least that was the intention.

What we actually implemented is the following: If extrapolating all
the way to the beginning of the total interval would lead to an
extrapolated negative value, we would only extrapolate to the zero
point as above, even if the algorithm above would have selected a
starting point that is just half a sampling interval before the first
sample and that starting point would not have an extrapolated negative
value. In other word: What was meant as a _limitation_ of the
extrapolation interval yielded a _longer_ extrapolation interval in
this case.

There is an exception to the case just described: If the increase of
the extrapolation interval is more than 110% of the sampling interval,
we suddenly drop back to only extrapolate to half a sampling interval.

This behavior can be nicely seen in the testcounter_zero_cutoff test,
where the rate goes up all the way to 0.7 and then jumps back to 0.6.

This commit changes the behavior to what was (presumably) intended
from the beginning: The extension of the extrapolation interval is
only limited if actually needed to prevent extrapolation to negative
values, but the "limitation" never leads to _more_ extrapolation
anymore.

The difference is subtle, and probably it never bothered anyone.
However, if you calculate a rate of a classic histograms, the old
behavior might create non-monotonic histograms as a result (because of
the jumps you can see nicely in the old version of the
testcounter_zero_cutoff test). With this fix, that doesn't happen
anymore.

Signed-off-by: beorn7 <beorn@grafana.com>
2024-03-07 01:20:33 +01:00
..
aggregators.test address comment 2022-02-15 22:09:17 +08:00
at_modifier.test PromQL: Test negative offset in PromQL tests 2022-01-11 18:23:40 +01:00
collision.test promql: Organize legacy tests into appropriate files (#7989) 2020-10-07 10:09:20 +01:00
functions.test promql: Fix limiting of extrapolation to negative values 2024-03-07 01:20:33 +01:00
histograms.test add doc 2022-02-13 21:59:03 +08:00
literals.test PromQL: Fix string and parentheses handling in engine (#6612) 2020-01-15 18:31:58 +01:00
native_histograms.test promql: add histogram_avg function (#13467) 2024-02-01 18:28:42 +01:00
operators.test Drop metric name for "atan2" binary operator 2023-07-24 14:36:02 +02:00
selectors.test PromQL: Test negative offset in PromQL tests 2022-01-11 18:23:40 +01:00
staleness.test Remove 4 interval staleness heuristic. (#3244) 2017-10-05 12:55:14 +01:00
subquery.test PromQL: Fix string and parentheses handling in engine (#6612) 2020-01-15 18:31:58 +01:00
trig_functions.test Add inverse hyperbolic functions 2021-09-15 22:47:10 -04:00