Aligning the uid's for datasources across multiple instances of Grafana

  • What Grafana version and what operating system are you using?
    Grafana v12.0.2 (NOT in a Docker container), RHEL8

  • What are you trying to achieve?
    find the best practice for setting up connections to the data sources across more than once instance of Grafana.

We have 3 separate environments: Development, PreLive and Production.
We have an instance of Grafana installed in each.

When we copy a dashboard from one instance to another, the JSON specifies a UID for that datasource in each panel. As the datasource UIDs don’t match in each environment, I’m having to do a find/replace before importing the JSON.

I saw a post that mentions setting up a dashboard variable for the datasource instead.
I can see how to do this but I’m assuming that when i come to copy over Alert rules, I’m going to run into the same sort of issue.

Is there a way go into the Grafana backend somehow and change the UIDs so I can make them the same in all 3 environments?
Does anyone have any better suggestions?
What’s the best practice here?

Thanks for any help you can offer!

All the best :slight_smile:

Are these dev/qa/production type of environments?

if you want to keep those uids the same across environments, it probably is best to use provisioning.

ooh. That looks interesting. I wasn’t aware of that facility.
So if I define my datasources in a yaml, Grafana will pick them up and use them.
I take it I can set the UIDs for them there?
As I’ve already got Grafana instances with the datasources in place, is there a way to export the settings ready for the yaml file?
Failing that, could someone point me in the direction of a page explaining how I define all the parameters?
I’ve got sources I’ll need to replicate for InfluxDB (v2), Loki & Infinity.
Thanks all!

1 Like

but again. you have not answered what all this instances are that requires copying dashboard jsons :wink:

another option is to use git sync. so your dashboards are artifacts committed to gitlab

Sorry, I thought that was implicit in my original description. Yes. They are.
All the best.
M.

Just so the followup question doesn’t get lost, here it is again:

Thanks again!

Here you go

Ta.
Does that mean there isn’t a way to export the current settings for the data sources that were entered via the UI?

Hi All,
In case it’s of any use to others, I’ve worked out how to get the current settings for the DataSources.

For background - our Grafana runs on RHEL8 and we’ve set it up for https.

  1. Log onto the server
  2. Run the following command to return a list of the data sources from the API:
curl -k https://GrafanaAdminUsername:GrafanaAdminPassword@localhost:3000/api/datasources

Hint: if your password has any special characters in it, you can escape them with a backslash (\).

This should respond with a chunk of JSON with the details you need :slight_smile:

1 Like