sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Support object-typed datasource references

Open colega opened this issue 2 years ago • 2 comments

See: https://github.com/grafana/grafana/pull/33817

Since Grafana v8.4.3 datasource references are not longer a string with the datasource name, but an object with the type and UID instead.

This means that dashboards saved with Grafana v8.4.3 or higher are not longer parseable by this SDK.

I replaced the *string datasource by a DatasourceRef struct, which has custom unmarshaling: it tries to unmarshal the new object, and if it fails, it will try to unmarshal data as string and put it into LegacyName instead.

colega avatar Mar 04 '22 08:03 colega

I had a similar request pending. https://github.com/grafana-tools/sdk/pull/195/files

That fixed the issue for me. All you need is the Uid to be persisted when importing/exporting dashboards. That being said, I'm using the Raw calls rather the model maybe that's the big difference?

More context here: https://github.com/netsage-project/gdg/issues/71 (GDG is the tool i wrote to manage dashboards that utilizes this SDK)

safaci2000 avatar Mar 15 '22 20:03 safaci2000

Hi! Note that https://github.com/grafana-tools/sdk/pull/195 just adds more fields to the datasource object, so it won't prevent it from being unmarshaled (by this tool, IDK about grafana, which may will fail if there's no UID)

This PR doesn't change the dastasource object definition, instead it changes the datasource field in other object, which was previously a string and now it's a an object.

colega avatar Mar 16 '22 07:03 colega