Skip to content

Conversation

roidelapluie
Copy link
Member

No description provided.

@roidelapluie roidelapluie force-pushed the add-step-promql branch 5 times, most recently from 6253826 to ff7572c Compare June 26, 2025 12:00
@roidelapluie roidelapluie changed the title [WIP] Add step() in promql duration expressions Add step() in promql duration expressions Jun 26, 2025
@roidelapluie roidelapluie force-pushed the add-step-promql branch 3 times, most recently from b549206 to 140abe4 Compare June 26, 2025 12:50
@roidelapluie roidelapluie requested review from beorn7 and krajorama June 26, 2025 12:51
@roidelapluie roidelapluie marked this pull request as ready for review June 26, 2025 12:52
Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this.

@roidelapluie
Copy link
Member Author

Thanks for doing this.

I have updated the PR with your comments.

@roidelapluie
Copy link
Member Author

Funnily enough, rate [5m x 5m] was parsed correctly.

Fixed by this PR too.

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.

Looks good, but I wonder if adding min/max was intentional?

If yes, please update PR description as well.

@roidelapluie roidelapluie force-pushed the add-step-promql branch 4 times, most recently from c4bdbb7 to 02cca53 Compare June 30, 2025 15:06
@roidelapluie roidelapluie changed the title Add step() in promql duration expressions Add step(), min() and max() in promql duration expressions Jun 30, 2025
@roidelapluie roidelapluie requested a review from krajorama June 30, 2025 15:20
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, just a couple of more unit test cases 2x2 and you're done I think

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. I'm OK with this, especially since this is experimental and I'm not likely to spot random edge cases.

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Just nit-picking left for documentation. Otherwise LGTM.

step() is a new keyword introduced to represent the query step width in duration expressions.

min(a,b) and max(a,b) return the min and max from two duration expressions.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Signed-off-by: Julien <291750+roidelapluie@users.noreply.github.com>
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

@ringerc
Copy link
Contributor

ringerc commented Aug 1, 2025

Adding a quick summary of what's added here as best I can tell:

  • A new step() pseudo function that returns the step interval in float seconds of the current range-query step. It looks (unconfirmed) like this doesn't work in subqueries inside instant queries, and always returns the outermost query's step in range queries.
  • support for min() and max() in PromQL duration expressions guarded by --enable-feature=promql-duration-expr

@beorn7
Copy link
Member

beorn7 commented Aug 1, 2025

Yes, it returns the step parameter from the range query. This is deliberate. (You know the step for a sub query anyway as it is set in the very same query.)

@bboreham
Copy link
Member

Ref #15862 (comment) where step() was requested.

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.

6 participants