Cloudwatch: Fix issue with field calculation transform not working properly with Cloudwatch data (#28761) (#28775)

* Cloudwatch: Fix issue with reducer transform not working properly with Cloudwatch data

* Updated go sdk and updated code

* CloudWatch: Improve test

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
(cherry picked from commit fa567de9b8)

Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
Grot (@grafanabot)
2020-11-03 12:07:18 +01:00
committed by GitHub
co-authored by Torkel Ödegaard
parent 7f9990c889
commit d55ca82f0b
4 changed files with 12 additions and 11 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ require (
github.com/google/go-cmp v0.5.0
github.com/gosimple/slug v1.4.2
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4
github.com/grafana/grafana-plugin-sdk-go v0.78.0
github.com/grafana/grafana-plugin-sdk-go v0.79.0
github.com/grafana/loki v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.2.1
github.com/hashicorp/go-hclog v0.12.2
+2 -2
View File
@@ -580,8 +580,8 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ=
github.com/gosimple/slug v1.4.2/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 h1:SPdxCL9BChFTlyi0Khv64vdCW4TMna8+sxL7+Chx+Ag=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4/go.mod h1:nc0XxBzjeGcrMltCDw269LoWF9S8ibhgxolCdA1R8To=
github.com/grafana/grafana-plugin-sdk-go v0.78.0 h1:w43X+b36goTvis4TAW5PzhkGuSJokgm3KKYPOYiENAc=
github.com/grafana/grafana-plugin-sdk-go v0.78.0/go.mod h1:NvxLzGkVhnoBKwzkst6CFfpMFKwAdIUZ1q8ssuLeF60=
github.com/grafana/grafana-plugin-sdk-go v0.79.0 h1:7NVEIMlF8G9H7XUdLX9jH/g01FllE1GEBcFvzXZD+Kw=
github.com/grafana/grafana-plugin-sdk-go v0.79.0/go.mod h1:NvxLzGkVhnoBKwzkst6CFfpMFKwAdIUZ1q8ssuLeF60=
github.com/grafana/loki v1.6.0 h1:vHuFgfhW1iRMCm7/LgnZi02Ifvqj389vWhyfNJlHQTQ=
github.com/grafana/loki v1.6.0/go.mod h1:X+GvtCzAf2ok/xRLLvGB8kuWP1R+75nXnvjCEnenP0s=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
+6 -8
View File
@@ -105,12 +105,11 @@ func parseMetricResults(results map[string]*cloudwatch.MetricDataResult, labels
}
}
timeField := data.NewField("timestamp", nil, []*time.Time{})
timeField.SetConfig(&data.FieldConfig{DisplayName: "Time"})
timeField := data.NewField(data.TimeSeriesTimeFieldName, nil, []*time.Time{})
valueField := data.NewField(data.TimeSeriesValueFieldName, tags, []*float64{})
frameName := formatAlias(query, query.Stats, tags, label)
valueField := data.NewField("value", tags, []*float64{})
valueField.SetConfig(&data.FieldConfig{DisplayName: frameName})
valueField.SetConfig(&data.FieldConfig{DisplayNameFromDS: frameName})
emptyFrame := data.Frame{
Name: frameName,
@@ -160,12 +159,11 @@ func parseMetricResults(results map[string]*cloudwatch.MetricDataResult, labels
points = append(points, val)
}
timeField := data.NewField("timestamp", nil, timestamps)
timeField.SetConfig(&data.FieldConfig{DisplayName: "Time"})
timeField := data.NewField(data.TimeSeriesTimeFieldName, nil, timestamps)
valueField := data.NewField(data.TimeSeriesValueFieldName, tags, points)
frameName := formatAlias(query, query.Stats, tags, label)
valueField := data.NewField("value", tags, points)
valueField.SetConfig(&data.FieldConfig{DisplayName: frameName})
valueField.SetConfig(&data.FieldConfig{DisplayNameFromDS: frameName})
frame := data.Frame{
Name: frameName,
@@ -310,10 +310,13 @@ func TestCloudWatchResponseParser(t *testing.T) {
frame := frames[0]
assert.False(t, partialData)
assert.Equal(t, "AWS/ApplicationELB_TargetResponseTime_Average", frame.Name)
assert.Equal(t, "Time", frame.Fields[0].Name)
assert.Equal(t, "lb", frame.Fields[1].Labels["LoadBalancer"])
assert.Equal(t, 10.0, *frame.Fields[1].At(0).(*float64))
assert.Equal(t, 20.0, *frame.Fields[1].At(1).(*float64))
assert.Nil(t, frame.Fields[1].At(2))
assert.Equal(t, 30.0, *frame.Fields[1].At(3).(*float64))
assert.Equal(t, "Value", frame.Fields[1].Name)
assert.Equal(t, "", frame.Fields[1].Config.DisplayName)
})
}