Skip to content

Commit

Permalink
[Metricbeat] azure: move event report into loop validDim loop (#29945) (
Browse files Browse the repository at this point in the history
#30379)

Co-authored-by: Adrian Tomalla <[email protected]>
Co-authored-by: Patrick Eichhorn <[email protected]>
(cherry picked from commit ef7a0b9)

Co-authored-by: ClumsyPotato <[email protected]>
  • Loading branch information
mergify[bot] and ClumsyPotato authored Feb 14, 2022
1 parent 02d6083 commit fe1f651
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
37 changes: 19 additions & 18 deletions x-pack/metricbeat/module/azure/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,34 @@ func EventsMapping(metrics []Metric, client *Client, report mb.ReporterV2) error
groupByDimensions[dimKey] = append(groupByDimensions[dimKey], dimGroupValue)
}
for _, groupDimValues := range groupByDimensions {
event, metricList = createEvent(timestamp, defaultMetric, resource, groupDimValues)
if client.Config.AddCloudMetadata {
vm = client.GetVMForMetaData(&resource, groupDimValues)
addCloudVMMetadata(&event, vm, resource.Subscription)
}
manageAndReportEvent(client, report, event, metricList, vm, timestamp, defaultMetric, resource, groupDimValues)
}
}
} else {
event, metricList = createEvent(timestamp, defaultMetric, resource, groupTimeValues)
if client.Config.AddCloudMetadata {
vm = client.GetVMForMetaData(&resource, groupTimeValues)
addCloudVMMetadata(&event, vm, resource.Subscription)
}
manageAndReportEvent(client, report, event, metricList, vm, timestamp, defaultMetric, resource, groupTimeValues)
}
if client.Config.DefaultResourceType == "" {
event.ModuleFields.Put("metrics", metricList)
} else {
for key, metric := range metricList {
event.MetricSetFields.Put(key, metric)
}
}
report.Event(event)
}
}
return nil
}

// manageAndReportEvent function will handle event creation and report
func manageAndReportEvent(client *Client, report mb.ReporterV2, event mb.Event, metricList common.MapStr, vm VmResource, timestamp time.Time, defaultMetric Metric, resource Resource, groupedValues []MetricValue) {
event, metricList = createEvent(timestamp, defaultMetric, resource, groupedValues)
if client.Config.AddCloudMetadata {
vm = client.GetVMForMetaData(&resource, groupedValues)
addCloudVMMetadata(&event, vm, resource.Subscription)
}
if client.Config.DefaultResourceType == "" {
event.ModuleFields.Put("metrics", metricList)
} else {
for key, metric := range metricList {
event.MetricSetFields.Put(key, metric)
}
}
report.Event(event)
}

// managePropertyName function will handle metric names, there are several formats the metric names are written
func managePropertyName(metric string) string {
// replace spaces with underscores
Expand Down
30 changes: 12 additions & 18 deletions x-pack/metricbeat/module/azure/monitor/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"azure": {
"dimensions": {
"activity_name": "secretlist"
},
"metrics": {
"data_usage": {
"total": 131072
},
"document_count": {
"total": 2
},
"document_quota": {
"total": 107374182400
"availability": {
"avg": 100
}
},
"namespace": "Microsoft.DocumentDb/databaseAccounts",
"namespace": "Microsoft.KeyVault/vaults",
"resource": {
"group": "obs-infrastructure",
"id": "/subscriptions/70bd6e64-4b1e-4835-8896-db77b8eef364/resourceGroups/obs-infrastructure/providers/Microsoft.DocumentDb/databaseAccounts/obsaccount",
"name": "obsaccount",
"tags": {
"defaultExperience": "Core (SQL)"
},
"type": "Microsoft.DocumentDb/databaseAccounts"
"group": "some-rg",
"id": "/subscriptions/70f046a0-a299-ab73-9950-88ac8b5ac454/resourceGroups/some-rg/providers/Microsoft.KeyVault/vaults/somekeyvault",
"name": "somekeyvault",
"type": "Microsoft.KeyVault/vaults"
},
"subscription_id": "70bd6e64-4b1e-4835-8896-db77b8eef364",
"timegrain": "PT5M"
"timegrain": "PT1M"
},
"cloud": {
"provider": "azure",
Expand All @@ -41,4 +35,4 @@
"service": {
"type": "azure"
}
}
}
17 changes: 17 additions & 0 deletions x-pack/metricbeat/module/azure/monitor/monitor_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/libbeat/common"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
)

Expand All @@ -37,3 +39,18 @@ func TestData(t *testing.T) {
metricSet := mbtest.NewFetcher(t, config)
metricSet.WriteEvents(t, "/")
}

func TestDataMultipleDimensions(t *testing.T) {
config := test.GetConfig(t, "monitor")
config["resources"] = []map[string]interface{}{{
"resource_query": "resourceType eq 'Microsoft.KeyVault/vaults'",
"metrics": []map[string]interface{}{{"namespace": "Microsoft.KeyVault/vaults",
"name": []string{"Availability"}, "dimensions": []map[string]interface{}{{"name": "ActivityName", "value": "*"}}}}}}
metricSet := mbtest.NewFetcher(t, config)
metricSet.WriteEventsCond(t, "/", func(m common.MapStr) bool {
if m["azure"].(common.MapStr)["dimensions"].(common.MapStr)["activity_name"] == "secretget" {
return true
}
return false
})
}

0 comments on commit fe1f651

Please sign in to comment.