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

PromQL: scalar comparison for range selector #10399

Open
roidelapluie opened this issue Mar 4, 2022 · 7 comments · May be fixed by #14095
Open

PromQL: scalar comparison for range selector #10399

roidelapluie opened this issue Mar 4, 2022 · 7 comments · May be fixed by #14095

Comments

@roidelapluie
Copy link
Member

roidelapluie commented Mar 4, 2022

Proposal

Use case. Why is this important?

It would be great if we could do: avg_over_time(probe_duration_seconds[10m] != 0). This could happen between a range selector and scalars. This would work directly on the samples of the selection, samples not matching would be dropped. This could be combined: avg_over_time(probe_duration_seconds[10m] > 0 < 10)

This is more effective that doing a subquery, which, additionally, requires you to know the scrape interval.

@roidelapluie
Copy link
Member Author

cc @juliusv

@juliusv
Copy link
Member

juliusv commented Mar 5, 2022

No strong opinion on this yet, but once we go that direction, we could also consider a whole lot more variations:

  • The same between a range vector and an instant vector (I don't see how the other way around would work).
  • The same for arithmetic and set ops (for example, you could also have used an and operator, like probe_duration_seconds[10m] and probe_success == 1, or maybe in other cases you'll want to multiply or add an offset to all values before averaging them.

@roidelapluie
Copy link
Member Author

roidelapluie commented Mar 5, 2022

What would it change for instant vector? For instant vector this should already work with current promql.

@juliusv
Copy link
Member

juliusv commented Mar 5, 2022

I mean between a range vector and an instant vector: foo[5m] > bar

@roidelapluie
Copy link
Member Author

I think we can limit this to scalar for now.

@mabhi
Copy link
Contributor

mabhi commented Feb 17, 2023

@roidelapluie I would like to work on this proposal.
Could you provide some more expressions I can analyse with, especially combination of operators like the one you put in the description above.
As I have only come across operator combination in logical expressions, would that suffice here. e.g. avg_over_time(probe_duration_seconds[10m] > 0 < 10) be equivalent to avg_over_time(probe_duration_seconds[10m] > 0 ) and avg_over_time(probe_duration_seconds[10m] < 10)

@mabhi
Copy link
Contributor

mabhi commented Feb 22, 2023

@roidelapluie, as per my understanding, when applying a scalar on to a range vector, does this illustration below depict the correct behavior / results or the expected outcome is something else. Request your feedback here, please.

Input: prometheus_http_requests_total[2m] actual samples

  • prometheus_http_requests_total{code="200", handler="/api/v1/query", instance="localhost:9090", job="prometheus"}
    5 @123456
    3 @123476
    
  • prometheus_http_requests_total{code="200", handler="/metrics", instance="localhost:9090", job="prometheus"}
     5 @123456
     2 @123476
     3 @123496
     23 @123116
     13 @123136
    

expected outcome prometheus_http_requests_total[2m] > 4

  • prometheus_http_requests_total{code="200", handler="/api/v1/query", instance="localhost:9090", job="prometheus"}
    5 @123456
    
  • prometheus_http_requests_total{code="200", handler="/metrics", instance="localhost:9090", job="prometheus"}
     5 @123456
     23 @123116
     13 @123136
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants