fix(inputs.cloudwatch): Fix multiple namespaces issue (#12177)

This commit is contained in:
Sven Rebhan 2022-11-07 15:43:20 +01:00 committed by GitHub
parent f2b49ce39c
commit 74454109b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 22 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -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())

View File

@ -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