Skip to content

[bugfix] Correct end time adjustment for query range#6360

Merged
ruslan-mikhailov merged 9 commits intografana:mainfrom
ruslan-mikhailov:bugfix/recent-query-end-cutoff
Feb 9, 2026
Merged

[bugfix] Correct end time adjustment for query range#6360
ruslan-mikhailov merged 9 commits intografana:mainfrom
ruslan-mikhailov:bugfix/recent-query-end-cutoff

Conversation

@ruslan-mikhailov
Copy link
Copy Markdown
Contributor

@ruslan-mikhailov ruslan-mikhailov commented Feb 2, 2026

What this PR does: fixes QueryEndCutoff for query range. Query frontend initialises query range handler with combiners and alignment first, which leads to two bugs: empty buckets after cutoff and ignoring the param if end is not aligned.

Before:
image
After:
Pasted image 20260202071617

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@ruslan-mikhailov ruslan-mikhailov force-pushed the bugfix/recent-query-end-cutoff branch from a21f517 to 8510258 Compare February 2, 2026 11:25
@ruslan-mikhailov ruslan-mikhailov force-pushed the bugfix/recent-query-end-cutoff branch from 8510258 to 7a5290b Compare February 2, 2026 14:51
Copy link
Copy Markdown
Contributor

@javiermolinar javiermolinar left a comment

Choose a reason for hiding this comment

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

Is there any e2e test we can test this?

Comment thread modules/frontend/frontend.go Outdated
[]pipeline.AsyncMiddleware[combiner.PipelineResponse]{
headerStripWare,
adjustEndWareNanos,
// adjustEndWareNanos, // due to alignments and combiner, it needs to be done in handler
Copy link
Copy Markdown
Contributor

@javiermolinar javiermolinar Feb 2, 2026

Choose a reason for hiding this comment

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

This is not just for clamping the end, it also provides a default start and end. The idea is to simplify the existing logic by relaying on it. Is there a way to keep it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Summary of the discussion: currently, it is not possible to do. In order to support the middleware is to force combiner initialisation only after all handlers are applied. There are a couple of ways to do it, but it's not a minor refactoring, so we decided to do it separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added ToDos

maxEnd := now.Add(-cfg.QueryEndCutoff)
reqEnd := time.Unix(0, int64(req.End))
if reqEnd.After(maxEnd) {
req.End = uint64(maxEnd.UnixNano())
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.

What's wrong with the existing reqEnd? The code does something similar, substracting the EndCutOff to time.Now()

Copy link
Copy Markdown
Contributor

@javiermolinar javiermolinar left a comment

Choose a reason for hiding this comment

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

We can make the roundtrip/combiner more flexible later. This is good for now.

@ruslan-mikhailov ruslan-mikhailov merged commit aa36f73 into grafana:main Feb 9, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants