Skip to content

Commit

Permalink
fix linked accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
BenB196 committed Apr 7, 2024
1 parent e1d5be2 commit 776170a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions x-pack/metricbeat/module/aws/billing/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ func (m *MetricSet) getCostGroupBy(svcCostExplorer *costexplorer.Client, groupBy
if index == 0 {
if groupByPrimaryType == costexplorertypes.GroupDefinitionTypeDimension {
_, _ = event.MetricSetFields.Put("group_by."+groupBy.primary, key)

if groupBy.primary == "LINKED_ACCOUNT" {
if name, ok := accounts[key]; ok {
_, _ = event.RootFields.Put("aws.linked_account.id", key)
_, _ = event.RootFields.Put("aws.linked_account.name", name)
}
}
}
if groupByPrimaryType == costexplorertypes.GroupDefinitionTypeTag {
// tag key value is separated by $
Expand All @@ -374,6 +381,13 @@ func (m *MetricSet) getCostGroupBy(svcCostExplorer *costexplorer.Client, groupBy
if index == 1 {
if groupBySecondaryType == costexplorertypes.GroupDefinitionTypeDimension {
_, _ = event.MetricSetFields.Put("group_by."+groupBy.secondary, key)

if groupBy.secondary == "LINKED_ACCOUNT" {
if name, ok := accounts[key]; ok {
_, _ = event.RootFields.Put("aws.linked_account.id", key)
_, _ = event.RootFields.Put("aws.linked_account.name", name)
}
}
}
if groupBySecondaryType == costexplorertypes.GroupDefinitionTypeTag {
// tag key value is separated by $
Expand All @@ -391,13 +405,6 @@ func (m *MetricSet) getCostGroupBy(svcCostExplorer *costexplorer.Client, groupBy
m.Logger().Errorf("unexpected additional index %d, with key %s, while process metrics", index, key)
continue
}

if groupBy.primary == "LINKED_ACCOUNT" || groupBy.secondary == "LINKED_ACCOUNT" {
if name, ok := accounts[key]; ok {
_, _ = event.RootFields.Put("aws.linked_account.id", key)
_, _ = event.RootFields.Put("aws.linked_account.name", name)
}
}
}

t, err := time.Parse(dateLayout, endDate)
Expand Down

0 comments on commit 776170a

Please sign in to comment.