mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: Fixes Dashboard init failed error on dashboards with old singlestat panels in collapsed rows
This commit is contained in:
parent
9a5e10e6fb
commit
b3a2740d57
@ -40,6 +40,7 @@ import { getStandardFieldConfigs, getStandardOptionEditors } from '@grafana/ui';
|
|||||||
standardEditorsRegistry.setInit(getStandardOptionEditors);
|
standardEditorsRegistry.setInit(getStandardOptionEditors);
|
||||||
standardFieldConfigEditorRegistry.setInit(getStandardFieldConfigs);
|
standardFieldConfigEditorRegistry.setInit(getStandardFieldConfigs);
|
||||||
|
|
||||||
|
type PanelSchemeUpgradeHandler = (panel: PanelModel) => PanelModel;
|
||||||
export class DashboardMigrator {
|
export class DashboardMigrator {
|
||||||
dashboard: DashboardModel;
|
dashboard: DashboardModel;
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ export class DashboardMigrator {
|
|||||||
updateSchema(old: any) {
|
updateSchema(old: any) {
|
||||||
let i, j, k, n;
|
let i, j, k, n;
|
||||||
const oldVersion = this.dashboard.schemaVersion;
|
const oldVersion = this.dashboard.schemaVersion;
|
||||||
const panelUpgrades = [];
|
const panelUpgrades: PanelSchemeUpgradeHandler[] = [];
|
||||||
this.dashboard.schemaVersion = 30;
|
this.dashboard.schemaVersion = 30;
|
||||||
|
|
||||||
if (oldVersion === this.dashboard.schemaVersion) {
|
if (oldVersion === this.dashboard.schemaVersion) {
|
||||||
@ -71,8 +72,9 @@ export class DashboardMigrator {
|
|||||||
if (panel.type === 'graphite') {
|
if (panel.type === 'graphite') {
|
||||||
panel.type = 'graph';
|
panel.type = 'graph';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panel.type !== 'graph') {
|
if (panel.type !== 'graph') {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBoolean(panel.legend)) {
|
if (isBoolean(panel.legend)) {
|
||||||
@ -106,6 +108,8 @@ export class DashboardMigrator {
|
|||||||
panel.y_formats[1] = panel.y2_format;
|
panel.y_formats[1] = panel.y2_format;
|
||||||
delete panel.y2_format;
|
delete panel.y2_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +122,8 @@ export class DashboardMigrator {
|
|||||||
panel.id = maxId;
|
panel.id = maxId;
|
||||||
maxId += 1;
|
maxId += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,12 +132,16 @@ export class DashboardMigrator {
|
|||||||
// move aliasYAxis changes
|
// move aliasYAxis changes
|
||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
if (panel.type !== 'graph') {
|
if (panel.type !== 'graph') {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
each(panel.aliasYAxis, (value, key) => {
|
each(panel.aliasYAxis, (value, key) => {
|
||||||
panel.seriesOverrides = [{ alias: key, yaxis: value }];
|
panel.seriesOverrides = [{ alias: key, yaxis: value }];
|
||||||
});
|
});
|
||||||
|
|
||||||
delete panel.aliasYAxis;
|
delete panel.aliasYAxis;
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +185,8 @@ export class DashboardMigrator {
|
|||||||
target.refId = panel.getNextQueryLetter && panel.getNextQueryLetter();
|
target.refId = panel.getNextQueryLetter && panel.getNextQueryLetter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +230,8 @@ export class DashboardMigrator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +240,7 @@ export class DashboardMigrator {
|
|||||||
// move aliasYAxis changes
|
// move aliasYAxis changes
|
||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
if (panel.type !== 'singlestat' && panel.thresholds !== '') {
|
if (panel.type !== 'singlestat' && panel.thresholds !== '') {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panel.thresholds) {
|
if (panel.thresholds) {
|
||||||
@ -237,6 +251,8 @@ export class DashboardMigrator {
|
|||||||
panel.thresholds = k.join(',');
|
panel.thresholds = k.join(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +261,7 @@ export class DashboardMigrator {
|
|||||||
// move aliasYAxis changes
|
// move aliasYAxis changes
|
||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
if (panel.type !== 'table') {
|
if (panel.type !== 'table') {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
each(panel.styles, (style) => {
|
each(panel.styles, (style) => {
|
||||||
@ -255,6 +271,8 @@ export class DashboardMigrator {
|
|||||||
style.thresholds = k;
|
style.thresholds = k;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,10 +297,10 @@ export class DashboardMigrator {
|
|||||||
// update graph yaxes changes
|
// update graph yaxes changes
|
||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
if (panel.type !== 'graph') {
|
if (panel.type !== 'graph') {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
if (!panel.grid) {
|
if (!panel.grid) {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!panel.yaxes) {
|
if (!panel.yaxes) {
|
||||||
@ -321,6 +339,8 @@ export class DashboardMigrator {
|
|||||||
delete panel['y-axis'];
|
delete panel['y-axis'];
|
||||||
delete panel['x-axis'];
|
delete panel['x-axis'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,10 +348,10 @@ export class DashboardMigrator {
|
|||||||
// update graph yaxes changes
|
// update graph yaxes changes
|
||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
if (panel.type !== 'graph') {
|
if (panel.type !== 'graph') {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
if (!panel.grid) {
|
if (!panel.grid) {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!panel.thresholds) {
|
if (!panel.thresholds) {
|
||||||
@ -388,6 +408,8 @@ export class DashboardMigrator {
|
|||||||
delete panel.grid.threshold2;
|
delete panel.grid.threshold2;
|
||||||
delete panel.grid.threshold2Color;
|
delete panel.grid.threshold2Color;
|
||||||
delete panel.grid.thresholdLine;
|
delete panel.grid.thresholdLine;
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +435,10 @@ export class DashboardMigrator {
|
|||||||
}) - 1
|
}) - 1
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
delete panel.minSpan;
|
delete panel.minSpan;
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,6 +469,8 @@ export class DashboardMigrator {
|
|||||||
delete panel.options.suffix;
|
delete panel.options.suffix;
|
||||||
delete panel['options-gauge'];
|
delete panel['options-gauge'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,6 +480,8 @@ export class DashboardMigrator {
|
|||||||
if (panel.links && isArray(panel.links)) {
|
if (panel.links && isArray(panel.links)) {
|
||||||
panel.links = panel.links.map(upgradePanelLink);
|
panel.links = panel.links.map(upgradePanelLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,6 +509,8 @@ export class DashboardMigrator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,18 +533,22 @@ export class DashboardMigrator {
|
|||||||
panel.options.fieldOptions.defaults.links = panel.options.fieldOptions.defaults.links.map(updateLinks);
|
panel.options.fieldOptions.defaults.links = panel.options.fieldOptions.defaults.links.map(updateLinks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 22) {
|
if (oldVersion < 22) {
|
||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
if (panel.type !== 'table') {
|
if (panel.type !== 'table') {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
each(panel.styles, (style) => {
|
each(panel.styles, (style) => {
|
||||||
style.align = 'auto';
|
style.align = 'auto';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,13 +568,14 @@ export class DashboardMigrator {
|
|||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
const wasAngularTable = panel.type === 'table';
|
const wasAngularTable = panel.type === 'table';
|
||||||
if (wasAngularTable && !panel.styles) {
|
if (wasAngularTable && !panel.styles) {
|
||||||
return; // styles are missing so assumes default settings
|
return panel; // styles are missing so assumes default settings
|
||||||
}
|
}
|
||||||
const wasReactTable = panel.table === 'table2';
|
const wasReactTable = panel.table === 'table2';
|
||||||
if (!wasAngularTable || wasReactTable) {
|
if (!wasAngularTable || wasReactTable) {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
panel.type = wasAngularTable ? 'table-old' : 'table';
|
panel.type = wasAngularTable ? 'table-old' : 'table';
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,11 +587,12 @@ export class DashboardMigrator {
|
|||||||
panelUpgrades.push((panel: any) => {
|
panelUpgrades.push((panel: any) => {
|
||||||
const wasReactText = panel.type === 'text2';
|
const wasReactText = panel.type === 'text2';
|
||||||
if (!wasReactText) {
|
if (!wasReactText) {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
panel.type = 'text';
|
panel.type = 'text';
|
||||||
delete panel.options.angular;
|
delete panel.options.angular;
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,8 +614,10 @@ export class DashboardMigrator {
|
|||||||
if (oldVersion < 28) {
|
if (oldVersion < 28) {
|
||||||
panelUpgrades.push((panel: PanelModel) => {
|
panelUpgrades.push((panel: PanelModel) => {
|
||||||
if (panel.type === 'singlestat') {
|
if (panel.type === 'singlestat') {
|
||||||
migrateSinglestat(panel);
|
return migrateSinglestat(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const variable of this.dashboard.templating.list) {
|
for (const variable of this.dashboard.templating.list) {
|
||||||
@ -627,10 +666,10 @@ export class DashboardMigrator {
|
|||||||
|
|
||||||
for (j = 0; j < this.dashboard.panels.length; j++) {
|
for (j = 0; j < this.dashboard.panels.length; j++) {
|
||||||
for (k = 0; k < panelUpgrades.length; k++) {
|
for (k = 0; k < panelUpgrades.length; k++) {
|
||||||
panelUpgrades[k].call(this, this.dashboard.panels[j]);
|
this.dashboard.panels[j] = panelUpgrades[k].call(this, this.dashboard.panels[j]);
|
||||||
if (this.dashboard.panels[j].panels) {
|
if (this.dashboard.panels[j].panels) {
|
||||||
for (n = 0; n < this.dashboard.panels[j].panels.length; n++) {
|
for (n = 0; n < this.dashboard.panels[j].panels.length; n++) {
|
||||||
panelUpgrades[k].call(this, this.dashboard.panels[j].panels[n]);
|
this.dashboard.panels[j].panels[n] = panelUpgrades[k].call(this, this.dashboard.panels[j].panels[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -880,7 +919,14 @@ function migrateSinglestat(panel: PanelModel) {
|
|||||||
// If 'grafana-singlestat-panel' exists, move to that
|
// If 'grafana-singlestat-panel' exists, move to that
|
||||||
if (config.panels['grafana-singlestat-panel']) {
|
if (config.panels['grafana-singlestat-panel']) {
|
||||||
panel.type = 'grafana-singlestat-panel';
|
panel.type = 'grafana-singlestat-panel';
|
||||||
return;
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
let returnSaveModel = false;
|
||||||
|
|
||||||
|
if (!panel.changePlugin) {
|
||||||
|
returnSaveModel = true;
|
||||||
|
panel = new PanelModel(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// To make sure PanelModel.isAngularPlugin logic thinks the current panel is angular
|
// To make sure PanelModel.isAngularPlugin logic thinks the current panel is angular
|
||||||
@ -895,12 +941,18 @@ function migrateSinglestat(panel: PanelModel) {
|
|||||||
statPanelPlugin.meta = config.panels['stat'];
|
statPanelPlugin.meta = config.panels['stat'];
|
||||||
panel.changePlugin(statPanelPlugin);
|
panel.changePlugin(statPanelPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (returnSaveModel) {
|
||||||
|
return panel.getSaveModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgradeValueMappingsForPanel(panel: PanelModel) {
|
function upgradeValueMappingsForPanel(panel: PanelModel) {
|
||||||
const fieldConfig = panel.fieldConfig;
|
const fieldConfig = panel.fieldConfig;
|
||||||
if (!fieldConfig) {
|
if (!fieldConfig) {
|
||||||
return;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldConfig.defaults.mappings = upgradeValueMappings(fieldConfig.defaults.mappings, fieldConfig.defaults.thresholds);
|
fieldConfig.defaults.mappings = upgradeValueMappings(fieldConfig.defaults.mappings, fieldConfig.defaults.thresholds);
|
||||||
@ -912,6 +964,8 @@ function upgradeValueMappingsForPanel(panel: PanelModel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgradeValueMappings(oldMappings: any, thresholds?: ThresholdsConfig): ValueMapping[] | undefined {
|
function upgradeValueMappings(oldMappings: any, thresholds?: ThresholdsConfig): ValueMapping[] | undefined {
|
||||||
@ -982,4 +1036,6 @@ function migrateTooltipOptions(panel: PanelModel) {
|
|||||||
delete panel.options.tooltipOptions;
|
delete panel.options.tooltipOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return panel;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user