CloudWatch: Fix alerting for queries with Id (using GetMetricData) (#17899)

This commit addresses half of #13749 by making sure GetMetricData 
works for alerting. Math Expressions (compound metrics) will still not 
work for alerting, this would require a bigger refactoring of Grafana's 
alerting service. However, with this commit at least alerting for basic 
metrics with non empty query Id will work.

Fixes half of #13749
This commit is contained in:
Alexander Berger
2019-08-05 17:28:09 +02:00
committed by Marcus Efraimsson
parent c82a26e2b2
commit 4e1e220962
6 changed files with 9 additions and 8 deletions

View File

@@ -31,7 +31,6 @@ func TestCloudWatchGetMetricData(t *testing.T) {
Period: 300,
Id: "id1",
Expression: "",
ReturnData: true,
},
"id2": {
RefId: "B",
@@ -39,7 +38,6 @@ func TestCloudWatchGetMetricData(t *testing.T) {
Statistics: []*string{aws.String("Average")},
Id: "id2",
Expression: "id1 * 2",
ReturnData: true,
},
}
@@ -58,11 +56,9 @@ func TestCloudWatchGetMetricData(t *testing.T) {
So(*v.MetricStat.Period, ShouldEqual, 300)
So(*v.MetricStat.Stat, ShouldEqual, "Average")
So(*v.Id, ShouldEqual, "id1")
So(*v.ReturnData, ShouldEqual, true)
} else {
So(*v.Id, ShouldEqual, "id2")
So(*v.Expression, ShouldEqual, "id1 * 2")
So(*v.ReturnData, ShouldEqual, true)
}
}
})

View File

@@ -146,7 +146,14 @@ func parseQuery(model *simplejson.Json) (*CloudWatchQuery, error) {
alias := model.Get("alias").MustString()
returnData := model.Get("returnData").MustBool(false)
returnData := !model.Get("hide").MustBool(false)
queryType := model.Get("type").MustString()
if queryType == "" {
// If no type is provided we assume we are called by alerting service, which requires to return data!
// Note, this is sort of a hack, but the official Grafana interfaces do not carry the information
// who (which service) called the TsdbQueryEndpoint.Query(...) function.
returnData = true
}
highResolution := model.Get("highResolution").MustBool(false)
return &CloudWatchQuery{