mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
Fix: Correctly migrate mixed data source targets (#54152)
* Failing test case * Fix mixed datasource targets migration
This commit is contained in:
parent
6128cb60b4
commit
f9a49aa3ed
@ -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', () => {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user