From 91a67ab0fba4035a4f22c4c8181056263ab515fd Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Wed, 8 Sep 2021 16:30:55 +0200 Subject: [PATCH] CloudWatch/Logs: Don't group dataframes for non time series queries for non live path (#38915) * Use the same grouping function in legacy code * Add error propagation * Fix tests * Fix tests --- pkg/tests/api/metrics/api_metrics_test.go | 3 --- pkg/tsdb/cloudwatch/log_actions.go | 32 +++-------------------- pkg/tsdb/cloudwatch/log_actions_test.go | 13 --------- 3 files changed, 4 insertions(+), 44 deletions(-) diff --git a/pkg/tests/api/metrics/api_metrics_test.go b/pkg/tests/api/metrics/api_metrics_test.go index 7344b293a0d..afe2b5a3a0f 100644 --- a/pkg/tests/api/metrics/api_metrics_test.go +++ b/pkg/tests/api/metrics/api_metrics_test.go @@ -129,9 +129,6 @@ func TestQueryCloudWatchLogs(t *testing.T) { Fields: []*data.Field{ data.NewField("logGroupName", nil, []*string{}), }, - Meta: &data.FrameMeta{ - PreferredVisualization: "logs", - }, }, } diff --git a/pkg/tsdb/cloudwatch/log_actions.go b/pkg/tsdb/cloudwatch/log_actions.go index 99bb4fd44be..b2b0ee536ba 100644 --- a/pkg/tsdb/cloudwatch/log_actions.go +++ b/pkg/tsdb/cloudwatch/log_actions.go @@ -35,36 +35,12 @@ func (e *cloudWatchExecutor) executeLogActions(ctx context.Context, req *backend return err } - // When a query of the form "stats ... by ..." is made, we want to return - // one series per group defined in the query, but due to the format - // the query response is in, there does not seem to be a way to tell - // by the response alone if/how the results should be grouped. - // Because of this, if the frontend sees that a "stats ... by ..." query is being made - // the "statsGroups" parameter is sent along with the query to the backend so that we - // can correctly group the CloudWatch logs response. - statsGroups := model.Get("statsGroups").MustStringArray() - if len(statsGroups) > 0 && len(dataframe.Fields) > 0 { - groupedFrames, err := groupResults(dataframe, statsGroups) - if err != nil { - return err - } - - resultChan <- backend.Responses{ - query.RefID: backend.DataResponse{Frames: groupedFrames}, - } - return nil + groupedFrames, err := groupResponseFrame(dataframe, model.Get("statsGroups").MustStringArray()) + if err != nil { + return err } - - if dataframe.Meta != nil { - dataframe.Meta.PreferredVisualization = "logs" - } else { - dataframe.Meta = &data.FrameMeta{ - PreferredVisualization: "logs", - } - } - resultChan <- backend.Responses{ - query.RefID: backend.DataResponse{Frames: data.Frames{dataframe}}, + query.RefID: backend.DataResponse{Frames: groupedFrames}, } return nil }) diff --git a/pkg/tsdb/cloudwatch/log_actions_test.go b/pkg/tsdb/cloudwatch/log_actions_test.go index afce302d9d1..f52a7338d58 100644 --- a/pkg/tsdb/cloudwatch/log_actions_test.go +++ b/pkg/tsdb/cloudwatch/log_actions_test.go @@ -81,9 +81,6 @@ func TestQuery_DescribeLogGroups(t *testing.T) { aws.String("group_a"), aws.String("group_b"), aws.String("group_c"), }), }, - Meta: &data.FrameMeta{ - PreferredVisualization: "logs", - }, }, }, }, @@ -142,9 +139,6 @@ func TestQuery_DescribeLogGroups(t *testing.T) { aws.String("group_a"), aws.String("group_b"), aws.String("group_c"), }), }, - Meta: &data.FrameMeta{ - PreferredVisualization: "logs", - }, }, }, }, @@ -220,9 +214,6 @@ func TestQuery_GetLogGroupFields(t *testing.T) { aws.Int64(100), aws.Int64(30), aws.Int64(55), }), }, - Meta: &data.FrameMeta{ - PreferredVisualization: "logs", - }, } expFrame.RefID = refID assert.Equal(t, &backend.QueryDataResponse{Responses: backend.Responses{ @@ -357,7 +348,6 @@ func TestQuery_StartQuery(t *testing.T) { Custom: map[string]interface{}{ "Region": "default", }, - PreferredVisualization: "logs", } assert.Equal(t, &backend.QueryDataResponse{Responses: backend.Responses{ refID: { @@ -431,9 +421,6 @@ func TestQuery_StopQuery(t *testing.T) { Fields: []*data.Field{ data.NewField("success", nil, []bool{true}), }, - Meta: &data.FrameMeta{ - PreferredVisualization: "logs", - }, } assert.Equal(t, &backend.QueryDataResponse{Responses: backend.Responses{ "": {