3 Environment Dashboard Variables => 2 DataSource Variables?

We have 3 environments in our setup staging / sandbox / prod and they use 2 different prometheus data sources dev / prod. Staging and Sandbox lives in the dev prometheus, and prod lives in prod.

I am looking for a way to set the datasource as a variable based on the selection of the environment, such that:

  • selection of staging changes datasource variable to dev
  • selection of sandbox changes datasource variable to dev
  • selection of prod changes datasource variable to prod

I know I can do this with 2 different dashboard variable dropdowns, but Ideally I would like to hide the datasource variable and change them with a single environment selection. Is this possible?

Hi @coneybeare,

Did you find any solution for your problem ?
I am facing the similar challenge with Azure monitor data source.

create Custom variable. spacing is critical here for kv pair (k: seen in UI, v: used in queries etc)

staging : dev,  sandbox : dev, prod : prod

image

I’m also in need to be able to switch through datasource using variables.

I found a hacky way, using a Custom variable, with Key and Value. Where the Value is the ID of the datasource. Image below.

The UI won’t support that directly, but if you edit the Panel’s JSON and add the variable `${datasrcs.value}, it will work and the query will work as expected. But the Panel UI will seem broken if you’ll try to edit it, as a result of it not knowing how to handle this hack.

Cursom Var with Key : Datasource_id

Panel’s JSON - adding the variable directly.
image