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).
Thanks in advance,
Wiard