Search code examples
grafanaprometheusgrafana-templating

Unable to pipe template variables in Grafana 4.5.2


In Grafana, I have a template variable which I want to pipe for running a prometheus query.

query{key='value1|value2|value3'} works for me.

Whereas, I have a template variable (Type: Query with Prometheus datasource and filtered with regex) called $t_var which can take values ['value1','value2','value3']

But, when I try the following query, I don't get any results:

query{key=~'${t_var:pipe}'}

Look at the pipe section in Grafana documentation: https://grafana.com/docs/reference/templating/


Solution

  • I have solved this problem without using any advanced formatting techniques such as pipe, json, csv, etc., as mentioned in this Grafana documentation.

    Change required was very simple:

    Instead of trying to concatenate list of template variables by pipe, I passed the whole template variable inside the query and also made 'Legend' as the template variable.

    For example, my modified query is as follows:

    query{key=~'[[t_var]]' Legend format is {{t_var}}