Templating Init Failed


I am creating new Datasource and importing dashboard through API, all is working except one minor issue. After creating Datasource and importing Dasbords, when I click any newly imported Grafana dasboard , I get templating init failed error

To fix this issue, I have to click Datasources–>Click newly created Datasource–>Click Save&Test and then all start working. I do only Save&test. Is there anyway I can test through API before importing the dashboards or another suggestion to fix this issue please?

Thanks in advance.

What data source is this? If you check the Chrome console, can you see the underlying error?

Thanks @daniellee for the response. Sorry, I should have provided more information.

Datasource is Prometheus, Below is the error I receive on the GUI and chrome console.

  1. {message: “Datasource named XYZ was not found”}

But the Datasource exists, first time after creating Datasource and importing dashboard, it throws an error " “Templating Init failed, Datasource xyz was not found”

To fix this issue, I have to click Datasources–>Click newly created Datasource–>Click Save&Test and then all start working. I don’t need anything special just only “Save&test”.

It seems Datasource created through API exists but somehow it need to be kicked in through “save&test”, not sure to be honest.

@daniellee, I further investigated and I created Datasource through the below command

curl -X POST -d ‘{“name”:“XYZ”, “Access”:“proxy”, “type”:“prometheus”, “url”:“promtheus.xyz”}’ -u admin:admin -H “Content-Type: Content-Type: application/json” localhost:3000/api/datasources

It created datasource successfully but when I try to create dashboard, Query drop down doesnt show the XYZ datasource until I go to Datasource–>click XYZ–>Click “Save&Test” and come back then Query drop down shows XYZ in the drop down. Datasource is not available in grafana until I manually click “Save&Test” which is weird.

I thought something wrong with my dashboards json but It seems bug to me. Could you please try to reproduce at your end? I tested on 6.5/6.6/7.2

I cannot recreate this. Do you have multiple organizations and have multiple tabs open?

No, I dont have multiple organizations. I just did another test

  1. download latest grafana 6.7.2 on my laptop

  2. start grafana with default settings

  3. access grafana new url from new browser/new session, it forced me to change the default password

  4. open terminal and run the curl api command to create dummy datasource

  5. go back to browser session and verify new datasource created successfully

  6. click on dashbord and select query/visulazier and click on query datasource drop down and cant see newly created datasource, very weird

  7. go back to newly created datasource, click only save&test and then go back to dashboards, click query/visualizer and then I can see this new datasource in the dropdown

It is very weird indeed, cant find any reason why it is behaving like that. Is my curl api command missing something? I tried many ways but none of them working. I thought something wrong with my setup but I tried on brand new grafana instance on my laptop and I can recreate it.

Any way to debug or hint? I have automated everything through ansible install grafan, create datasource, create folder, get folder id and import dashboards under these folders, everything working perfectly fine, only this issue is not letting enjoy my success :slight_smile: , have to open grafana datasource page and click save&test on all the data sources which created through automation then all starts working.


workaround is to restart grafana that fixed the issue. It seems if we create Datasource from API, it appears in Datasource but cant be seen if you try to create new dasboard, solution is to restart the grafana.