Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard: Replace datasource name with a reference object #33817

Merged
merged 100 commits into from
Oct 29, 2021

Conversation

ryantxu
Copy link
Member

@ryantxu ryantxu commented May 7, 2021

Fixes #1664, See also #32853

We currently store the datasource name in the dashboard, this has a few bad effects:

  1. not enough information in a dashboard to know if the queries are valid without a database lookup. See Make it possible to validate dashboard JSON with datasource queries #33761
  2. renaming a datasource will break all references

This replaces our existing string object with a datasourceRef:

export interface DatasourceRef {
  type?: string;
  uid?: string;
}

Although we could simply replace our existing name with the uid, using an object with type makes defining dashboards programatically MUCH more natural. Specifically, this allows us to day "I need a loki datasource, but I don't care which one". Also the type parameter will allow validating the query syntax without without needing to lookup uid > datasource.pluginType

TODO:

  • migrate variable queries
  • dashboard queries...
  • Unified alerting seems to be working and tests pass (after a code update by torkel, se changes in expr/graph and expr/nodes)
  • Updated legacy alerting alert rule extractor
  • What should dashboard exporter do?
  • Annotation queries

Copy link
Member

@torkelo torkelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very promising, awesome job

@ryantxu
Copy link
Member Author

ryantxu commented May 11, 2021

@malcolmholmes
Copy link
Contributor

I assume that this introduces a new schema version, and that older schema versions will be migrated to this version. In which case, at least in this sense, this isn't a breaking change. Existing dashboard json will continue to work. It will only break if you update the schema version without updating your dashboard references.

Are these assumptions correct?

@@ -62,7 +65,7 @@ export class DashboardMigrator {
let i, j, k, n;
const oldVersion = this.dashboard.schemaVersion;
const panelUpgrades: PanelSchemeUpgradeHandler[] = [];
this.dashboard.schemaVersion = 32;
this.dashboard.schemaVersion = 33;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malcolmholmes this changes the schemaVersion

@dginhoux
Copy link

Very great idea, thank you very mich for this improvment

@marefr marefr removed the breaking change Relevant for changelog generation label Nov 25, 2021
@marefr
Copy link
Contributor

marefr commented Nov 25, 2021

I assume that this introduces a new schema version, and that older schema versions will be migrated to this version. In which case, at least in this sense, this isn't a breaking change. Existing dashboard json will continue to work. It will only break if you update the schema version without updating your dashboard references.

Are these assumptions correct?

I removed the breaking change label for now.

@marefr marefr changed the title Dashboard: replace datasource name with a reference object Dashboard: Replace datasource name with a reference object Nov 25, 2021
colega added a commit to colega/grafana-tools-sdk that referenced this pull request Mar 4, 2022
See: grafana/grafana#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.

Signed-off-by: Oleg Zaytsev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Datasources: Renaming a data source does not update dashboard panels