Allow dashboard variables to work across multiple datasources

I am trying to create a dashboard where dashboard variables can pull and combine values from multiple datasources. Currently, Grafana variables require a single datasource for query variables, which prevents me from:

  • Creating a variable that represents the union of values from multiple datasources (e.g., $data1 from datasource A and $data2 from datasource B).

  • Using a single variable as a filter across panels where each panel may query a different datasource.

  • Providing an “Include All” or combined selection behavior for multiple datasources.

My use case:

  1. I have multiple clusters, each with its own datasource (Prometheus, Azure Monitor Workspace, etc.).

  2. I want a variable (e.g., namespace) that aggregates values across all clusters. Or even a solution that inspects all data sources and determines the appropriate namespaces using only the cluster variable.

  3. Panels select the appropriate datasource dynamically based on cluster selection.

  4. Currently, this setup is not possible, because variable queries can only target one datasource.

Practical case:

I currently have three variables: datasource, cluster, and namespace. I want to remove the datasource variable. I can convert cluster into a custom variable, but then the namespace variable would need to search across all data sources and query them based on the selected cluster value.

Questions / requests:

  1. Is there a supported method to create a variable that merges values from multiple datasources?

  2. If not, please consider this as a feature request: allow variables to query multiple datasources and provide combined “Include All” behavior.

  3. Any recommended workarounds or best practices for multi-datasource variables in dashboards would be appreciated.

Thank you for your time and support.

1 Like

Hi, I can think of one possible solution - you can create a hidden variable per each datasource and then combine them in the namespace variable via Infinity plugin - you can inline Json and use your previous variables like ${var:json} or something like that. More variables to create but less variables for your users.

As for feature request, you’d probably be better off (and most probably asked to) create an issue on Github.

1 Like

Thanks for the help!

I tried it with the following configuration (see screenshot below), but the result is still empty.

What’s confusing is that the variable namespace_notmanaged does return values, so the variable itself seems to work. I’m just not sure why those values don’t show up here. Am I missing something about how the variable is being referenced or evaluated?

Update:

It worked! It might not be the cleanest solution, but I can finally move forward. Thank you so much for your suggestion @dawiddebowski

1 Like

Hi @claucarregosa ,

  1. Questions / requests:

    1. Is there a supported method to create a variable that merges values from multiple datasources?
      Ans:-
      Federation / aggregation at the data layer

      If the datasources are the same type (most commonly Prometheus based):-

      Prometheus Federation

      • Create a central Prometheus that federates others

      • Point Grafana at the federated Prometheus

      • Create your variable from that single datasource