From 668f397a8e58e5291dc9f547268d84e7903f78ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Mon, 16 Aug 2021 09:20:58 +0200 Subject: [PATCH] Prometheus/Alerting: handle datasource.timeRange is nil case (#37888) --- pkg/tsdb/prometheus/prometheus.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/tsdb/prometheus/prometheus.go b/pkg/tsdb/prometheus/prometheus.go index 14ede6f57d6..bebdfc9e432 100644 --- a/pkg/tsdb/prometheus/prometheus.go +++ b/pkg/tsdb/prometheus/prometheus.go @@ -85,9 +85,18 @@ func newInstanceSettings() datasource.InstanceFactoryFunc { return nil, errors.New("no http method provided") } - timeInterval, ok := jsonData["timeInterval"].(string) - if !ok { - return nil, errors.New("invalid time-interval provided") + // timeInterval can be a string or can be missing. + // if it is missing, we set it to empty-string + + timeInterval := "" + + timeIntervalJson := jsonData["timeInterval"] + if timeIntervalJson != nil { + // if it is not nil, it must be a string + timeInterval, ok = timeIntervalJson.(string) + if !ok { + return nil, errors.New("invalid time-interval provided") + } } mdl := DatasourceInfo{