From 87ae3e06447916a5bd4dc600375bf31d204f3728 Mon Sep 17 00:00:00 2001 From: Alexander Emelin Date: Fri, 29 Apr 2022 18:49:38 +0300 Subject: [PATCH] Search: handle a couple of corner cases when parsing dashboard data (#48521) --- pkg/services/searchV2/extract/dashboard.go | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pkg/services/searchV2/extract/dashboard.go b/pkg/services/searchV2/extract/dashboard.go index 5ce13f38c2c..6806fc232ae 100644 --- a/pkg/services/searchV2/extract/dashboard.go +++ b/pkg/services/searchV2/extract/dashboard.go @@ -2,6 +2,7 @@ package extract import ( "io" + "strconv" jsoniter "github.com/json-iterator/go" ) @@ -38,8 +39,17 @@ func ReadDashboard(stream io.Reader, lookup DatasourceLookup) (*DashboardInfo, e dash.Description = iter.ReadString() case "schemaVersion": - dash.SchemaVersion = iter.ReadInt64() - + switch iter.WhatIsNext() { + case jsoniter.NumberValue: + dash.SchemaVersion = iter.ReadInt64() + case jsoniter.StringValue: + val := iter.ReadString() + if v, err := strconv.ParseInt(val, 10, 64); err == nil { + dash.SchemaVersion = v + } + default: + iter.Skip() + } case "timezone": dash.TimeZone = iter.ReadString() @@ -176,8 +186,17 @@ func readPanelInfo(iter *jsoniter.Iterator, lookup DatasourceLookup) PanelInfo { targets.addDatasource(iter) case "targets": - for iter.ReadArray() { - targets.addTarget(iter) + switch iter.WhatIsNext() { + case jsoniter.ArrayValue: + for iter.ReadArray() { + targets.addTarget(iter) + } + case jsoniter.ObjectValue: + for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { + targets.addTarget(iter) + } + default: + iter.Skip() } case "transformations":