mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Expressions: Fixes dashboard schema migration issue that casued Expression datasource to be set on panel level (#50945)
* Expressions: Fixes dashboard schema migration issue that casued Expression datasource to be set on panel level * fixing logic * Updated
This commit is contained in:
parent
ccc587dc0f
commit
eb25d8df89
@ -345,6 +345,7 @@ describe('given dashboard with repeated panels', () => {
|
||||
expect(element.model).toEqual({
|
||||
id: 17,
|
||||
datasource: { type: 'other2', uid: '$ds' },
|
||||
targets: [{ refId: 'A', datasource: { type: 'other2', uid: '$ds' } }],
|
||||
type: 'graph',
|
||||
});
|
||||
});
|
||||
|
@ -1992,6 +1992,38 @@ describe('DashboardModel', () => {
|
||||
expect(model.panels[0].targets[0].datasource).toEqual({ type: 'prometheus', uid: 'prom2-uid' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('when migrating default (null) datasource with panel with expressions queries', () => {
|
||||
let model: DashboardModel;
|
||||
|
||||
beforeEach(() => {
|
||||
model = new DashboardModel({
|
||||
panels: [
|
||||
{
|
||||
id: 2,
|
||||
targets: [
|
||||
{
|
||||
refId: 'A',
|
||||
},
|
||||
{
|
||||
refId: 'B',
|
||||
datasource: '__expr__',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
schemaVersion: 30,
|
||||
});
|
||||
});
|
||||
|
||||
it('should update panel datasource props to default datasource', () => {
|
||||
expect(model.panels[0].datasource).toEqual({ type: 'prometheus', uid: 'prom2-uid' });
|
||||
});
|
||||
|
||||
it('should update target datasource props to default data source', () => {
|
||||
expect(model.panels[0].targets[0].datasource).toEqual({ type: 'prometheus', uid: 'prom2-uid' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createRow(options: any, panelDescriptions: any[]) {
|
||||
|
@ -761,15 +761,15 @@ export class DashboardMigrator {
|
||||
}
|
||||
|
||||
for (const target of panel.targets) {
|
||||
if (target.datasource && panelDataSourceWasDefault) {
|
||||
if (target.datasource == null || target.datasource.uid == null) {
|
||||
target.datasource = { ...panel.datasource };
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (target.datasource === null) {
|
||||
target.datasource = getDataSourceRef(defaultDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
return panel;
|
||||
|
Loading…
Reference in New Issue
Block a user