Skip to content

feat/ui: add editor support for experimental PromQL duration expressions - #18561

Closed
adity-a34 wants to merge 2 commits into
prometheus:mainfrom
adity-a34:feat-promql-duration-expression
Closed

adity-a34 wants to merge 2 commits into
prometheus:mainfrom
adity-a34:feat-promql-duration-expression

Conversation

@adity-a34

Copy link
Copy Markdown
Contributor

Add grammar, highlighting, autocompletion, and linting for the step(), range(), min(), and max() duration pseudo-functions behind --enable-feature=promql-duration-expr.

  • lezer-promql: add DurationExpr rule; update MatrixSelector and SubqueryExpr to accept DurationExpr in duration slots; define DurationStep/DurationRange via condFn to preserve step/range as valid identifiers outside duration context
  • highlight.js: tag DurationExpr child nodes as function(variableName)
  • promql.terms.ts: add durationExprTerms with step(), range(), snippets
  • hybrid.ts: add ContextKind.DurationExpr; use node.getChild('DurationExpr') instead of containsAtLeastOneChild with string arg; add dedupeCompletions
  • parser.ts: warn when range() is in subquery step position; error on step()/range() in offset position without duplicating parse error

Which issue(s) does the PR fix:

Fixes #17742

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

[ENHANCEMENT] UI: Add syntax highlighting, autocompletion, and linting for experimental PromQL duration expressions (`step()`, `range()`, `min()`, `max()`) in range selectors and subqueries.

Testing

I used the following expression to validate the implementation is correct:

  1. http_requests_total[step()] and rate(metric[min(5m,range())]) - no lint errors, step()/range()/min() syntax-highlighted correctly; backend errors are expected without --enable-feature=promql-duration-expr.
  2. Autocomplete inside rate(metric[ - dropdown correctly surfaced step(), range(), min(, ), max(, ) alongside existing duration unit literals (d, h, m, etc.).
  3. foo offset step() - targeted lint error shown with offset and step() underlined; no duplicate generic parse error emitted.

@adity-a34
adity-a34 requested review from a team, Nexucis and juliusv as code owners April 22, 2026 06:42
@adity-a34

Copy link
Copy Markdown
Contributor Author

cc: @juliusv @roidelapluie

Please review!

Add grammar, highlighting, autocompletion, and linting for the
step(), range(), min(), and max() duration pseudo-functions
behind --enable-feature=promql-duration-expr.

- lezer-promql: add DurationExpr rule; update MatrixSelector and
  SubqueryExpr to accept DurationExpr in duration slots; define
  DurationStep/DurationRange via condFn to preserve step/range as
  valid identifiers outside duration context
- highlight.js: tag DurationExpr child nodes as function(variableName)
- promql.terms.ts: add durationExprTerms with step(), range(), snippets
- hybrid.ts: add ContextKind.DurationExpr; use node.getChild('DurationExpr')
  instead of containsAtLeastOneChild with string arg; add dedupeCompletions
- parser.ts: warn when range() is in subquery step position; error on
  step()/range() in offset position without duplicating parse error

Signed-off-by: ADITYA TIWARI <[email protected]>
@adity-a34
adity-a34 force-pushed the feat-promql-duration-expression branch from 071ff30 to 8d2129e Compare April 22, 2026 06:55
@adity-a34

Copy link
Copy Markdown
Contributor Author

my changes do not touch any Go code so I guess the CI / Go tests on Windows (pull_request) is flaky.

@roidelapluie

Copy link
Copy Markdown
Member

Thanks!

A quick test in the netlify preview is not looking great:

image

@adity-a34

adity-a34 commented May 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks!

A quick test in the netlify preview is not looking great:

Hi @roidelapluie I see there is a PR linked that fixes this review/issue.
Do I need to take another look at this PR? (I have my end-semester exams ongoing so I am a bit occupied.)

@bboreham

bboreham commented Jun 9, 2026

Copy link
Copy Markdown
Member

Hello from the bug-scrub!

@adity-a34 yes, #18625 took your work here and added a bit more. As you can see in the discussion there, it was not perfect. If you have some time, please contribute to that discussion or continue the work here.

@roidelapluie

Copy link
Copy Markdown
Member

Merged in #18625, thanks!

@adity-a34

Copy link
Copy Markdown
Contributor Author

Completed in #18625.

@adity-a34 adity-a34 closed this Jul 13, 2026
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.

UI follow-up for PromQL duration expression: add range(), step(), min(), max()

3 participants