If you need to change an entire query, you can map those to custom variable (given that the key value pairs are not used), e.g.: foo : sum(rate(go_gc_cycles_automatic_gc_cycles_total[5m])), bar : vector(0)
and then just use the variables like that:
Only the name of the metric is changing the query, right. And yes, I’d like to change the entire query but per panel. I could pass the query as a custom value but imagine there are N panels and want to replace for each one.
I don’t think I understand tbh. Let’s say you have a dashboard with two panels - panelA and panelB. Also, you have a variable there with possible values foo, bar, and baz (I know you have the key-value pairs, but for simplicity let’s omit those).
panelA has query: sum(rate(metric_foo)) and
panelB has query avg(rate(metric_foo))
Now I change foo to bar in the variable list. What would you like to happen? Also please tag me in your response, cause I don’t get notifications and otherwise I’m not going to see your response
Thanks @dawiddebowski, but what if i have multiple panels and want to change on each based on provided variable? It seems this way would only support for one panel. (Since we can only pass one query per one variable)
You could always create one hidden variable per one panel. But I fail to understand why would you want to change all the queries. What’s your use-case for that? I mean I would find it pretty confusing.
Hi @dawiddebowski
I have a use case which might be related/interesting/impossible;
I have multiple panels and one variable type (ssd, hdd). Now this variable is used as is in the query labels, but I’d also like to set some other labels based on that, eg:
If the variable is set to ssd, I want the label type="$type" but also some label pool=~"1|3|5"
but if the variable is set to hdd I want pool=~"2|4|6"
If so, you can create a variable (e.g. named filter) of type query with infinity plugin, type CSV, parser Backend, source Inline (ofc you can also use json but I’m quite used to CSV in that case).
As for the data, go with such csv:
Then toggle computed columns, filter, group by and in filter type in contains(“${type}”, Type) (first ${type} refers to your variable, second Type refers to the column in csv). Run the query and it should work (I’ve never tested it for multi value variable though, so I’m not sure it would work).
In your query use (metric name is sample, I assume you’re using PromQL): some_metric{type=“$type”, $filter}. I’m not too familiar with vanilla PromQL but it should work (I’m mainly considered with the , part but as long as you’re always setting ssd or hdd it should be fine). I think it should work for you (worked for me at least).
If you don’t have infinity plugin installed nor you want to install it, let me know, but I’m not sure I’ll come up with something then
P.S. the column doesn’t have to be called Type, it can as well be type, I’m just typing it on IPad and I still haven’t figured out how not to capitalize the first letter of the new line