Skip to content

Commit bbed3ae

Browse files
[8.15](backport #41022) [AWS] Use namespace for GetListMetrics when exists (#41175)
* [AWS] Use namespace for GetListMetrics when exists (#41022) * Use namespace for GetListMetrics when exists (cherry picked from commit 36327a4) --------- Co-authored-by: kaiyan-sheng <kaiyan.sheng@elastic.co>
1 parent 2a714a1 commit bbed3ae

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
124124
- Fix Azure Monitor 429 error by causing metricbeat to retry the request again. {pull}38294[38294]
125125
- Fix fields not being parsed correctly in postgresql/database {issue}25301[25301] {pull}37720[37720]
126126
- rabbitmq/queue - Change the mapping type of `rabbitmq.queue.consumers.utilisation.pct` to `scaled_float` from `long` because the values fall within the range of `[0.0, 1.0]`. Previously, conversion to integer resulted in reporting either `0` or `1`.
127+
- Use namespace for GetListMetrics when exists in AWS {pull}41022[41022]
127128

128129
*Osquerybeat*
129130

metricbeat/docs/modules/aws.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ GetMetricData max page size: 100, based on https://docs.aws.amazon.com/AmazonClo
329329
| IAM ListAccountAliases | 1 | Once on startup
330330
| STS GetCallerIdentity | 1 | Once on startup
331331
| EC2 DescribeRegions| 1 | Once on startup
332-
| CloudWatch ListMetrics | Total number of results / ListMetrics max page size | Per region per collection period
332+
| CloudWatch ListMetrics without specifying namespace in configuration | Total number of results / ListMetrics max page size | Per region per collection period
333+
| CloudWatch ListMetrics with specific namespaces in configuration | Total number of results / ListMetrics max page size * number of unique namespaces | Per region per collection period
333334
| CloudWatch GetMetricData | Total number of results / GetMetricData max page size | Per region per namespace per collection period
334335
|===
335336
`billing`, `ebs`, `elb`, `sns`, `usage` and `lambda` are the same as `cloudwatch` metricset.

x-pack/metricbeat/module/aws/_meta/docs.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ GetMetricData max page size: 100, based on https://docs.aws.amazon.com/AmazonClo
317317
| IAM ListAccountAliases | 1 | Once on startup
318318
| STS GetCallerIdentity | 1 | Once on startup
319319
| EC2 DescribeRegions| 1 | Once on startup
320-
| CloudWatch ListMetrics | Total number of results / ListMetrics max page size | Per region per collection period
320+
| CloudWatch ListMetrics without specifying namespace in configuration | Total number of results / ListMetrics max page size | Per region per collection period
321+
| CloudWatch ListMetrics with specific namespaces in configuration | Total number of results / ListMetrics max page size * number of unique namespaces | Per region per collection period
321322
| CloudWatch GetMetricData | Total number of results / GetMetricData max page size | Per region per namespace per collection period
322323
|===
323324
`billing`, `ebs`, `elb`, `sns`, `usage` and `lambda` are the same as `cloudwatch` metricset.

x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,22 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error {
179179
continue
180180
}
181181

182-
// retrieve all the details for all the metrics available in the current region
183-
listMetricsOutput, err := aws.GetListMetricsOutput("*", regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch)
184-
if err != nil {
185-
m.Logger().Errorf("Error while retrieving the list of metrics for region %s: %w", regionName, err)
182+
// retrieve all the details for all the metrics available in the current region when no namespace is specified
183+
// otherwise only retrieve metrics from the specific namespaces from the config
184+
var listMetricsOutput []aws.MetricWithID
185+
if len(namespaceDetailTotal) == 0 {
186+
listMetricsOutput, err = aws.GetListMetricsOutput("*", regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch)
187+
if err != nil {
188+
m.Logger().Errorf("Error while retrieving the list of metrics for region %s and namespace %s: %w", regionName, "*", err)
189+
}
190+
} else {
191+
for namespace := range namespaceDetailTotal {
192+
listMetricsOutputPerNamespace, err := aws.GetListMetricsOutput(namespace, regionName, m.Period, m.IncludeLinkedAccounts, m.OwningAccount, m.MonitoringAccountID, svcCloudwatch)
193+
if err != nil {
194+
m.Logger().Errorf("Error while retrieving the list of metrics for region %s and namespace %s: %w", regionName, namespace, err)
195+
}
196+
listMetricsOutput = append(listMetricsOutput, listMetricsOutputPerNamespace...)
197+
}
186198
}
187199

188200
if len(listMetricsOutput) == 0 {

0 commit comments

Comments
 (0)