From 47cd8288cde6b8f936da00aef9aae43b3052bdd1 Mon Sep 17 00:00:00 2001 From: "Arati R." <33031346+suntala@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:42:15 +0200 Subject: [PATCH] SearchV2: Fix reading library panels (#92961) * Fix reading of library panel field * Add test to check reading of library panel field --- .../store/kind/dashboard/dashboard.go | 8 +- .../store/kind/dashboard/dashboard_test.go | 1 + .../panel-with-library-panel-field-info.json | 30 +++++++ .../panel-with-library-panel-field.json | 83 +++++++++++++++++++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field-info.json create mode 100644 pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field.json diff --git a/pkg/services/store/kind/dashboard/dashboard.go b/pkg/services/store/kind/dashboard/dashboard.go index b325acd8c57..6c50b68bf42 100644 --- a/pkg/services/store/kind/dashboard/dashboard.go +++ b/pkg/services/store/kind/dashboard/dashboard.go @@ -396,9 +396,13 @@ func readpanelInfo(iter *jsoniter.Iterator, lookup DatasourceLookup) panelInfo { panel.PluginVersion = iter.ReadString() // since 7x (the saved version for the plugin model) case "libraryPanel": - var v map[string]string + var v map[string]interface{} iter.ReadVal(&v) - panel.LibraryPanel = v["uid"] + if uid, ok := v["uid"]; ok { + if u, isString := uid.(string); isString { + panel.LibraryPanel = u + } + } case "datasource": targets.addDatasource(iter) diff --git a/pkg/services/store/kind/dashboard/dashboard_test.go b/pkg/services/store/kind/dashboard/dashboard_test.go index 94287ad69e0..5be34abbbca 100644 --- a/pkg/services/store/kind/dashboard/dashboard_test.go +++ b/pkg/services/store/kind/dashboard/dashboard_test.go @@ -70,6 +70,7 @@ func TestReadDashboard(t *testing.T) { "mixed-datasource-with-variable", "special-datasource-types", "panels-without-datasources", + "panel-with-library-panel-field", } devdash := "../../../../../devenv/dev-dashboards/" diff --git a/pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field-info.json b/pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field-info.json new file mode 100644 index 00000000000..1ffaecb605b --- /dev/null +++ b/pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field-info.json @@ -0,0 +1,30 @@ +{ + "id": 345, + "title": "The libraryPanel field should get read properly despite the version being an integer", + "tags": null, + "datasource": [ + { + "uid": "default.uid", + "type": "default.type" + } + ], + "panels": [ + { + "id": 454, + "title": "Example title", + "type": "timeseries", + "libraryPanel": "dfkljg98345dkf", + "datasource": [ + { + "uid": "default.uid", + "type": "default.type" + } + ] + } + ], + "schemaVersion": 39, + "linkCount": 0, + "timeFrom": "now-6h", + "timeTo": "now", + "timezone": "" +} \ No newline at end of file diff --git a/pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field.json b/pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field.json new file mode 100644 index 00000000000..06e9195c90d --- /dev/null +++ b/pkg/services/store/kind/dashboard/testdata/panel-with-library-panel-field.json @@ -0,0 +1,83 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "The libraryPanel field should get read properly despite the version being an integer", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 345, + "links": [], + "panels": [ + { + "description": "", + "fieldConfig": { + "defaults": {}, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 15 + }, + "id": 454, + "libraryPanel": { + "name": "example name", + "uid": "dfkljg98345dkf", + "version": 2001 + }, + "options": { + "legend": { + "calcs": [], + "displayMode": "hidden", + "placement": "bottom" + }, + "tooltip": { + "mode": "single" + } + }, + "targets": [ + { + "datasource": { + "type": "graphite", + "uid": "000000001" + }, + "refId": "A" + } + ], + "title": "Example title", + "transparent": true, + "type": "timeseries" + } + ], + "preload": false, + "refresh": "", + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "The libraryPanel field should get read properly despite the version being an integer", + "uid": "sdjf03945834sdkf", + "version": 33, + "weekStart": "" +}