grafana / google-bigquery-datasource

Google BigQuery Datasource Plugin for Grafana.
Apache License 2.0
25 stars 13 forks source link

Dynamic way of getting a 'default dataset' or 'default region'? #258

Open MatinF opened 4 months ago

MatinF commented 4 months ago

We are trying to create a Grafana-BigQuery dashboard template as per below screenshot. The goal is to provide this template to our end users who will deploy it with their own BigQuery datasources across the globe.

These users will have their own dataset names and are trying to make this as dynamic as possible by e.g. querying the user's dataset via a Variable query as below:

SELECT
  schema_name as dataset_id
FROM
 region-europe-west3.INFORMATION_SCHEMA.SCHEMATA

This returns the datasets in that region - but it has the downside, as evident, that the region has to be hardcoded by every user that deploys the template - either by editing the template JSON, or by editing the Variable once loaded.

We need the dataset as it serves as a variable in our panel queries, which look as below:

SELECT
  TIMESTAMP_MILLIS(DIV(UNIX_MILLIS(t), $__interval_ms) * $__interval_ms) as time,  
  ${signal_value:csv}
FROM
  ${dataset}.tbl_${device:csv}_${message:csv}
WHERE
  $__timeFilter(t)
GROUP BY
  time

We can of course consider adapting our guide to enforce that the user has to specify a specific dataset name - but we would rather want to make this more dynamic. Is there a way to return a 'default' dataset and/or 'default' region for a Project via e.g. macros/variables?

image

gabor commented 3 months ago

hi @MatinF , as far as i understand there's no default-region or default-dataset as a concept in bigquery (feel free to correct me if i'm wrong 😄 ), so ... i'm not sure how would this work. i mean, the user would have to fill in these 2 values somewhere, right?

i would recommend creating a custom dashboard variable for this, and the user only has to adjust that single one, and then the other dashboard-queries would use the value of that custom variable.