Prometheus/Alerting: handle datasource.timeRange is nil case (#37888)

This commit is contained in:
Gábor Farkas 2021-08-16 09:20:58 +02:00 committed by GitHub
parent 5ab8d6a3b9
commit 668f397a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,9 +85,18 @@ func newInstanceSettings() datasource.InstanceFactoryFunc {
return nil, errors.New("no http method provided") return nil, errors.New("no http method provided")
} }
timeInterval, ok := jsonData["timeInterval"].(string) // timeInterval can be a string or can be missing.
if !ok { // if it is missing, we set it to empty-string
return nil, errors.New("invalid time-interval provided")
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{ mdl := DatasourceInfo{