CloudWatch Logs: Add labels to alert and expression queries (#77529)

pull/77600/head
Isabella Siu 2 years ago committed by GitHub
parent 9e0ca0d113
commit 64e28c0ae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      pkg/tsdb/cloudwatch/log_query.go
  2. 4
      pkg/tsdb/cloudwatch/log_query_test.go

@ -205,14 +205,16 @@ func groupResults(results *data.Frame, groupingFieldNames []string, fromSyncQuer
if fromSyncQuery {
// remove grouping indices
newFrame.Fields = removeFieldsByIndex(newFrame.Fields, removeFieldIndices)
groupLabels := generateLabels(groupingFields, i)
// set the group key as the display name for sync queries
for i := 1; i < len(newFrame.Fields); i++ {
valueField := newFrame.Fields[i]
for j := 1; j < len(newFrame.Fields); j++ {
valueField := newFrame.Fields[j]
if valueField.Config == nil {
valueField.Config = &data.FieldConfig{}
}
valueField.Config.DisplayNameFromDS = groupKey
valueField.Labels = groupLabels
}
}
@ -275,10 +277,21 @@ func generateGroupKey(fields []*data.Field, row int) string {
}
}
}
return groupKey
}
func generateLabels(fields []*data.Field, row int) data.Labels {
labels := data.Labels{}
for _, field := range fields {
if strField, ok := field.At(row).(*string); ok {
if strField != nil {
labels[field.Name] = *strField
}
}
}
return labels
}
func numericFieldToStringField(field *data.Field) (*data.Field, error) {
if !field.Type().Numeric() {
return nil, fmt.Errorf("field is not numeric")

@ -583,7 +583,7 @@ func TestGroupingResultsWithFromSyncQueryTrue(t *testing.T) {
Name: "fakelog-a1",
Fields: []*data.Field{
data.NewField("@timestamp", data.Labels{}, []*time.Time{&timeA, &timeB}),
data.NewField("count", data.Labels{}, []*string{
data.NewField("count", data.Labels{"@log": "fakelog-a", "stream": "1"}, []*string{
aws.String("100"),
aws.String("57"),
}),
@ -594,7 +594,7 @@ func TestGroupingResultsWithFromSyncQueryTrue(t *testing.T) {
Name: "fakelog-b1",
Fields: []*data.Field{
data.NewField("@timestamp", data.Labels{}, []*time.Time{&timeA, &timeB}),
data.NewField("count", data.Labels{}, []*string{
data.NewField("count", data.Labels{"@log": "fakelog-b", "stream": "1"}, []*string{
aws.String("150"),
aws.String("62"),
}),

Loading…
Cancel
Save