fix(inputs.cloudwatch): Fix multiple namespaces issue (#12177)
This commit is contained in:
parent
f2b49ce39c
commit
74454109b9
|
|
@ -96,8 +96,6 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
|
|
||||||
## Metric Statistic Namespaces (required)
|
## Metric Statistic Namespaces (required)
|
||||||
namespaces = ["AWS/ELB"]
|
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
|
## 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
|
## 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"
|
# value = "p-example"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Please note, the `namespace` option is deprecated in favor of the `namespaces`
|
||||||
|
list option.
|
||||||
|
|
||||||
## Requirements and Terminology
|
## Requirements and Terminology
|
||||||
|
|
||||||
Plugin Configuration utilizes [CloudWatch concepts][concept] and access pattern to
|
Plugin Configuration utilizes [CloudWatch concepts][concept] and access
|
||||||
allow monitoring of any CloudWatch Metric.
|
pattern to allow monitoring of any CloudWatch Metric.
|
||||||
|
|
||||||
- `region` must be a valid AWS [region][] value
|
- `region` must be a valid AWS [region][] value
|
||||||
- `period` must be a valid CloudWatch [period][] 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
|
- `names` must be valid CloudWatch [metric][] names
|
||||||
- `dimensions` must be valid CloudWatch [dimension][] name/value pairs
|
- `dimensions` must be valid CloudWatch [dimension][] name/value pairs
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ type CloudWatch struct {
|
||||||
|
|
||||||
Period config.Duration `toml:"period"`
|
Period config.Duration `toml:"period"`
|
||||||
Delay config.Duration `toml:"delay"`
|
Delay config.Duration `toml:"delay"`
|
||||||
Namespace string `toml:"namespace"`
|
Namespace string `toml:"namespace" deprecated:"1.25.0;use 'namespaces' instead"`
|
||||||
Namespaces []string `toml:"namespaces"`
|
Namespaces []string `toml:"namespaces"`
|
||||||
Metrics []*Metric `toml:"metrics"`
|
Metrics []*Metric `toml:"metrics"`
|
||||||
CacheTTL config.Duration `toml:"cache_ttl"`
|
CacheTTL config.Duration `toml:"cache_ttl"`
|
||||||
|
|
@ -320,19 +320,15 @@ func getFilteredMetrics(c *CloudWatch) ([]filteredMetric, error) {
|
||||||
func (c *CloudWatch) fetchNamespaceMetrics() ([]types.Metric, error) {
|
func (c *CloudWatch) fetchNamespaceMetrics() ([]types.Metric, error) {
|
||||||
metrics := []types.Metric{}
|
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 {
|
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 {
|
for {
|
||||||
resp, err := c.client.ListMetrics(context.Background(), params)
|
resp, err := c.client.ListMetrics(context.Background(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -340,12 +336,11 @@ func (c *CloudWatch) fetchNamespaceMetrics() ([]types.Metric, error) {
|
||||||
// skip problem namespace on error and continue to next namespace
|
// skip problem namespace on error and continue to next namespace
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics = append(metrics, resp.Metrics...)
|
metrics = append(metrics, resp.Metrics...)
|
||||||
|
|
||||||
if resp.NextToken == nil {
|
if resp.NextToken == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
params.NextToken = resp.NextToken
|
params.NextToken = resp.NextToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ func TestGather(t *testing.T) {
|
||||||
Period: internalDuration,
|
Period: internalDuration,
|
||||||
RateLimit: 200,
|
RateLimit: 200,
|
||||||
BatchSize: 500,
|
BatchSize: 500,
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -139,6 +140,7 @@ func TestGather_MultipleNamespaces(t *testing.T) {
|
||||||
Period: internalDuration,
|
Period: internalDuration,
|
||||||
RateLimit: 200,
|
RateLimit: 200,
|
||||||
BatchSize: 500,
|
BatchSize: 500,
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -231,6 +233,7 @@ func TestSelectMetrics(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
c.client = &mockSelectMetricsCloudWatchClient{}
|
c.client = &mockSelectMetricsCloudWatchClient{}
|
||||||
|
|
@ -262,6 +265,7 @@ func TestGenerateStatisticsInputParams(t *testing.T) {
|
||||||
Delay: internalDuration,
|
Delay: internalDuration,
|
||||||
Period: internalDuration,
|
Period: internalDuration,
|
||||||
BatchSize: 500,
|
BatchSize: 500,
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, c.initializeCloudWatch())
|
require.NoError(t, c.initializeCloudWatch())
|
||||||
|
|
@ -302,6 +306,7 @@ func TestGenerateStatisticsInputParamsFiltered(t *testing.T) {
|
||||||
Delay: internalDuration,
|
Delay: internalDuration,
|
||||||
Period: internalDuration,
|
Period: internalDuration,
|
||||||
BatchSize: 500,
|
BatchSize: 500,
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, c.initializeCloudWatch())
|
require.NoError(t, c.initializeCloudWatch())
|
||||||
|
|
@ -342,6 +347,7 @@ func TestUpdateWindow(t *testing.T) {
|
||||||
Delay: internalDuration,
|
Delay: internalDuration,
|
||||||
Period: internalDuration,
|
Period: internalDuration,
|
||||||
BatchSize: 500,
|
BatchSize: 500,
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
@ -371,6 +377,7 @@ func TestProxyFunction(t *testing.T) {
|
||||||
HTTPProxyURL: "http://www.penguins.com",
|
HTTPProxyURL: "http://www.penguins.com",
|
||||||
},
|
},
|
||||||
BatchSize: 500,
|
BatchSize: 500,
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyFunction, err := c.HTTPProxy.Proxy()
|
proxyFunction, err := c.HTTPProxy.Proxy()
|
||||||
|
|
@ -389,6 +396,7 @@ func TestCombineNamespaces(t *testing.T) {
|
||||||
Namespace: "AWS/ELB",
|
Namespace: "AWS/ELB",
|
||||||
Namespaces: []string{"AWS/EC2", "AWS/Billing"},
|
Namespaces: []string{"AWS/EC2", "AWS/Billing"},
|
||||||
BatchSize: 500,
|
BatchSize: 500,
|
||||||
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,6 @@
|
||||||
|
|
||||||
## Metric Statistic Namespaces (required)
|
## Metric Statistic Namespaces (required)
|
||||||
namespaces = ["AWS/ELB"]
|
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
|
## 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
|
## is 50 reqs/sec, so if you define multiple namespaces, these should add up
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue