Skip to content

Commit

Permalink
[Metricbeat] [Azure] Fix monitor namespace empty string (#36295)
Browse files Browse the repository at this point in the history
* add monitor fix

* add changelog entry
  • Loading branch information
gpop63 authored Sep 8, 2023
1 parent 9ca9434 commit ad64f28
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Resolve statsd module's prematurely halting of metrics parsing upon encountering an invalid packet. {pull}35075[35075]
- Fix the gap in fetching forecast API metrics at the end of each month for Azure billing module {pull}36142[36142]
- Add option in SQL module to execute queries for all dbs. {pull}35688[35688]
- Fix Azure Monitor empty metricnamespace. {pull}36295[36295]
- Fix GCP compute metadata. {pull}36338[36338]
- Add support for api_key authentication in elasticsearch module {pull}36274[36274]
- Add remaining dimensions for azure storage account to make them available for tsdb enablement. {pull}36331[36331]
Expand Down
33 changes: 21 additions & 12 deletions x-pack/metricbeat/module/azure/monitor_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ func (service *MonitorService) GetMetricNamespaces(resourceId string) (armmonito

// GetMetricDefinitions will return all supported metrics based on the resource id and namespace
func (service *MonitorService) GetMetricDefinitions(resourceId string, namespace string) (armmonitor.MetricDefinitionCollection, error) {
pager := service.metricDefinitionClient.NewListPager(resourceId, &armmonitor.MetricDefinitionsClientListOptions{
Metricnamespace: &namespace,
})
opts := &armmonitor.MetricDefinitionsClientListOptions{}

if namespace != "" {
opts.Metricnamespace = &namespace
}

pager := service.metricDefinitionClient.NewListPager(resourceId, opts)

metricDefinitionCollection := armmonitor.MetricDefinitionCollection{}

Expand Down Expand Up @@ -246,17 +250,22 @@ func (service *MonitorService) GetMetricValues(resourceId string, namespace stri

metricNames := strings.Join(metricNames[i:end], ",")

resp, err := service.metricsClient.List(service.context, resourceId, &armmonitor.MetricsClientListOptions{
Aggregation: &aggregations,
Filter: metricsFilter,
Interval: tg,
Metricnames: &metricNames,
Metricnamespace: &namespace,
Timespan: &timespan,
Top: nil,
opts := &armmonitor.MetricsClientListOptions{
Aggregation: &aggregations,
Filter: metricsFilter,
Interval: tg,
Metricnames: &metricNames,
Timespan: &timespan,
Top: nil,
// Orderby: &orderBy,
ResultType: &resultTypeData,
})
}

if namespace != "" {
opts.Metricnamespace = &namespace
}

resp, err := service.metricsClient.List(service.context, resourceId, opts)

// check for applied charges before returning any errors
if resp.Cost != nil && *resp.Cost != 0 {
Expand Down

0 comments on commit ad64f28

Please sign in to comment.