mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch: Fix segfault when migrating legacy queries (#93543)
This commit is contained in:
parent
216b63549d
commit
2ad558d046
@ -385,7 +385,11 @@ func (q *CloudWatchQuery) validateAndSetDefaults(refId string, metricsDataQuery
|
||||
func getStatistic(query metricsDataQuery) string {
|
||||
// If there's not a statistic property in the json, we know it's the legacy format and then it has to be migrated
|
||||
if query.Statistic == nil {
|
||||
return query.Statistics[0]
|
||||
if len(query.Statistics) > 0 {
|
||||
return query.Statistics[0]
|
||||
}
|
||||
// if there isn't a statistic property in the legacy format fall back to Average
|
||||
return "Average"
|
||||
}
|
||||
return *query.Statistic
|
||||
}
|
||||
|
@ -296,6 +296,37 @@ func TestRequestParser(t *testing.T) {
|
||||
assert.Equal(t, "Average", migratedQuery.Statistic)
|
||||
})
|
||||
|
||||
t.Run("legacy statistics field is migrated: if no stat, uses Average", func(t *testing.T) {
|
||||
oldQuery := []backend.DataQuery{
|
||||
{
|
||||
MaxDataPoints: 0,
|
||||
QueryType: "timeSeriesQuery",
|
||||
Interval: 0,
|
||||
RefID: "A",
|
||||
JSON: json.RawMessage(`{
|
||||
"region":"us-east-1",
|
||||
"namespace":"ec2",
|
||||
"metricName":"CPUUtilization",
|
||||
"dimensions":{
|
||||
"InstanceId": ["test"]
|
||||
},
|
||||
"statistics":[],
|
||||
"period":"600",
|
||||
"hide":false
|
||||
}`),
|
||||
},
|
||||
}
|
||||
|
||||
migratedQueries, err := ParseMetricDataQueries(oldQuery, time.Now(), time.Now(), "us-east-2", logger, false)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, migratedQueries, 1)
|
||||
require.NotNil(t, migratedQueries[0])
|
||||
|
||||
migratedQuery := migratedQueries[0]
|
||||
assert.Equal(t, "A", migratedQuery.RefId)
|
||||
assert.Equal(t, "Average", migratedQuery.Statistic)
|
||||
})
|
||||
|
||||
t.Run("New dimensions structure", func(t *testing.T) {
|
||||
query := []backend.DataQuery{
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user