Grafana templating variable with "all" or multiple values selected isn't working

Hello,

  • Using InfluxDB 1.8
  • Grafana 7.1.5

I am trying to use templating variables in my Flux query. So variable1 is set up as:
SHOW TAG VALUES WITH KEY = “myTag”

And then I enable the “Multi-value” and “Include All option” in the variable’s settings.
I get no data returned from the query, because selecting “All” passes in a list for {$variable1}.

Here is the filter part of the query:
|> filter(fn: (r) => r._measurement == "stuff" and r._field == "my_field" and r._value > 0 and r.myTag == "${variable1}"

When I inspect the query, I can see that it is generating this query:
|> filter(fn: (r) => r._measurement == "stuff" and r._field == "my_field" and r._value > 0 and r.myTag == "{someValue1,someValue2,someValue3,someValue4,someValue5}"

So this query is obviously not formatted correctly for InfluxDB which needs the values OR’d together or some type of regular expression.

Any ideas on how I can fix this query so that I can use templated variables with the “all” and multi value" options?

Thanks!

I’ve figured out my own question in case anyone runs into this. I had to use regular expressions with a pipe separator to get the query to work for InfluxDB.

So my filter part of my query is now:
|> filter(fn: (r) => r._measurement == "stuff" and r._field == "my_field" and r._value > 0 and r.myTag =~ /${variable1:pipe}/

Now it works great.

1 Like

Hi @shanacb,
Did you chain or create dependent variables
Example:

How can i do the following using flux in Grafana Variables?
Using influxql
1)
I have the first variable called Site_Name (pull it from the query)
SHOW TAG VALUES WITH KEY=“Site”

Second variable called Env (pull it from the query based on filter using Site_Name)
SHOW TAG VALUES WITH KEY=“Environment” WHERE Site =~ /$Site_Name/