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

[Azure] [Billing] Add Azure resource tags from Usage Details API #36428

Merged
merged 5 commits into from
Aug 30, 2023
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.
Jump to
Jump to file
Failed to load files.
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 @@ -229,6 +229,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Migrate Azure Billing, Monitor, and Storage metricsets to the newer SDK. {pull}33585[33585]
- Add support for float64 values parsing for statsd metrics of counter type. {pull}35099[35099]
- Add kubernetes.deployment.status.* fields for Kubernetes module {pull}35999[35999]
- Add Azure resource tags support to Azure Billing module {pull}36428[36428]


*Osquerybeat*
Expand Down
8 changes: 8 additions & 0 deletions x-pack/metricbeat/module/azure/billing/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func EventsMapping(
"group": legacy.Properties.ResourceGroup,
},
}
if len(legacy.Tags) > 0 {
_, _ = event.ModuleFields.Put("resource.tags", legacy.Tags)
devamanv marked this conversation as resolved.
Show resolved Hide resolved
}

event.MetricSetFields = mapstr.M{
// original fields
"billing_period_id": legacy.ID,
Expand Down Expand Up @@ -96,6 +100,10 @@ func EventsMapping(
"group": strings.ToLower(*modern.Properties.ResourceGroup),
},
}
if len(modern.Tags) > 0 {
_, _ = event.ModuleFields.Put("resource.tags", modern.Tags)
}

event.MetricSetFields = mapstr.M{
// original fields
"billing_period_id": modern.ID,
Expand Down
15 changes: 14 additions & 1 deletion x-pack/metricbeat/module/azure/billing/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestEventMapping(t *testing.T) {
name := "test"
billingAccountId := "123"
startDate := time.Time{}
tagName := "team"
tagValue := "obs-cloud-monitoring"

//
// Usage Details
Expand All @@ -49,6 +51,9 @@ func TestEventMapping(t *testing.T) {
ID: &ID,
Kind: &kind,
Properties: &props,
Tags: map[string]*string{
tagName: &tagValue,
},
}

//
Expand Down Expand Up @@ -102,15 +107,23 @@ func TestEventMapping(t *testing.T) {
// Check the results
//
for _, event := range events {
// if is an usage event
if ok, _ := event.MetricSetFields.HasKey("department_name"); ok {
//
// The event is a usage detail
//
val1, _ := event.MetricSetFields.GetValue("account_name")
assert.Equal(t, val1, &name)
val2, _ := event.MetricSetFields.GetValue("product")
assert.Equal(t, val2, &name)
val3, _ := event.MetricSetFields.GetValue("department_name")
assert.Equal(t, val3, &name)
tags, _ := event.ModuleFields.GetValue("resource.tags")
assert.Equal(t, tags, map[string]*string{tagName: &tagValue})

} else {
//
// The event is a forecast
//

// Check the actual cost
isActual, _ := event.MetricSetFields.HasKey("actual_cost")
Expand Down