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

* Failing test case

* Fix mixed datasource targets migration
This commit is contained in:
Dominik Prokop 2022-08-25 00:07:10 -07:00 committed by GitHub
parent 6128cb60b4
commit f9a49aa3ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -1813,6 +1813,12 @@ describe('DashboardModel', () => {
{
datasource: 'prom',
},
{
datasource: 'default',
},
{
datasource: null,
},
],
},
{
@ -1847,6 +1853,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', () => {

View File

@ -43,6 +43,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';
@ -771,10 +772,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;