Search before asking
Motivation
Description
IoTDB should support Prometheus-compatible semantics for the PromQL rate() and irate() functions on counter range vectors.
The expected behavior should follow Prometheus:
rate(v range-vector) returns the per-second average rate of increase over the selected range.
irate(v range-vector) returns the per-second instant rate based on the last two samples in the selected range.
- Both functions should handle counter resets correctly.
rate() should use all samples in the range and extrapolate to the range boundaries.
irate() should use only the last two samples and should not extrapolate to range boundaries.
Expected Implementation Semantics
For rate() on float counters:
- Require at least two samples.
- Compute the raw increase as
last - first.
- For each adjacent sample pair, detect counter reset when
current < previous.
- For each detected reset, add the previous value to the corrected increase.
- If start timestamp metadata is available, also treat start timestamp reset as a counter reset.
- Apply Prometheus-compatible boundary extrapolation:
- Compute the sampled interval between the first and last samples.
- Compute the average interval between samples.
- If the first/last sample is close enough to the range boundary, extrapolate to the boundary.
- If it is too far away, extrapolate only by half of the average sample interval.
- For counters, avoid extrapolating the left boundary below zero.
- Divide by the full range duration in seconds.
For irate() on float counters:
- Require at least two samples.
- Use only the last two samples in the range.
- If no reset is detected, return
(last - previous) / intervalSeconds.
- If reset is detected, return
last / intervalSeconds.
- Do not perform range-boundary extrapolation.
Test Cases
Please add compatibility tests for:
rate() without reset.
rate() with one counter reset.
rate() with multiple counter resets.
rate() boundary extrapolation when samples are close to the range boundaries.
rate() boundary extrapolation when samples are far from the range boundaries.
rate() counter zero-point extrapolation guard.
irate() without reset.
irate() with reset between the last two samples.
irate() ignoring older samples except for selecting the last two points.
- Empty result when fewer than two samples are available.
References
Solution
No response
Alternatives
No response
Are you willing to submit a PR?
Search before asking
Motivation
Description
IoTDB should support Prometheus-compatible semantics for the PromQL
rate()andirate()functions on counter range vectors.The expected behavior should follow Prometheus:
rate(v range-vector)returns the per-second average rate of increase over the selected range.irate(v range-vector)returns the per-second instant rate based on the last two samples in the selected range.rate()should use all samples in the range and extrapolate to the range boundaries.irate()should use only the last two samples and should not extrapolate to range boundaries.Expected Implementation Semantics
For
rate()on float counters:last - first.current < previous.For
irate()on float counters:(last - previous) / intervalSeconds.last / intervalSeconds.Test Cases
Please add compatibility tests for:
rate()without reset.rate()with one counter reset.rate()with multiple counter resets.rate()boundary extrapolation when samples are close to the range boundaries.rate()boundary extrapolation when samples are far from the range boundaries.rate()counter zero-point extrapolation guard.irate()without reset.irate()with reset between the last two samples.irate()ignoring older samples except for selecting the last two points.References
rate()documentation: https://prometheus.io/docs/prometheus/latest/querying/functions/#rateirate()documentation: https://prometheus.io/docs/prometheus/latest/querying/functions/#irateresets()documentation: https://prometheus.io/docs/prometheus/latest/querying/functions/#resetsrate()implementation: https://github.com/prometheus/prometheus/blob/main/promql/functions.go#L2991-L3249irate()implementation: https://github.com/prometheus/prometheus/blob/main/promql/functions.go#L3521-L3758Solution
No response
Alternatives
No response
Are you willing to submit a PR?