Time range values not passed to variable queries

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

Grafana Cloud: Grafana v11.1.0-71516 (0ba54152dc)

  • What are you trying to achieve?

Load variable values from influxdb based on the selected time range

  • How are you trying to achieve it?

I have a query variable which selects all unique influxdb tag values in the selected time range:

import "influxdata/influxdb/schema"

schema.tagValues(bucket: "my_bucket", tag: "my_tag", start: v.timeRangeStart, stop: v.timeRangeStop)
  • What happened?

When the dashboard executes the query to load the variable values, it sends the query request without “from” and “to” values. This results in a status 400 response with the message “error”: “invalid: error in building plan while starting program: cannot query an empty range”, because v.timeRangeStart and v.timeRangeStop are both interpreted as 1970-01-01 (timestamp 0)

  • What did you expect to happen?

Load the tag values from the provided tag in the provided time range. This same query worked fine before in the same dashboard. The query still works fine in the data source explorer.

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

The HTTP request sent in the data source explorer:

{"queries":[{"refId":"A","datasource":{"type":"influxdb","uid":"redacted"},"query":"import \"influxdata/influxdb/schema\"\n\nschema.tagValues(bucket: \"my_bucket\", tag: \"my_tag\", start: v.timeRangeStart, stop: v.timeRangeStop)","datasourceId":12,"intervalMs":60000,"maxDataPoints":1572}],"from":"1717575257774","to":"1717578857774"}

The HTTP request sent from the dashboard upon reloading the variables:

{"queries":[{"refId":"metricFindQuery","query":"import \"influxdata/influxdb/schema\"\n\nschema.tagValues(bucket: \"my_bucket\", tag: \"my_tag\", start: v.timeRangeStart, stop: v.timeRangeStop)","rawQuery":true,"datasource":{"type":"influxdb","uid":"redacted"},"datasourceId":12,"maxDataPoints":1000}]}

As you see, the “from” and “to” keys in the request are missing.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

The query requests for the variables give status code 400. This results in the variable list being empty, and just showing the “all” value. This results in my dashboard query filtering on no tag value and showing “no data”. The dashboard query executes fine, as it seems to replace v.timeRangeStart/Stop in-line in the query.

  • Did you follow any online instructions? If so, what is the URL?


I also have this problem !!!
the following code was working fine up to 4-5 June

import “influxdata/influxdb/schema”

bucket: “MYBUCKET”,
tag: “Machine”,
predicate: (r) => r[“_measurement”] == “TELEM” and r[“Machine”] =~ /AA/,
start: v.timeRangeStart,
stop: v.timeRangeStop

if I just remove the stoprow it shows data, so there is a problem with start and stop param management !!
Note that this query works fine when used on a panel with table visualization.
Seems there is a problem on variables

in that variable’s config I would first query the min and max tag dates as separate variables, without any date time ranges as there is no date ranges when configuring a variable and feed those min max dates to the main tag query as start and end date ranges?

It works on Grafana 11.0 and below, so it looks like a recent change.

Could it be caused by this PR?

DISCLAIMER: With Flux, I couldn’t figure out how to get a Query-type variable to work, seemingly because Flux expects time bounds (|> range(start: v.timeRangeStart, stop: v.timeRangeStop)), and dashboard query variables don’t appear to support that. So the Flux-derived panels instead use Custom-type variables.

1 Like

Leaving out the stop time value does make sure that we receive the variable data, but it ignores the selected time range altogether. For now I’ve also done this, but it does seem like some bug slipped into grafana, as you’re also experiencing this.
Think I’ll create an issue over on github for this. Edit: Dashboards: InfluxDB Flux query dashboard variables fail since v11.1 · Issue #88983 · grafana/grafana · GitHub


1 Like