mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: protect against missing overrides section (#35577)
* Protect against missing overrides section We are using grafonnet-lib to generate dashboards. These dashboards do not contain any `override` keys in `fieldConfig` by default and that is causing this DashboardMigrator script to blow up when trying to import the dashboards, see [1]. In Grafana v7, an empty overrides is automatically added but using grafonnet-lib, it isn't possible to set an empty overrides attribute e.g. [2] requires matcher/properties to be set. Setting to null ends up giving me [3], which causes the panel to not be displayed. [1] ``` initDashboard.ts:137 TypeError: t.overrides is not iterable at v.w (DashboardMigrator.ts:960) at v.updateSchema (DashboardMigrator.ts:672) at D.updateSchema (DashboardModel.ts:993) at new D (DashboardModel.ts:156) at initDashboard.ts:134 ``` [2] https://github.com/grafana/grafonnet-lib/blob/master/grafonnet/stat_panel.libsonnet#L150-L164 [3] ``` "fieldConfig": { "defaults": { "links": [ ], "mappings": [ ], "thresholds": { "mode": "absolute", "steps": [ { "color": "red", "value": 0 }, { "color": "orange", "value": 1 }, { "color": "green", "value": 3 } ] }, "unit": "none" }, "overrides": [ { } ] }, ``` * Update public/app/features/dashboard/state/DashboardMigrator.ts Co-authored-by: Marcus Andersson <systemvetaren@gmail.com>
This commit is contained in:
parent
16cc91bf33
commit
eb7dd8e377
@ -957,6 +957,8 @@ function upgradeValueMappingsForPanel(panel: PanelModel) {
|
|||||||
|
|
||||||
fieldConfig.defaults.mappings = upgradeValueMappings(fieldConfig.defaults.mappings, fieldConfig.defaults.thresholds);
|
fieldConfig.defaults.mappings = upgradeValueMappings(fieldConfig.defaults.mappings, fieldConfig.defaults.thresholds);
|
||||||
|
|
||||||
|
// Protect against no overrides
|
||||||
|
if (Array.isArray(fieldConfig.overrides)) {
|
||||||
for (const override of fieldConfig.overrides) {
|
for (const override of fieldConfig.overrides) {
|
||||||
for (const prop of override.properties) {
|
for (const prop of override.properties) {
|
||||||
if (prop.id === 'mappings') {
|
if (prop.id === 'mappings') {
|
||||||
@ -964,6 +966,7 @@ function upgradeValueMappingsForPanel(panel: PanelModel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user