Commit fa567de9 by Torkel Ödegaard Committed by GitHub

Cloudwatch: Fix issue with field calculation transform not working properly with…

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

* 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>
parent 651ab567
...@@ -43,7 +43,7 @@ require ( ...@@ -43,7 +43,7 @@ require (
github.com/google/uuid v1.1.2 github.com/google/uuid v1.1.2
github.com/gosimple/slug v1.4.2 github.com/gosimple/slug v1.4.2
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 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/grafana/loki v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.2.1 github.com/grpc-ecosystem/go-grpc-middleware v1.2.1
github.com/hashicorp/go-hclog v0.12.2 github.com/hashicorp/go-hclog v0.12.2
......
...@@ -606,8 +606,8 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ= ...@@ -606,8 +606,8 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ=
github.com/gosimple/slug v1.4.2/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0= 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 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-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.79.0 h1:7NVEIMlF8G9H7XUdLX9jH/g01FllE1GEBcFvzXZD+Kw=
github.com/grafana/grafana-plugin-sdk-go v0.78.0/go.mod h1:NvxLzGkVhnoBKwzkst6CFfpMFKwAdIUZ1q8ssuLeF60= 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 h1:vHuFgfhW1iRMCm7/LgnZi02Ifvqj389vWhyfNJlHQTQ=
github.com/grafana/loki v1.6.0/go.mod h1:X+GvtCzAf2ok/xRLLvGB8kuWP1R+75nXnvjCEnenP0s= 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= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
......
...@@ -105,12 +105,11 @@ func parseMetricResults(results map[string]*cloudwatch.MetricDataResult, labels ...@@ -105,12 +105,11 @@ func parseMetricResults(results map[string]*cloudwatch.MetricDataResult, labels
} }
} }
timeField := data.NewField("timestamp", nil, []*time.Time{}) timeField := data.NewField(data.TimeSeriesTimeFieldName, nil, []*time.Time{})
timeField.SetConfig(&data.FieldConfig{DisplayName: "Time"}) valueField := data.NewField(data.TimeSeriesValueFieldName, tags, []*float64{})
frameName := formatAlias(query, query.Stats, tags, label) frameName := formatAlias(query, query.Stats, tags, label)
valueField := data.NewField("value", tags, []*float64{}) valueField.SetConfig(&data.FieldConfig{DisplayNameFromDS: frameName})
valueField.SetConfig(&data.FieldConfig{DisplayName: frameName})
emptyFrame := data.Frame{ emptyFrame := data.Frame{
Name: frameName, Name: frameName,
...@@ -160,12 +159,11 @@ func parseMetricResults(results map[string]*cloudwatch.MetricDataResult, labels ...@@ -160,12 +159,11 @@ func parseMetricResults(results map[string]*cloudwatch.MetricDataResult, labels
points = append(points, val) points = append(points, val)
} }
timeField := data.NewField("timestamp", nil, timestamps) timeField := data.NewField(data.TimeSeriesTimeFieldName, nil, timestamps)
timeField.SetConfig(&data.FieldConfig{DisplayName: "Time"}) valueField := data.NewField(data.TimeSeriesValueFieldName, tags, points)
frameName := formatAlias(query, query.Stats, tags, label) frameName := formatAlias(query, query.Stats, tags, label)
valueField := data.NewField("value", tags, points) valueField.SetConfig(&data.FieldConfig{DisplayNameFromDS: frameName})
valueField.SetConfig(&data.FieldConfig{DisplayName: frameName})
frame := data.Frame{ frame := data.Frame{
Name: frameName, Name: frameName,
......
...@@ -310,10 +310,13 @@ func TestCloudWatchResponseParser(t *testing.T) { ...@@ -310,10 +310,13 @@ func TestCloudWatchResponseParser(t *testing.T) {
frame := frames[0] frame := frames[0]
assert.False(t, partialData) assert.False(t, partialData)
assert.Equal(t, "AWS/ApplicationELB_TargetResponseTime_Average", frame.Name) 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, "lb", frame.Fields[1].Labels["LoadBalancer"])
assert.Equal(t, 10.0, *frame.Fields[1].At(0).(*float64)) assert.Equal(t, 10.0, *frame.Fields[1].At(0).(*float64))
assert.Equal(t, 20.0, *frame.Fields[1].At(1).(*float64)) assert.Equal(t, 20.0, *frame.Fields[1].At(1).(*float64))
assert.Nil(t, frame.Fields[1].At(2)) assert.Nil(t, frame.Fields[1].At(2))
assert.Equal(t, 30.0, *frame.Fields[1].At(3).(*float64)) 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)
}) })
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment