Templating: Failed to upgrade legacy queries Datasource was not found

Hi,

After upgrading to version 10.2.2 ( from 9.4.x), I am getting error 'Templating: Failed to upgrade legacy queries Datasource was not found" when loading a dashboard. In this dashboard I have two datasources, the second one uses regex of the first one. I have tried deleting the dashboard and importing it again to assign a new UID. Also deleted the datasources (bcnc-ocpbt and bcnc-ocpbp) and created new ones.
Any advice ?

Datasources

{
    "id": 39,
    "uid": "c3fe0c74-bae5-40db-96e3-44aa06661008",
    "orgId": 1,
    "name": "bcnc-ocpbp",
    "type": "prometheus",
    "typeName": "Prometheus",
    "typeLogoUrl": "/public/app/plugins/datasource/prometheus/img/prometheus_logo.svg",
    "access": "proxy",
    "url": "XXXXXXXXXXXXXXX",
    "user": "",
    "database": "",
    "basicAuth": true,
    "isDefault": false,
    "jsonData": {
      "httpMethod": "POST",
      "oauthPassThru": false,
      "sigV4Auth": false,
      "tlsSkipVerify": true
    },
    "readOnly": false
  },
  {
    "id": 40,
    "uid": "f32d5b7b-3d96-420f-8ced-e5307da51ed5",
    "orgId": 1,
    "name": "bcnc-ocpbt",
    "type": "prometheus",
    "typeName": "Prometheus",
    "typeLogoUrl": "/public/app/plugins/datasource/prometheus/img/prometheus_logo.svg",
    "access": "proxy",
    "url": "XXXXXXXXXXXXXXX",
    "user": "",
    "database": "",
    "basicAuth": true,
    "isDefault": false,
    "jsonData": {
      "httpMethod": "POST",
      "oauthPassThru": false,
      "sigV4Auth": false,
      "tlsSkipVerify": true
    },
    "readOnly": false
  },
  {
    "id": 5,
    "uid": "P2BE2660C7C3A6879",
    "orgId": 1,
    "name": "ocpbp",
    "type": "prometheus",
    "typeName": "Prometheus",
    "typeLogoUrl": "/public/app/plugins/datasource/prometheus/img/prometheus_logo.svg",
    "access": "proxy",
    "url": "XXXXXXXXXXXXXXX",
    "user": "",
    "database": "",
    "basicAuth": false,
    "isDefault": false,
    "jsonData": {
      "esVersion": 0,
      "httpHeaderName1": "Authorization",
      "httpMethod": "POST",
      "nodeGraph": {},
      "search": {},
      "serviceMap": {},
      "timeInterval": "30s",
      "tlsSkipVerify": true,
      "tracesToLogs": {}
    },
    "readOnly": false
  },
  {
    "id": 32,
    "uid": "l2-BhJ94z",
    "orgId": 1,
    "name": "ocpbt",
    "type": "prometheus",
    "typeName": "Prometheus",
    "typeLogoUrl": "/public/app/plugins/datasource/prometheus/img/prometheus_logo.svg",
    "access": "proxy",
    "url": "XXXXXXXXXXXXXXX",
    "user": "",
    "database": "",
    "basicAuth": false,
    "isDefault": false,
    "jsonData": {
      "esVersion": 0,
      "httpHeaderName1": "Authorization",
      "httpMethod": "POST",
      "nodeGraph": {},
      "search": {},
      "serviceMap": {},
      "timeInterval": "30s",
      "tlsSkipVerify": true,
      "tracesToLogs": {}
    },
    "readOnly": false
  },

Templating in dashboard

  "templating": {
    "list": [
      {
        "current": {
          "selected": false,
          "text": "ocpbt",
          "value": "l2-BhJ94z"
        },
        "hide": 0,
        "includeAll": false,
        "label": "Cluster",
        "multi": false,
        "name": "OCP_DS",
        "options": [],
        "query": "prometheus",
        "queryValue": "",
        "refresh": 1,
        "regex": "/^(ocpbt|ocpbp|ocpct|ocpcp).*/",
        "skipUrlSync": false,
        "type": "datasource"
      },
      {
        "current": {
          "selected": false,
          "text": "No data sources found",
          "value": ""
        },
        "hide": 2,
        "includeAll": false,
        "label": "Datasource",
        "multi": false,
        "name": "DS_PROMETHEUS",
        "options": [],
        "query": "prometheus",
        "queryValue": "",
        "refresh": 1,
        "regex": "/^bcnc-${OCP_DS}/",
        "skipUrlSync": false,
        "type": "datasource"
      },

I have the same problem friend.

I have the same issue moving my 1 of my dashboards to a new grafana server. The dashboard that is failing is a complicated one with the Acache EChart plugin. My other dashboards work fine on the new server, but they do not use any plug-ins

How are you doing this move?

hi everyone, I have the same problem. I had grafana 7 and now i want to use 11.1. when i import dashboards either by uid or by json file i always get the same error even when changing the uid. how can resolve this problem ?

if your grafana backend sqlite?

i am not sure, how can i check ?

look at your grafana or default .ini file

there are much easier ways to upgrade

yes to your first question: it is sqlite3. and hoq can i import dashboards from the old grafana (the easier way)?

no need to import anything

do you have any new items created in the new version or it is a pristine install?

if it is a fresh install with no dashboard or alerts etc:

  1. stop the grafana service on both versions
  2. copy grafana.db from old version to new version
  3. start grafana service in new version

search for your old dashboard in new version.

Thank you so much for your answer, it is so helpful. but what if i want to import some of the dashboards but not all of them ? that is what i am trying to do, i want to import only few dashboards from the old grafana. and everytime i import json file or i put the uid or i paste the json file i get the error that says failed to upgrade the legacy query. can you help me resolve this problem ?

1 Like

have you created the datasources for these dashboards? if so, the datasource uid referenced need to change bcs new ds means new uid

yes i have created the datasource already, when i import the dashboard i change the uid but still get error

and here i changed the uid and the name than

thank you for your time! i appreciate everything. i resolved it :facepunch:

please provide resolution to help others?

of course!!! I just deleted the uid in every section of the json file