diff --git a/plugins/inputs/cloudwatch/README.md b/plugins/inputs/cloudwatch/README.md index 0c4a70b0e..737222a46 100644 --- a/plugins/inputs/cloudwatch/README.md +++ b/plugins/inputs/cloudwatch/README.md @@ -96,8 +96,6 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. ## Metric Statistic Namespaces (required) namespaces = ["AWS/ELB"] - ## Single metric statistic namespace appended to namespaces on startup - # namespace = "AWS/ELB" ## Maximum requests per second. Note that the global default AWS rate limit ## is 50 reqs/sec, so if you define multiple namespaces, these should add up @@ -139,14 +137,17 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. # value = "p-example" ``` +Please note, the `namespace` option is deprecated in favor of the `namespaces` +list option. + ## Requirements and Terminology -Plugin Configuration utilizes [CloudWatch concepts][concept] and access pattern to -allow monitoring of any CloudWatch Metric. +Plugin Configuration utilizes [CloudWatch concepts][concept] and access +pattern to allow monitoring of any CloudWatch Metric. - `region` must be a valid AWS [region][] value - `period` must be a valid CloudWatch [period][] value -- `namespace` must be a valid CloudWatch [namespace][] value +- `namespaces` must be a list of valid CloudWatch [namespace][] value(s) - `names` must be valid CloudWatch [metric][] names - `dimensions` must be valid CloudWatch [dimension][] name/value pairs diff --git a/plugins/inputs/cloudwatch/cloudwatch.go b/plugins/inputs/cloudwatch/cloudwatch.go index d1422f657..331644c13 100644 --- a/plugins/inputs/cloudwatch/cloudwatch.go +++ b/plugins/inputs/cloudwatch/cloudwatch.go @@ -48,7 +48,7 @@ type CloudWatch struct { Period config.Duration `toml:"period"` Delay config.Duration `toml:"delay"` - Namespace string `toml:"namespace"` + Namespace string `toml:"namespace" deprecated:"1.25.0;use 'namespaces' instead"` Namespaces []string `toml:"namespaces"` Metrics []*Metric `toml:"metrics"` CacheTTL config.Duration `toml:"cache_ttl"` @@ -320,19 +320,15 @@ func getFilteredMetrics(c *CloudWatch) ([]filteredMetric, error) { func (c *CloudWatch) fetchNamespaceMetrics() ([]types.Metric, error) { metrics := []types.Metric{} - var token *string - - params := &cwClient.ListMetricsInput{ - Dimensions: []types.DimensionFilter{}, - NextToken: token, - MetricName: nil, - } - if c.RecentlyActive == "PT3H" { - params.RecentlyActive = types.RecentlyActivePt3h - } - for _, namespace := range c.Namespaces { - params.Namespace = aws.String(namespace) + params := &cwClient.ListMetricsInput{ + Dimensions: []types.DimensionFilter{}, + Namespace: aws.String(namespace), + } + if c.RecentlyActive == "PT3H" { + params.RecentlyActive = types.RecentlyActivePt3h + } + for { resp, err := c.client.ListMetrics(context.Background(), params) if err != nil { @@ -340,12 +336,11 @@ func (c *CloudWatch) fetchNamespaceMetrics() ([]types.Metric, error) { // skip problem namespace on error and continue to next namespace break } - metrics = append(metrics, resp.Metrics...) + if resp.NextToken == nil { break } - params.NextToken = resp.NextToken } } diff --git a/plugins/inputs/cloudwatch/cloudwatch_test.go b/plugins/inputs/cloudwatch/cloudwatch_test.go index 6b05f5527..4905d0cb3 100644 --- a/plugins/inputs/cloudwatch/cloudwatch_test.go +++ b/plugins/inputs/cloudwatch/cloudwatch_test.go @@ -107,6 +107,7 @@ func TestGather(t *testing.T) { Period: internalDuration, RateLimit: 200, BatchSize: 500, + Log: testutil.Logger{}, } var acc testutil.Accumulator @@ -139,6 +140,7 @@ func TestGather_MultipleNamespaces(t *testing.T) { Period: internalDuration, RateLimit: 200, BatchSize: 500, + Log: testutil.Logger{}, } var acc testutil.Accumulator @@ -231,6 +233,7 @@ func TestSelectMetrics(t *testing.T) { }, }, }, + Log: testutil.Logger{}, } require.NoError(t, c.Init()) c.client = &mockSelectMetricsCloudWatchClient{} @@ -262,6 +265,7 @@ func TestGenerateStatisticsInputParams(t *testing.T) { Delay: internalDuration, Period: internalDuration, BatchSize: 500, + Log: testutil.Logger{}, } require.NoError(t, c.initializeCloudWatch()) @@ -302,6 +306,7 @@ func TestGenerateStatisticsInputParamsFiltered(t *testing.T) { Delay: internalDuration, Period: internalDuration, BatchSize: 500, + Log: testutil.Logger{}, } require.NoError(t, c.initializeCloudWatch()) @@ -342,6 +347,7 @@ func TestUpdateWindow(t *testing.T) { Delay: internalDuration, Period: internalDuration, BatchSize: 500, + Log: testutil.Logger{}, } now := time.Now() @@ -371,6 +377,7 @@ func TestProxyFunction(t *testing.T) { HTTPProxyURL: "http://www.penguins.com", }, BatchSize: 500, + Log: testutil.Logger{}, } proxyFunction, err := c.HTTPProxy.Proxy() @@ -389,6 +396,7 @@ func TestCombineNamespaces(t *testing.T) { Namespace: "AWS/ELB", Namespaces: []string{"AWS/EC2", "AWS/Billing"}, BatchSize: 500, + Log: testutil.Logger{}, } require.NoError(t, c.Init()) diff --git a/plugins/inputs/cloudwatch/sample.conf b/plugins/inputs/cloudwatch/sample.conf index c5be16452..26d311003 100644 --- a/plugins/inputs/cloudwatch/sample.conf +++ b/plugins/inputs/cloudwatch/sample.conf @@ -67,8 +67,6 @@ ## Metric Statistic Namespaces (required) namespaces = ["AWS/ELB"] - ## Single metric statistic namespace appended to namespaces on startup - # namespace = "AWS/ELB" ## Maximum requests per second. Note that the global default AWS rate limit ## is 50 reqs/sec, so if you define multiple namespaces, these should add up