Fix: Correctly migrate mixed data source targets (#54152) (#54198)

* Failing test case

* Fix mixed datasource targets migration

(cherry picked from commit f9a49aa3ed)

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
Grot (@grafanabot)andDominik Prokop authored and GitHub committed 2022-08-25 05:57:19 -07:00
1 parent 5466d4dbf3
commit 38cb07a076
2 files changed
+15 -2

No files matched your search

@@ -1814,6 +1814,12 @@ describe('DashboardModel', () => {
{
datasource: 'prom',
},
{
datasource: 'default',
},
{
datasource: null,
},
],
},
{
@@ -1848,6 +1854,8 @@ describe('DashboardModel', () => {
it('should update target datasource props to refs', () => {
expect(model.panels[2].targets[0].datasource).toEqual({ type: 'prometheus', uid: 'prom-uid' });
expect(model.panels[2].targets[1].datasource).toEqual({ type: 'prometheus', uid: 'prom2-uid' });
expect(model.panels[2].targets[2].datasource).toEqual({ type: 'prometheus', uid: 'prom2-uid' });
});
it('should update datasources in panels collapsed rows', () => {
@@ -41,6 +41,7 @@ import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
import { isConstant, isMulti } from 'app/features/variables/guard';
import { alignCurrentWithMulti } from 'app/features/variables/shared/multiOptions';
import { CloudWatchMetricsQuery, LegacyAnnotationQuery } from 'app/plugins/datasource/cloudwatch/types';
import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource';
import { plugin as gaugePanelPlugin } from 'app/plugins/panel/gauge/module';
import { plugin as statPanelPlugin } from 'app/plugins/panel/stat/module';
@@ -762,10 +763,14 @@ export class DashboardMigrator {
for (const target of panel.targets) {
if (target.datasource == null || target.datasource.uid == null) {
target.datasource = { ...panel.datasource };
if (panel.datasource?.uid !== MIXED_DATASOURCE_NAME) {
target.datasource = { ...panel.datasource };
} else {
target.datasource = migrateDatasourceNameToRef(target.datasource, { returnDefaultAsNull: false });
}
}
if (panelDataSourceWasDefault && target.datasource.uid !== '__expr__') {
if (panelDataSourceWasDefault && target.datasource?.uid !== '__expr__') {
// We can have situations when default ds changed and the panel level data source is different from the queries
// In this case we use the query level data source as source for truth
panel.datasource = target.datasource as DataSourceRef;