mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch Logs: Add labels to alert and expression queries (#77529)
This commit is contained in:
parent
9e0ca0d113
commit
64e28c0ae2
@ -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…
Reference in New Issue
Block a user