Hi,

On 12/3/20 10:06 AM, lizhihua0925 wrote:
What I want to do is limit the rule to eval metrics which have the spcified label.
Ah, I understood that you wanted to add labels, but you already said that you wanted to add matchers.

So, just to confirm that I understand correctly:

If the user enters the expression 'foo > 1' it should automatically be modified to read 'foo{some_static_label="some_dynamic_value"} > 1', right?

So, basically you are looking for a way to programatically modify PromQL expressions.

This is possible, prefereable by using Go as that's where the reference PromQL parser happens to be.

That sounds like what I'm doing in the prometheus-filter-proxy except that I'm modifying in-flight requests while you want to modify PromQL expressions in alerts. You could still use the same pattern:

* Parse the expression
* Traverse all relevant selectors
* Add the matcher you want
* Convert to string representation again

For reference: https://github.com/hoffie/prometheus-filter-proxy/blob/master/filter.go#L57

There are other projects which do similar things, e.g. in the Kubernetes/OpenShift ecosystem. This may provide further inspiration. :)

Kind regards,
Christian

--
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/513ec04f-e1b7-278c-cb11-2217e6af7ef7%40hoffmann-christian.info.

Attachment: OpenPGP_0x2C1F41CF361CB280.asc
Description: application/pgp-keys

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to