mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(mixed datasource): fixed issue when exporting dashboard using mixed data source, fixes #6032
This commit is contained in:
parent
46ab09ed60
commit
4a1693196c
@ -24,6 +24,10 @@ export class DashboardExporter {
|
|||||||
|
|
||||||
var templateizeDatasourceUsage = obj => {
|
var templateizeDatasourceUsage = obj => {
|
||||||
promises.push(this.datasourceSrv.get(obj.datasource).then(ds => {
|
promises.push(this.datasourceSrv.get(obj.datasource).then(ds => {
|
||||||
|
if (ds.meta.builtIn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var refName = 'DS_' + ds.name.replace(' ', '_').toUpperCase();
|
var refName = 'DS_' + ds.name.replace(' ', '_').toUpperCase();
|
||||||
datasources[refName] = {
|
datasources[refName] = {
|
||||||
name: refName,
|
name: refName,
|
||||||
@ -46,11 +50,19 @@ export class DashboardExporter {
|
|||||||
|
|
||||||
// check up panel data sources
|
// check up panel data sources
|
||||||
for (let row of dash.rows) {
|
for (let row of dash.rows) {
|
||||||
_.each(row.panels, (panel) => {
|
for (let panel of row.panels) {
|
||||||
if (panel.datasource !== undefined) {
|
if (panel.datasource !== undefined) {
|
||||||
templateizeDatasourceUsage(panel);
|
templateizeDatasourceUsage(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (panel.targets) {
|
||||||
|
for (let target of panel.targets) {
|
||||||
|
if (target.datasource !== undefined) {
|
||||||
|
templateizeDatasourceUsage(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var panelDef = config.panels[panel.type];
|
var panelDef = config.panels[panel.type];
|
||||||
if (panelDef) {
|
if (panelDef) {
|
||||||
requires['panel' + panelDef.id] = {
|
requires['panel' + panelDef.id] = {
|
||||||
@ -60,7 +72,7 @@ export class DashboardExporter {
|
|||||||
version: panelDef.info.version,
|
version: panelDef.info.version,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// templatize template vars
|
// templatize template vars
|
||||||
|
@ -42,21 +42,34 @@ describe('given dashboard with repeated panels', function() {
|
|||||||
repeat: 'test',
|
repeat: 'test',
|
||||||
panels: [
|
panels: [
|
||||||
{id: 2, repeat: 'apps', datasource: 'gfdb', type: 'graph'},
|
{id: 2, repeat: 'apps', datasource: 'gfdb', type: 'graph'},
|
||||||
{id: 2, repeat: null, repeatPanelId: 2},
|
{id: 3, repeat: null, repeatPanelId: 2},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
datasource: '-- Mixed --',
|
||||||
|
targets: [{datasource: 'other'}],
|
||||||
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
dash.rows.push({
|
dash.rows.push({
|
||||||
repeat: null,
|
repeat: null,
|
||||||
repeatRowId: 1,
|
repeatRowId: 1,
|
||||||
panels: [],
|
panels: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
var datasourceSrvStub = {
|
var datasourceSrvStub = {get: sinon.stub()};
|
||||||
get: sinon.stub().returns(Promise.resolve({
|
datasourceSrvStub.get.withArgs('gfdb').returns(Promise.resolve({
|
||||||
name: 'gfdb',
|
name: 'gfdb',
|
||||||
meta: {id: "testdb", info: {version: "1.2.1"}, name: "TestDB"}
|
meta: {id: "testdb", info: {version: "1.2.1"}, name: "TestDB"}
|
||||||
}))
|
}));
|
||||||
};
|
datasourceSrvStub.get.withArgs('other').returns(Promise.resolve({
|
||||||
|
name: 'other',
|
||||||
|
meta: {id: "other", info: {version: "1.2.1"}, name: "OtherDB"}
|
||||||
|
}));
|
||||||
|
datasourceSrvStub.get.withArgs('-- Mixed --').returns(Promise.resolve({
|
||||||
|
name: 'mixed',
|
||||||
|
meta: {id: "mixed", info: {version: "1.2.1"}, name: "Mixed", builtIn: true}
|
||||||
|
}));
|
||||||
|
|
||||||
config.panels['graph'] = {
|
config.panels['graph'] = {
|
||||||
id: "graph",
|
id: "graph",
|
||||||
@ -72,7 +85,7 @@ describe('given dashboard with repeated panels', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('exported dashboard should not contain repeated panels', function() {
|
it('exported dashboard should not contain repeated panels', function() {
|
||||||
expect(exported.rows[0].panels.length).to.be(1);
|
expect(exported.rows[0].panels.length).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('exported dashboard should not contain repeated rows', function() {
|
it('exported dashboard should not contain repeated rows', function() {
|
||||||
@ -109,6 +122,16 @@ describe('given dashboard with repeated panels', function() {
|
|||||||
expect(require.version).to.be("1.2.1");
|
expect(require.version).to.be("1.2.1");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not add built in datasources to required', function() {
|
||||||
|
var require = _.find(exported.__requires, {name: 'Mixed'});
|
||||||
|
expect(require).to.be(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add datasources used in mixed mode', function() {
|
||||||
|
var require = _.find(exported.__requires, {name: 'OtherDB'});
|
||||||
|
expect(require).to.not.be(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it('should add panel to required', function() {
|
it('should add panel to required', function() {
|
||||||
var require = _.find(exported.__requires, {name: 'Graph'});
|
var require = _.find(exported.__requires, {name: 'Graph'});
|
||||||
expect(require.name).to.be("Graph");
|
expect(require.name).to.be("Graph");
|
||||||
|
Loading…
Reference in New Issue
Block a user