mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -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 => {
|
||||
promises.push(this.datasourceSrv.get(obj.datasource).then(ds => {
|
||||
if (ds.meta.builtIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
var refName = 'DS_' + ds.name.replace(' ', '_').toUpperCase();
|
||||
datasources[refName] = {
|
||||
name: refName,
|
||||
@ -46,11 +50,19 @@ export class DashboardExporter {
|
||||
|
||||
// check up panel data sources
|
||||
for (let row of dash.rows) {
|
||||
_.each(row.panels, (panel) => {
|
||||
for (let panel of row.panels) {
|
||||
if (panel.datasource !== undefined) {
|
||||
templateizeDatasourceUsage(panel);
|
||||
}
|
||||
|
||||
if (panel.targets) {
|
||||
for (let target of panel.targets) {
|
||||
if (target.datasource !== undefined) {
|
||||
templateizeDatasourceUsage(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var panelDef = config.panels[panel.type];
|
||||
if (panelDef) {
|
||||
requires['panel' + panelDef.id] = {
|
||||
@ -60,7 +72,7 @@ export class DashboardExporter {
|
||||
version: panelDef.info.version,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// templatize template vars
|
||||
|
@ -42,21 +42,34 @@ describe('given dashboard with repeated panels', function() {
|
||||
repeat: 'test',
|
||||
panels: [
|
||||
{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({
|
||||
repeat: null,
|
||||
repeatRowId: 1,
|
||||
panels: [],
|
||||
});
|
||||
|
||||
var datasourceSrvStub = {
|
||||
get: sinon.stub().returns(Promise.resolve({
|
||||
name: 'gfdb',
|
||||
meta: {id: "testdb", info: {version: "1.2.1"}, name: "TestDB"}
|
||||
}))
|
||||
};
|
||||
var datasourceSrvStub = {get: sinon.stub()};
|
||||
datasourceSrvStub.get.withArgs('gfdb').returns(Promise.resolve({
|
||||
name: 'gfdb',
|
||||
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'] = {
|
||||
id: "graph",
|
||||
@ -72,7 +85,7 @@ describe('given dashboard with 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() {
|
||||
@ -109,6 +122,16 @@ describe('given dashboard with repeated panels', function() {
|
||||
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() {
|
||||
var require = _.find(exported.__requires, {name: 'Graph'});
|
||||
expect(require.name).to.be("Graph");
|
||||
|
Loading…
Reference in New Issue
Block a user