Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min and max as binary operators #5177

Closed
xinau opened this Issue Feb 1, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@xinau
Copy link

xinau commented Feb 1, 2019

Proposal

Adding min and max as binary operators to promql.

Use case. Why is this important?
I've got two different timeseries and want to join them by using the maximum value of the two.
For example

timeseries_a{foo="bar"} 4
timeseries_b{foo="bar"} 7

I would like to do the following promql

timeseries_a bin_op_max timeseries_b

instead off doing something like this
https://www.maa.org/programs/faculty-and-departments/classroom-capsules-and-notes/the-maximum-and-minimum-of-two-numbers-using-the-quadratic-formula

# for maximum
(timeseries_a + timeseries_b + abs(timeseries_a - timeseries_b)) / 2
(vector(4) + vector(7) + abs(vector(4) - vector(7))) / 2
# for minimum
(timeseries_a + timeseries_b - abs(timeseries_a - timeseries_b)) / 2
(vector(4) + vector(7) - abs(vector(4) - vector(7))) / 2

, as this can get difficult with (on, group_left ...)

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Feb 1, 2019

You can do a > b or b

@xinau

This comment has been minimized.

Copy link
Author

xinau commented Feb 2, 2019

Thank you @brian-brazil.

@xinau xinau closed this Feb 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.