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
This commit is contained in:
Andrej Ocenas 2021-09-08 16:30:55 +02:00 committed by GitHub
parent 5e38b02f94
commit 91a67ab0fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 44 deletions

View File

@ -129,9 +129,6 @@ func TestQueryCloudWatchLogs(t *testing.T) {
Fields: []*data.Field{
data.NewField("logGroupName", nil, []*string{}),
},
Meta: &data.FrameMeta{
PreferredVisualization: "logs",
},
},
}

View File

@ -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
})

View File

@ -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{
"": {