You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When working on #6344 (#6348#discussion_r893370459) I discovered that the unwrapped rate aggregation (rate({} | unwrap x [$__interval]) behaves differently than expected.
rate(unwrapped-range): calculates per second rate of all values in the specified interval.
This clearly suggests that the individual values extracted from the log lines in a time range are summed up and divided by the range to get the rate per second.
The initial implementation before #5013 also was like that.
One would expect to get as result 2.7, based on (4+3+5+2+8+2+3)/10.
However, what you actually get is 1.6, based on (3-4+4+5+8)/10. This is due to the implementation of rate() when using Counter type metrics, that has been copied from Prometheus.
However, Loki does not have the notion of "counters".
The reason why the implementation was changed, was because of a tiny subset of common use of the rate() aggregation, where the value in the log lines acts as a "counter" (which can reset to 0), as explained in the PR description of #5013.
Describe the solution you'd like
I propose to revert the implementation of the rate to the previous behaviour.
Additionally, to cover the special use-case of a counter value, LogQL can provide a new aggregation function counter_rate(), which takes an unwrapped range as input and treats it as a counter.
I support your solution as well, however I would name it rate_counter because I think it's more discoverable when you are typing a query and know you want to rate something vs trying to remember that it's counter_rate
Is your feature request related to a problem? Please describe.
When working on #6344 (#6348#discussion_r893370459) I discovered that the unwrapped rate aggregation (
rate({} | unwrap x [$__interval]
) behaves differently than expected.The documentation on unwrapped range aggregations states:
This clearly suggests that the individual values extracted from the log lines in a time range are summed up and divided by the range to get the rate per second.
The initial implementation before #5013 also was like that.
loki/pkg/logql/functions.go
Lines 126 to 137 in a046d79
For example, executing
rate({} | logfmt | unwrap subqueries [10s])
on following logs lines:One would expect to get as result
2.7
, based on(4+3+5+2+8+2+3)/10
.However, what you actually get is
1.6
, based on(3-4+4+5+8)/10
. This is due to the implementation ofrate()
when usingCounter
type metrics, that has been copied from Prometheus.loki/pkg/logql/range_vector.go
Lines 231 to 256 in caf7dde
However, Loki does not have the notion of "counters".
The reason why the implementation was changed, was because of a tiny subset of common use of the
rate()
aggregation, where the value in the log lines acts as a "counter" (which can reset to 0), as explained in the PR description of #5013.Describe the solution you'd like
I propose to revert the implementation of the rate to the previous behaviour.
Additionally, to cover the special use-case of a counter value, LogQL can provide a new aggregation function
counter_rate()
, which takes an unwrapped range as input and treats it as a counter.Example:
Describe alternatives you've considered
Leave the implementation as is and change the documentation. This will probably cause a lot of confusion to people how want to rate "normal" values.
The text was updated successfully, but these errors were encountered: