Should provisioned dashboards have datasource uids?

Grafana version: grafana:8.4.3-armv7

I’ve deployed a docker-compose file that contains Grafana, Prometheus, and node exporter combo and a provisioned dashboard. I am working on an update and I’ve made changes to the docker-compose file to use the latest Grafana, Prometheus, and replaced the provisioned dashboard with a new one.

I’d like users to be able to docker-compose down from their existing installation, pull my new docker-compose, and dashboard and docker-compose up.

The new JSON has some datasource UIDs present like below

"panels": [
      {
        "collapsed": false,
        "gridPos": {
          "h": 1,
          "w": 24,
          "x": 0,
          "y": 0
        },
        "id": 4,
        "panels": [],
        "title": "System Information",
        "type": "row"
      },
      {
        "datasource": {
          "type": "prometheus",
          "uid": "P1809F7CD0C75ACF3"
        },
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "thresholds"
            },
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "green",
                  "value": null
                }
              ]
            }
          },
          "overrides": []
        },
        "gridPos": {
          "h": 4,
          "w": 7,
          "x": 0,
          "y": 1
        },
        "id": 8,
        "options": {
          "colorMode": "value",
          "graphMode": "none",
          "justifyMode": "auto",
          "orientation": "auto",
          "reduceOptions": {
            "calcs": [
              "lastNotNull"
            ],
            "fields": "",
            "values": false
          },
          "textMode": "auto"
        },
        "pluginVersion": "8.4.3",
        "targets": [
          {
            "datasource": {
              "type": "prometheus",
              "uid": "P1809F7CD0C75ACF3"
            },
            "exemplar": true,
            "expr": "count(count(node_cpu_seconds_total{job=\"node_exporter\"}) by (cpu))",
            "interval": "",
            "legendFormat": "",
            "refId": "A"
          }
        ],
        "title": "CPU Cores",
        "type": "stat"
      },

Upon testing, when I do docker-compose restart, all the latest applications are pulled and dashboard gets updated but it has no data in it and I’m not entirely sure why. The Prometheus datasource is present in the dashboard, but all the queries/datasources for each panel are empty.

I’m trying to nail down the issue and my initial suspicion was maybe these Prometheus datasource UIDs might be causing no data being shown. What do these UIDs do exactly and should my provisioned dashboard have them?

(Note: if i delete the Grafana docker volume and start fresh, everything works fine. I’m wondering if this is the way to go for users that want to pull the latest changes…)

I had a similar problem, that dashboards exported from new versions of Grafana would include the uid when referencing a datasource instead of just the name as before.

Solution that worked for me was to set a uid for the provisioned datasources, so they would always have the same uid.

How do/did you set the UID?

For anyone stumbling into this.

You must match the ‘uid’ from your Dashboard with your datasource.

For example:

---
apiversion: 2
datasources:
  - name: "My CSV datasource"
    type: marcusolsson-csv-datasource
    url: http://machine.example.com/restapi/
    access: "proxy"
    basicAuth: false
    isDefault: false
    editable: false
    version: 3
    # UID, do not leave undefined
    uid: "JOSE3g9KVz"
    jsonData:
      storage: http

Best way I found to solve this issue is to create a dashboard variable of the type “constant” with as value the name of the datasource. You can then change the uid value to $VariableName in the json representation of the dashboard.

Newer versions provide a dashboard export option that does not have this problem.