You might want to see if 
https://github.com/prometheus-community/prom-label-proxy provides what you 
need.

On Tuesday, 1 February 2022 at 21:33:11 UTC [email protected] wrote:

> Wow, I really appreciate this. Thanks so much. 
>
> Op dinsdag 1 februari 2022 om 22:05:36 UTC+1 schreef [email protected]:
>
>> Since rate() is a function, not a metric, you can't pass it to 
>> parser.ParseMetric() and expect it to work. You need to stick to ParseExpr 
>> and walk down the entire AST.
>> What you need to do is find all instances of parser.VectorSelector, 
>> which is the data structure that hold time series selectors in queries, and 
>> append labels there.
>> Here's an example: 
>> https://gist.github.com/prymitive/e021f48cda4744de24bce9c4b523c315
>>
>> If you need more example code check 
>> https://github.com/cloudflare/pint/blob/main/cmd/pint/parse.go
>> On Tuesday, 1 February 2022 at 19:47:16 UTC [email protected] wrote:
>>
>>> Hi everyone,
>>>
>>> I'm automating a way to modify Grafana Dashboards to our liking. For 
>>> example to use a public Grafana dashboard and append certain query labels 
>>> to every query in a dashboard. 
>>> For this, I figured to use the Prometheus Parser, which works well to 
>>> some extend for my use-case. However certain 'expressions' (or queries) 
>>> don't parse that well (or I'm doing it wrong). 
>>>
>>> As a quick draft I have the following code:
>>> ------
>>>     parsedExpr, _ := parser.ParseExpr(expr)
>>>     childExprs := parser.Children(parsedExpr)
>>>     parsedMainMetric, _ := parser.ParseMetric(expr)
>>>
>>>     fmt.Println(parsedMainMetric)
>>>     for _, childExpr := range childExprs {
>>>
>>>         parsedChildExpr, _ := parser.ParseMetric(childExpr.String())
>>>         fmt.Println(parsedChildExpr)
>>>     }
>>> ------
>>> Which works for:
>>>
>>> > input:    "rate(node_disk_io_time_seconds_total{bar=\"foo\"}[2m])",
>>>
>>> As this gives me the following output:
>>>
>>> > {__name__="rate"}
>>> > {__name__="node_disk_io_time_seconds_total", bar="foo"}
>>>
>>> However, lets say I change the input to: 
>>>
>>> > input:    "rate(node_disk_io_time_seconds_total{bar=\"foo\"}[2m]) > 0",
>>>
>>> Then it does not exactly go how I expected it to be:
>>>
>>> > {__name__="rate"}
>>> > {__name__="rate"}
>>> > {}
>>>
>>> (obviously this is mainly due to how I wrote my draft code). 
>>>
>>> I have seen https://demo.promlens.com/?l=eF6PYANAlbQ - and I was 
>>> wondering if someone could give me some pointers on how I should continue 
>>> (and if this is actually a viable option to update labels). 
>>>
>>> Thanks in advance,
>>>
>>> Wiard
>>>
>>

-- 
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/fe2e9481-765a-4be9-a76d-e88fc11b9146n%40googlegroups.com.

Reply via email to