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")
}
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{