grafanalib
grafanalib copied to clipboard
Grafana replaced datasource name with a reference object
What you expected to happen?
Load dashboards to Grafana 8.3.0+ version
What happened?
Failed to upload dashboard to Grafana when upgrading to the latest version
Error log message: logger=context traceID=00000000000000000000000000000000 userId=0 orgId=1 uname= t=2022-05-20T09:04:58.97+0000 lvl=eror msg="Failed to save dashboard" error="data source not found" remote_addr=10.0.5.148 traceID=00000000000000000000000000000000
Possibly due to this PR: https://github.com/grafana/grafana/pull/33817
How to reproduce it?
Load dashboards to Grafana 8.3.0+ version
Possible workaround
Instead of providing the string name of the data source, I've tried using the dictionary value:
For Target: datasource = { "type": "cloudwatch", "uid": "the data source uid" }
For Graph: dataSource = { "type": "cloudwatch", "uid": "the data source uid" }
And so far it worked for me... The only challenge is getting the uid's of the datasource from Grafana...
Also, looks like none values are not valid anymore for Targets, so if there is no data, the default should be: dataSource = { "type": "datasource", "uid": "grafana" }
That's annoying that they have changed that, I wonder how Grafana is handling that with their example dashboards ? https://grafana.com/grafana/dashboards/
Would you be willing to put together a PR to at least make a dashboard generated by grafanalib load rather than fail, even if the datasource was not quite correct?
Yeah, we are having to do this in all of our dashboards to be able to upgrade to later versions of Grafana. The good news is that it works on past versions of Grafana as well. I'm not sure why Grafana maintainers released this change in a non-major release because it is clearly a breaking change for people who maintain dashboards as code.
data_source=dict(type='prometheus', uid='${DataSource}')
Target(
datasource=data_source,
expr=blahblahblah,
),
In this example, we are populating UID from the drop-down variable for DataSource
in the dashboard.