From a419b52f5881459f440939e5a8823352d0a7dd72 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Thu, 26 Sep 2024 18:04:33 -0600 Subject: [PATCH 1/3] Use namespace for GetListMetrics when exists --- .../module/aws/cloudwatch/cloudwatch.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go index 241aa521663..14bdc48d645 100644 --- a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go +++ b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go @@ -178,9 +178,20 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { } // retrieve all the details for all the metrics available in the current region - listMetricsOutput, err := aws.GetListMetricsOutput("*", regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) - if err != nil { - m.Logger().Errorf("Error while retrieving the list of metrics for region %s: %w", regionName, err) + var listMetricsOutput []aws.MetricWithID + if namespaceDetailTotal == nil { + listMetricsOutput, err = aws.GetListMetricsOutput("*", regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) + if err != nil { + m.Logger().Errorf("Error while retrieving the list of metrics for region %s and namespace %s: %w", regionName, "*", err) + } + } else { + for namespace, _ := range namespaceDetailTotal { + listMetricsOutputPerNamespace, err := aws.GetListMetricsOutput(namespace, regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) + if err != nil { + m.Logger().Errorf("Error while retrieving the list of metrics for region %s and namespace %s: %w", regionName, namespace, err) + } + listMetricsOutput = append(listMetricsOutput, listMetricsOutputPerNamespace...) + } } if len(listMetricsOutput) == 0 { From 4143efb1e18395c88684ca334da096b79b38b03b Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Fri, 27 Sep 2024 09:34:14 -0600 Subject: [PATCH 2/3] add changelog --- CHANGELOG.next.asciidoc | 3 ++- x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 303f64d2b6c..6c8bc8151f7 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -194,6 +194,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Remove excessive info-level logs in cgroups setup {pull}40491[40491] - Add missing ECS Cloud fields in GCP `metrics` metricset when using `exclude_labels: true` {issue}40437[40437] {pull}40467[40467] - Add AWS OwningAccount support for cross account monitoring {issue}40570[40570] {pull}40691[40691] +- Use namespace for GetListMetrics when exists in AWS {pull}41022[41022] *Osquerybeat* @@ -332,7 +333,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Add new metricset cluster for the vSphere module. {pull}40536[40536] - Add new metricset network for the vSphere module. {pull}40559[40559] - Add new metricset resourcepool for the vSphere module. {pull}40456[40456] -- Add new metricset datastorecluster for vSphere module. {pull}40634[40634] +- Add new metricset datastorecluster for vSphere module. {pull}40634[40634] - Add support for new metrics in datastorecluster metricset. {pull}40694[40694] - Add new metrics for the vSphere Virtualmachine metricset. {pull}40485[40485] - Add support for snapshot in vSphere virtualmachine metricset {pull}40683[40683] diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go index 14bdc48d645..048efd83de0 100644 --- a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go +++ b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go @@ -177,7 +177,8 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { continue } - // retrieve all the details for all the metrics available in the current region + // retrieve all the details for all the metrics available in the current region when no namespace is specified + // otherwise only retrieve metrics from the specific namespaces from the config var listMetricsOutput []aws.MetricWithID if namespaceDetailTotal == nil { listMetricsOutput, err = aws.GetListMetricsOutput("*", regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) @@ -186,7 +187,8 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { } } else { for namespace, _ := range namespaceDetailTotal { - listMetricsOutputPerNamespace, err := aws.GetListMetricsOutput(namespace, regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) + var listMetricsOutputPerNamespace []aws.MetricWithID + listMetricsOutputPerNamespace, err = aws.GetListMetricsOutput(namespace, regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) if err != nil { m.Logger().Errorf("Error while retrieving the list of metrics for region %s and namespace %s: %w", regionName, namespace, err) } From 95df0a6008a3b5160e9057f0288b1a422a17422d Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Fri, 27 Sep 2024 10:27:05 -0600 Subject: [PATCH 3/3] fix lint --- x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go index 048efd83de0..487826506d3 100644 --- a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go +++ b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go @@ -186,9 +186,8 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { m.Logger().Errorf("Error while retrieving the list of metrics for region %s and namespace %s: %w", regionName, "*", err) } } else { - for namespace, _ := range namespaceDetailTotal { - var listMetricsOutputPerNamespace []aws.MetricWithID - listMetricsOutputPerNamespace, err = aws.GetListMetricsOutput(namespace, regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) + for namespace := range namespaceDetailTotal { + listMetricsOutputPerNamespace, err := aws.GetListMetricsOutput(namespace, regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch) if err != nil { m.Logger().Errorf("Error while retrieving the list of metrics for region %s and namespace %s: %w", regionName, namespace, err) }