1

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/

Balaraman L
  • 196
  • 2
  • 12
  • You could use either Grafana's query inspector (somewhere to the right of the query, if this a query from a panel) or your browser's network inspector to compare what the HTTP query looks like in the two cases. That should help you figure out why the behavior is different. – Alin Sînpălean Aug 28 '19 at 14:57
  • Thanks for the comment @AlinSînpălean. I have checked that with "Query inspector" tool too. Ideally, ```${t_var:pipe}``` should have given me ```value1|value2|value3``` according to the "advanced formatting" that Grafana claims. Instead, it is still showing as ```${t_var:pipe}```. This didn't change even if I put that outside of quotes as well. – Balaraman L Aug 29 '19 at 06:54
  • @AlinSînpălean I have found the solution for my problem and updated that in answer to this question. Thanks. – Balaraman L Aug 29 '19 at 07:15

1 Answers1

0

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}}

Community
  • 1
  • 1
Balaraman L
  • 196
  • 2
  • 12