CloudWatch Logs: Fix log query display name when used with expressions (#74497)

This commit is contained in:
Isabella Siu
2023-09-13 15:04:50 -04:00
committed by GitHub
parent 2d8f5c1488
commit 4b7b323061
2 changed files with 19 additions and 5 deletions

View File

@@ -163,7 +163,7 @@ func changeToStringField(lengthOfValues int, rows [][]*cloudwatchlogs.ResultFiel
return fieldValuesAsStrings
}
func groupResults(results *data.Frame, groupingFieldNames []string, removeNonTime bool) ([]*data.Frame, error) {
func groupResults(results *data.Frame, groupingFieldNames []string, fromSyncQuery bool) ([]*data.Frame, error) {
groupingFields := make([]*data.Field, 0)
removeFieldIndices := make([]int, 0)
@@ -180,7 +180,7 @@ func groupResults(results *data.Frame, groupingFieldNames []string, removeNonTim
field = newField
}
// For expressions and alerts to work properly we need to remove non-time grouping fields
if removeNonTime && !field.Type().Time() {
if fromSyncQuery && !field.Type().Time() {
removeFieldIndices = append(removeFieldIndices, i)
}
@@ -202,8 +202,20 @@ func groupResults(results *data.Frame, groupingFieldNames []string, removeNonTim
newFrame := results.EmptyCopy()
newFrame.Name = groupKey
newFrame.Meta = results.Meta
// remove grouping indices
newFrame.Fields = removeFieldsByIndex(newFrame.Fields, removeFieldIndices)
if fromSyncQuery {
// remove grouping indices
newFrame.Fields = removeFieldsByIndex(newFrame.Fields, removeFieldIndices)
// set the group key as the display name for sync queries
for i := 1; i < len(newFrame.Fields); i++ {
valueField := newFrame.Fields[i]
if valueField.Config == nil {
valueField.Config = &data.FieldConfig{}
}
valueField.Config.DisplayNameFromDS = groupKey
}
}
groupedDataFrames[groupKey] = newFrame
}

View File

@@ -543,7 +543,7 @@ func TestGroupingResultsWithNumericField(t *testing.T) {
assert.ElementsMatch(t, expectedGroupedFrames, groupedResults)
}
func TestGroupingResultsWithRemoveNonTimeTrue(t *testing.T) {
func TestGroupingResultsWithFromSyncQueryTrue(t *testing.T) {
logField := data.NewField("@log", data.Labels{}, []*string{
aws.String("fakelog-a"),
aws.String("fakelog-b"),
@@ -602,6 +602,8 @@ func TestGroupingResultsWithRemoveNonTimeTrue(t *testing.T) {
RefID: "",
},
}
expectedGroupedFrames[0].Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: "fakelog-a1"}
expectedGroupedFrames[1].Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: "fakelog-b1"}
groupedResults, err := groupResults(fakeDataFrame, []string{"@log", "stream"}, true)
require.NoError(t, err)