2

I'm trying to create a variable in Grafana that will pull distinct servers from a BigQuery database. I would like to only pull these servers from within a given time window like one would normally with something like WHERE $__timeFilter(timestamp). Is it possible to use global variables within a query variable? I can't seem to find any documentation around this. For reference, I'm currently using

This query to get a list of all servers:

SELECT DISTINCT server FROM table WHERE timetamp < CURRENT_TIMESTAMP

Whereas I would like to use something like this to get a list of servers within the time window the user selects in Grafana:

SELECT DISTINCT server FROM table WHERE $__timeFilter(timestamp)
eshirvana
  • 23,227
  • 3
  • 22
  • 38
Bwilly
  • 21
  • 1
  • 1
  • 3
  • Why you don't use troubleshooting guide https://github.com/doitintl/bigquery-grafana#troubleshooting ? – Jan Garaj Oct 10 '21 at 06:59
  • @JanGaraj It looks like the query inspector that they're using is within the panel creation, where using $__timeFilter works fine and doesn't throw an error. When you are creating a variable from a bigquery data source you can't use the query inspector (nor any way of trouble shooting from what I can tell). – Bwilly Oct 10 '21 at 12:47
  • You can use network console to see how macros are interpolated. But I guess macros are not supported in the dashboard variable queries. – Jan Garaj Oct 10 '21 at 15:12

1 Answers1

0

Assuming that date_column is your date column in table, in the Google BigQuery's standard DATE format, you should convert it into a TIMESTAMP and then apply $__timeFilter.

SELECT DISTINCT server FROM table WHERE $__timeFilter(TIMESTAMP(date_column))
Talal
  • 69
  • 1
  • 6