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

Cherry-pick #20736 to 7.x: Fill cloud.account.name with accountID if account alias doesn't exist #20745

Merged
merged 3 commits into from
Aug 26, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Groups same timestamp metric values to one event in the app_insights metricset. {pull}20403[20403]
- Updates vm_compute metricset with more info on guest metrics. {pull}20448[20448]
- Fix resource tags in aws cloudwatch metricset {issue}20326[20326] {pull}20385[20385]
- Fill cloud.account.name with accountID if account alias doesn't exist. {pull}20736[20736]
- Fix ec2 disk and network metrics to use Sum statistic method. {pull}20680[20680]

*Packetbeat*
Expand Down
13 changes: 9 additions & 4 deletions x-pack/metricbeat/module/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,24 @@ func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) {
default:
awsConfig.Region = "us-east-1"
}

svcIam := iam.New(awscommon.EnrichAWSConfigWithEndpoint(
config.AWSConfig.Endpoint, "iam", "", awsConfig))
req := svcIam.ListAccountAliasesRequest(&iam.ListAccountAliasesInput{})
output, err := req.Send(context.TODO())
if err != nil {
base.Logger().Warn("failed to list account aliases, please check permission setting: ", err)
metricSet.AccountName = metricSet.AccountID
} else {
// When there is no account alias, account ID will be used as cloud.account.name
if len(output.AccountAliases) == 0 {
metricSet.AccountName = metricSet.AccountID
}

// There can be more than one aliases for each account, for now we are only
// collecting the first one.
if output.AccountAliases != nil {
metricSet.AccountName = output.AccountAliases[0]
base.Logger().Debug("AWS Credentials belong to account name: ", metricSet.AccountName)
}
metricSet.AccountName = output.AccountAliases[0]
base.Logger().Debug("AWS Credentials belong to account name: ", metricSet.AccountName)
}

// Get IAM account id
Expand Down