Skip to content

Conversation

@ADITYATIWARI342005
Copy link
Contributor

Problem

The PromQL parser allowed invalid syntax like:

metric offset 5m[2m:10s]  # Should error, but was accepted
metric @ 123[2m:10s]      # Should error, but was accepted

While correctly rejecting the same pattern for regular range selectors:

metric offset 5m[2m]  # Correctly rejected

Solution

Added validation in the subquery_expr grammar rule to reject offset/@ modifiers when they appear immediately adjacent to the subquery bracket (no space between them).

The fix uses position checking (vs.PosRange.End == $2.Pos) to distinguish between:

  • metric offset 5m[2m:10s]Error (adjacent tokens, invalid)
  • metric offset 5m [2m:10s]Valid (spaced, subquery on offset result)

This makes subquery parsing behavior consistent with matrix_selector rules.

Testing

  • Added test case for some_metric OFFSET 1m[5m:10s] expecting parse error
  • Verified runtime behavior with API calls
  • All offset-related tests pass
  • Preserves valid use cases with spacing

Which issue(s) does the PR fix:

Fixes #17060

Does this PR introduce a user-facing change?

[BUGFIX] PromQL: Reject offset and @ modifiers immediately before subquery range selectors (e.g., `metric offset 5m[2m:10s]`). Valid syntax with spacing still works (e.g., `metric offset 5m [2m:10s]`).

Fixes a parser bug where offset and @ modifiers were incorrectly allowed
immediately before subquery range selectors like [5m:10s]

Signed-off-by: ADITYA TIWARI <adityatiwari342005@gmail.com>
@ADITYATIWARI342005 ADITYATIWARI342005 marked this pull request as draft January 14, 2026 04:48
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.

Offset should not be allowed before a range vector selector

1 participant