Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont overwrite metadata in rds and dimension in cloudwatch #29101

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ func insertRootFields(event mb.Event, metricValue float64, labels []string) mb.E
dimNames := strings.Split(labels[identifierNameIdx], ",")
dimValues := strings.Split(labels[identifierValueIdx], ",")
for i := 0; i < len(dimNames); i++ {
event.RootFields.Put("aws.dimensions."+dimNames[i], dimValues[i])
if _, err := event.RootFields.GetValue("aws.dimensions." + dimNames[i]); err == common.ErrKeyNotFound {
event.RootFields.Put("aws.dimensions."+dimNames[i], dimValues[i])
}

}
return event
}
Expand Down
29 changes: 22 additions & 7 deletions x-pack/metricbeat/module/aws/cloudwatch/metadata/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/rds/rdsiface"
"github.com/pkg/errors"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/metricbeat/mb"
awscommon "github.com/elastic/beats/v7/x-pack/libbeat/common/aws"
Expand Down Expand Up @@ -47,31 +48,45 @@ func AddMetadata(endpoint string, regionName string, awsConfig awssdk.Config, ev
}

if output.DBInstanceArn != nil {
events[identifier].RootFields.Put(metadataPrefix+"arn", *output.DBInstanceArn)
if _, err := events[identifier].RootFields.GetValue(metadataPrefix + "arn"); err == common.ErrKeyNotFound {
events[identifier].RootFields.Put(metadataPrefix+"arn", *output.DBInstanceArn)
}
}

if output.DBInstanceStatus != nil {
events[identifier].RootFields.Put(metadataPrefix+"status", *output.DBInstanceStatus)
if _, err := events[identifier].RootFields.GetValue(metadataPrefix + "status"); err == common.ErrKeyNotFound {
events[identifier].RootFields.Put(metadataPrefix+"status", *output.DBInstanceStatus)
}
}

if output.DBInstanceIdentifier != nil {
events[identifier].RootFields.Put(metadataPrefix+"identifier", *output.DBInstanceIdentifier)
if _, err := events[identifier].RootFields.GetValue(metadataPrefix + "identifier"); err == common.ErrKeyNotFound {
events[identifier].RootFields.Put(metadataPrefix+"identifier", *output.DBInstanceIdentifier)
}
}

if output.DBClusterIdentifier != nil {
events[identifier].RootFields.Put(metadataPrefix+"db_cluster_identifier", *output.DBClusterIdentifier)
if _, err := events[identifier].RootFields.GetValue(metadataPrefix + "db_cluster_identifier"); err == common.ErrKeyNotFound {
events[identifier].RootFields.Put(metadataPrefix+"db_cluster_identifier", *output.DBClusterIdentifier)
}
}

if output.DBInstanceClass != nil {
events[identifier].RootFields.Put(metadataPrefix+"class", *output.DBInstanceClass)
if _, err := events[identifier].RootFields.GetValue(metadataPrefix + "class"); err == common.ErrKeyNotFound {
events[identifier].RootFields.Put(metadataPrefix+"class", *output.DBInstanceClass)
}
}

if output.Engine != nil {
events[identifier].RootFields.Put(metadataPrefix+"engine_name", *output.Engine)
if _, err := events[identifier].RootFields.GetValue(metadataPrefix + "engine_name"); err == common.ErrKeyNotFound {
events[identifier].RootFields.Put(metadataPrefix+"engine_name", *output.Engine)
}
}

if output.AvailabilityZone != nil {
events[identifier].RootFields.Put("cloud.availability_zone", *output.AvailabilityZone)
if _, err := events[identifier].RootFields.GetValue("cloud.availability_zone"); err == common.ErrKeyNotFound {
events[identifier].RootFields.Put("cloud.availability_zone", *output.AvailabilityZone)
}
}
}
return events
Expand Down