mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch Logs: Fix log query display name when used with expressions (#74497)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user