Skip to content

promql: fix smoothed interpolation across counter resets#17988

Merged
roidelapluie merged 1 commit intoprometheus:mainfrom
roidelapluie:roidelapluie/fixsmoothing
Feb 2, 2026
Merged

promql: fix smoothed interpolation across counter resets#17988
roidelapluie merged 1 commit intoprometheus:mainfrom
roidelapluie:roidelapluie/fixsmoothing

Conversation

@roidelapluie
Copy link
Member

Fix incorrect interpolation when counter resets occur in smoothed range selector evaluation. Previously, the asymmetric handling of counter resets (y1=0 on left edge, y2+=y1 on right edge) produced wrong values.

Now uniformly set y1=0 when a counter reset is detected, correctly modeling the counter as starting from 0 post-reset.

This fixes rate calculations across counter resets. For example, rate(metric[10s] smoothed) where metric goes from 100 to 10 (a reset) now correctly computes 0.666... by treating the counter as resetting to 0 rather than producing inflated values from the old behavior.

Which issue(s) does the PR fix:

Does this PR introduce a user-facing change?

[BUGFIX] PromQL: Fix smoothed interpolation across counter resets

Fix incorrect interpolation when counter resets occur in smoothed range
selector evaluation. Previously, the asymmetric handling of counter
resets (y1=0 on left edge, y2+=y1 on right edge) produced wrong values.

Now uniformly set y1=0 when a counter reset is detected, correctly
modeling the counter as starting from 0 post-reset.

This fixes rate calculations across counter resets. For example,
rate(metric[10s] smoothed) where metric goes from 100 to 10 (a reset)
now correctly computes 0.666... by treating the counter as resetting
to 0 rather than producing inflated values from the old behavior.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
@roidelapluie roidelapluie requested a review from a team as a code owner February 2, 2026 10:56
@roidelapluie roidelapluie requested a review from ywwg February 2, 2026 10:56
Copy link
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Seems obvious in hindsight.

@roidelapluie roidelapluie merged commit 717d37b into prometheus:main Feb 2, 2026
52 of 54 checks passed
roidelapluie added a commit to grafana/mimir that referenced this pull request Feb 5, 2026
The upstream Prometheus change (prometheus/prometheus#17988) fixed
incorrect interpolation when counter resets occur in smoothed range
selector evaluation. The old behavior asymmetrically handled counter
resets (y1=0 on left edge, y2+=y1 on right edge) which produced wrong
values.

The fix uniformly sets y1=0 when a counter reset is detected, correctly
modeling the counter as starting from 0 post-reset. This updates our
interpolate function to match the new behavior by removing the leftEdge
parameter and adjusting test expectations accordingly.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
roidelapluie added a commit to grafana/mimir that referenced this pull request Feb 5, 2026
The upstream Prometheus change (prometheus/prometheus#17988) fixed
incorrect interpolation when counter resets occur in smoothed range
selector evaluation. The old behavior asymmetrically handled counter
resets (y1=0 on left edge, y2+=y1 on right edge) which produced wrong
values.

The fix uniformly sets y1=0 when a counter reset is detected, correctly
modeling the counter as starting from 0 post-reset. This updates our
interpolate function to match the new behavior by removing the leftEdge
parameter and adjusting test expectations accordingly.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
roidelapluie added a commit to grafana/mimir that referenced this pull request Feb 5, 2026
The upstream Prometheus change (prometheus/prometheus#17988) fixed
incorrect interpolation when counter resets occur in smoothed range
selector evaluation. The old behavior asymmetrically handled counter
resets (y1=0 on left edge, y2+=y1 on right edge) which produced wrong
values.

The fix uniformly sets y1=0 when a counter reset is detected, correctly
modeling the counter as starting from 0 post-reset. This updates our
interpolate function to match the new behavior by removing the leftEdge
parameter and adjusting test expectations accordingly.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
roidelapluie added a commit to grafana/mimir that referenced this pull request Feb 5, 2026
The upstream Prometheus change (prometheus/prometheus#17988) fixed
incorrect interpolation when counter resets occur in smoothed range
selector evaluation. The old behavior asymmetrically handled counter
resets (y1=0 on left edge, y2+=y1 on right edge) which produced wrong
values.

The fix uniformly sets y1=0 when a counter reset is detected, correctly
modeling the counter as starting from 0 post-reset. This updates our
interpolate function to match the new behavior by removing the leftEdge
parameter and adjusting test expectations accordingly.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants