In my opinion we should not rely on PromQL engine optimisations where  this 
optimisations may be omitted by better written expression. Sorry for being 
picky :)

You answered my question in this topic, and I agree with you, but we 
drifted a bit from original problem in github feature request. Let me 
rephrase it a bit to make it more clear:

*I want to be able to provide my k8s tenants same level of isolation by 
default in Prometheus(using namespace label) as it is in Kubernetes (by 
namespace). *

Proposed with_labels parameter in prometheus rules and with_labels PromQL 
function is only suggested option to resolve this issue. I know Prometheus 
is not limited to k8s world - but still for other use cases this feature 
will be useful.

I looked into solutions like jsonnet but I don't see any other way to do 
this without parsing PromQL


On Thursday, April 23, 2020 at 2:35:16 PM UTC+2, Brian Candler wrote:
>
> Sure, both LHS and RHS there return an unnamed timeseries with no labels.
>
> Are you aiming to do something like this?
> sum(up{job="node_exporter", fqdn=~"n.*", namespace="foo"}) / 
> sum(up{job="node_exporter", namespace="foo"})
>
> You can get sum() to return results with labels, using sum by:
>
> sum by (namespace,job) (up{job="node_exporter", namespace="foo", 
> fqdn=~"n.*"}) / sum by (namespace, job) (up)
>
> I agree it's not shorter, and it depends on PromQL engine optimisations if 
> it's going to be equally efficient, but it does at least move the logical 
> conditions into one place.
>
> It does let you get the results for all namespaces at once if you want:
>
> sum by (namespace,job) (up{job="node_exporter", fqdn=~"n.*"}) / sum by 
> (namespace, job) (up)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/193091bf-22e1-45d3-b141-9d8ca528a1a5%40googlegroups.com.

Reply via email to