I can reproduce the results by extracting parts of the extrapolatedRate() function, but I still don't understand what it's doing.
https://go.dev/play/p/ua3XGLEA0cI # _ _ _ 17 137 https://go.dev/play/p/NoJ3FoKLeLG # _ _ _ 1017 1137 Taking the first one: - It extrapolates backwards to find where the zero crossing ought to be (if it started linearly from zero). In the case of _ _ _ 17 137, this gives a time 8.5 seconds earlier, so the time between first and end points grows from 60 to 68.5 seconds. - It then adds half the average interval, making 98.5 seconds. - It then takes the increase and scales it by 98.5 / 60, where 60 is the true gap between the samples - It multiplies the true increase in the value by 98.5/60, then divides by 300 which is the full width of the range 120 * (98.5/60) / 300 = .6566666666 This calculates the extrapolated increase from time (t1 - 8.5) to (t2 + 30), but then it seems to be treating this increase as if it had been spread over the whole 5 minutes, rather than over 98.5 seconds? On Friday, 13 October 2023 at 12:31:38 UTC+1 Brian Candler wrote: > (I copy pasted the wrong bit of screen from when I had eval_time: 5m30s, > but it doesn't affect the result) > > On Friday, 13 October 2023 at 12:30:16 UTC+1 Brian Candler wrote: > >> I've been using "promtool test rules" to see how rate() behaves with a >> timeseries that has recently started, and I am struggling to understand it. >> >> What would you think the following test should return? >> >> ``` >> evaluation_interval: 1m >> >> tests: >> - input_series: >> - series: foo >> values: '_ _ _ 17 137' >> interval: 1m >> >> promql_expr_test: >> - expr: rate(foo[5m]) >> eval_time: 4m30s >> exp_samples: >> - value: 2 # I expected: increase of 120 in 60 seconds >> labels: "" >> ``` >> >> Result (with prometheus 2.45.0): >> >> ``` >> FAILED: >> expr: "rate(foo[5m])", time: 5m30s, >> exp: {} 2E+00 >> got: {} 6.566666666666666E-01 >> ``` >> >> That result is 197/300, and I have no idea how it derives this value! >> >> Now change the input data to: >> >> ``` >> values: '_ _ _ 1017 1137' >> ``` >> >> and the result is 0.8 (=240/300, 192/240 or 48/60) - even though the >> input values are still 120 apart. >> >> Any clues as to how it gets these results? >> > -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/44e16f4a-9fcb-44fe-ad73-985cec076502n%40googlegroups.com.

