Include All and Multi-value in InfluxDB Flux Query Variable

  • What Grafana version and what operating system are you using?
    Grafana Cloud

  • What are you trying to achieve?
    Inject multiple values into Flux query for dashboard panel

  • How are you trying to achieve it?
    Using variables from a Flux metadata query

  • What happened?
    Works with single values, fails with multiple

  • What did you expect to happen?
    Works with single, multiple, all

  • Can you copy/paste the configuration(s) that you are having problems with?

Basically I am using a query variable where I want to be able to use multiple values in my dashboard. If one is selected, it inputs the string into the query. When using multiple values from the variable, they are input as comma seperated values in curly brackets. My query then returns empty. How do I use this with Flux to get multiple values in my dashboard panel?

Query Variable:

import “influxdata/influxdb/schema”

schema.measurementTagValues(
bucket: “TrainingLogProd”,
tag: “strategy”,
measurement: “modelTraining”,
)

Flux query:
from(bucket: “TrainingLogProd”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “modelTraining”)
|> filter(fn: (r) => r[“strategy”] == “${Strategy}”)
|> filter(fn: (r) => r[“_field”] == “accuracy”)

Single value selected:
from(bucket: “TrainingLogProd”)
|> range(start: 2023-01-19T18:47:53.902Z, stop: 2023-01-26T18:47:53.902Z)
|> filter(fn: (r) => r[“_measurement”] == “modelTraining”)
|> filter(fn: (r) => r[“strategy”] == “strategy1”)
|> filter(fn: (r) => r[“_field”] == “accuracy”)

Multiple values selected:
from(bucket: “TrainingLogProd”)
|> range(start: 2023-01-19T18:47:53.902Z, stop: 2023-01-26T18:47:53.902Z)
|> filter(fn: (r) => r[“_measurement”] == “modelTraining”)
|> filter(fn: (r) => r[“strategy”] == “{strategy1, strategy2, strategy3}”)
|> filter(fn: (r) => r[“_field”] == “accuracy”)

Well I found the first important step. Formatting the variables.

https://stackoverflow.com/questions/70988924/what-is-the-optimal-way-to-write-a-flux-query-with-a-long-list-of-tag-filters

This seems to work, except there’s forward slashes in my query variable values so it breaks. Let me know if someone has another solution that might work.