Grafana - use custom variable as regex in query

Amjad Hussain Syed picture Amjad Hussain Syed · Mar 20, 2019 · Viewed 11.8k times · Source

we have prometheus datasource and I’m stuck at trying to use custom variable with few values as comma separated values, I wanted to use it to replace as regex in the label_values(job=~$"{eks_cluster:regex}"), but i get the error templating variables could not be initialized. Following are the screenshots to show what I’m trying to achieve enter image description here

enter image description here

Answer

Michał Politowski picture Michał Politowski · Mar 20, 2019

Your problem is not with the eks_cluster variable. This will just as much not work if the query is simply label_values(job=~".")

The label_values query, as described in Grafana documentation, takes either a label name or a label name and a metric name. It does not take a match to do whatever you wanted it to do. If you want to filter the values returned, use the Regex field just below Query.