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

[AWS Cloudwatch] Changed module to call ListMetrics API only once per region #34055

Merged
merged 14 commits into from
Dec 19, 2022
Merged
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Add support for multiple regions in GCP {pull}32964[32964]
- Add GCP Redis regions support {pull}33728[33728]
- Add namespace metadata to all namespaced kubernetes resources. {pull}33763[33763]
- Changed cloudwatch module to call ListMetrics API only once per region, instead of per AWS namespace {pull}34055[34055]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/docs/modules/aws.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ GetMetricData max page size: 100, based on https://docs.aws.amazon.com/AmazonClo
| IAM ListAccountAliases | 1 | Once on startup
| STS GetCallerIdentity | 1 | Once on startup
| EC2 DescribeRegions| 1 | Once on startup
| CloudWatch ListMetrics | Total number of results / ListMetrics max page size | Per region per namespace per collection period
| CloudWatch ListMetrics | Total number of results / ListMetrics max page size | Per region per collection period
| CloudWatch GetMetricData | Total number of results / GetMetricData max page size | Per region per namespace per collection period
|===
`billing`, `ebs`, `elb`, `sns`, `usage` and `lambda` are the same as `cloudwatch` metricset.
Expand Down
2 changes: 1 addition & 1 deletion x-pack/metricbeat/module/aws/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ GetMetricData max page size: 100, based on https://docs.aws.amazon.com/AmazonClo
| IAM ListAccountAliases | 1 | Once on startup
| STS GetCallerIdentity | 1 | Once on startup
| EC2 DescribeRegions| 1 | Once on startup
| CloudWatch ListMetrics | Total number of results / ListMetrics max page size | Per region per namespace per collection period
| CloudWatch ListMetrics | Total number of results / ListMetrics max page size | Per region per collection period
| CloudWatch GetMetricData | Total number of results / GetMetricData max page size | Per region per namespace per collection period
|===
`billing`, `ebs`, `elb`, `sns`, `usage` and `lambda` are the same as `cloudwatch` metricset.
Expand Down
14 changes: 13 additions & 1 deletion x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,22 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error {
if err != nil {
m.Logger().Warn("skipping metrics list from region '%s'", regionName)
}

// retrieve all the details for all the metrics available in the current region
regionListMetricsOutput, err := aws.GetListMetricsOutput("*", regionName, m.Period, svcCloudwatch)

// filter out metrics details for namespaces that are not included in the configuration
listMetricsOutput := make([]types.Metric, 0)
girodav marked this conversation as resolved.
Show resolved Hide resolved
for _, listMetricDetail := range regionListMetricsOutput {
namespace := *listMetricDetail.Namespace
if _, ok := namespaceDetailTotal[namespace]; ok {
listMetricsOutput = append(listMetricsOutput, listMetricDetail)
}
}

for namespace, namespaceDetails := range namespaceDetailTotal {
m.logger.Debugf("Collected metrics from namespace %s", namespace)

listMetricsOutput, err := aws.GetListMetricsOutput(namespace, regionName, m.Period, svcCloudwatch)
if err != nil {
girodav marked this conversation as resolved.
Show resolved Hide resolved
m.logger.Info(err.Error())
continue
Expand Down