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

[Metricbeat] azure: move event report into loop validDim loop #29945

Merged
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
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"
}
}
}
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
})
}