Skip to content

fix(engine): align range-query evaluation timestamps to the step grid - #20904

Merged
DylanGuedes merged 3 commits into
mainfrom
fix/range-agg-step-alignment
Feb 23, 2026
Merged

fix(engine): align range-query evaluation timestamps to the step grid#20904
DylanGuedes merged 3 commits into
mainfrom
fix/range-agg-step-alignment

Conversation

@DylanGuedes

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
On this PR I'm aligning startTs to the nearest epoch-aligned step boundary, to replicate the same behavior we'd have with the old engine. I found this to cause a sum by(x)(count_over_time({k="v"}[30m)) query to mismatch old vs the new engine.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR
Range queries (step > 0) must evaluate at timestamps that are multiples
of `step` relative to the Unix epoch, matching Prometheus's standard
behaviour.

The fix floors `startTs` to the nearest epoch-aligned step boundary
before building the windows array, and propagates the aligned value back
into `opts.startTs` so that the matcher factory's index arithmetic stays
in sync with the windows.
@DylanGuedes
DylanGuedes requested a review from a team as a code owner February 21, 2026 00:29
@ashwanthgoli

Copy link
Copy Markdown
Contributor
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Feb 23, 2026
@DylanGuedes
DylanGuedes force-pushed the fix/range-agg-step-alignment branch from b9cfeea to 9aa9e5e Compare February 23, 2026 10:29
@pull-request-size pull-request-size Bot added size/M and removed size/L labels Feb 23, 2026

@ashwanthgoli ashwanthgoli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@DylanGuedes
DylanGuedes merged commit 28d03ec into main Feb 23, 2026
149 of 151 checks passed
@DylanGuedes
DylanGuedes deleted the fix/range-agg-step-alignment branch February 23, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants