> The idea behind the rate() implementation is to not give the impression that the counter has actually been consistently increasing by 2 per second over the entire 5 minute input window if the series likely just started somewhere under the window (meaning that the rate was 0 or non-existent before that).
Hmm... so I guess it's a kind of histogram thing, where the area of a bar (= width x height) implies the total quantity - in this case meaning increase(), which is rate() times period.. It's estimating "how much did X increase" and taking into account that the counter cannot have been negative.
However, looking at the other example where the counter goes from 1017 to 1137 in 60 seconds (an increase of 120, with no zero crossing in the window): it extends by half a sample interval on each side, giving a range of 120 seconds, and proportionately scales up the increase from 120 to 240. It then assigns that entire increase to the window period of 300 seconds. Using rate = increase / window size, calculating the rate gives 240 / 300 = 0.8, rather than what I was expecting (2, which is the slope).
That logic is, well, surprising to me. I guess the question is, would I be more surprised to see increase(foo[5m]) equal to 600, given only those two data points?
In the past I have noticed rate graphs in Grafana behaving strangely for the first few samples of a new timeseries (being scraped from an SNMP device), and now I kind of understand it.
> Btw. rate() hasn't always behaved like this. Here's a super old issue (that I actually made a lengthy comment on) and a PR by Björn to address it:
Thanks for the links. I can understand the issue there: if a counter only increments occasionally, e.g.
(0 0 0 0) 0 1 1 1 1 1 2 2 2 2 2
and you are unlucky enough to pick up only the "0 1" at the start of the timeseries, you incorrectly extrapolate the rate to 1 / (sample interval). I don't think you'd need worry about this if the difference between the values is 2 or more: if the counter has incremented by N, then the average interval between those events must be somewhere between (sample interval / (N-1)) and (sample interval / N)