Skip to content

Commit

Permalink
fix: pagination error on cloudwatch plugin (#9693)
Browse files Browse the repository at this point in the history
(cherry picked from commit 646273a)
  • Loading branch information
Doron-Bargo authored and reimda committed Sep 17, 2021
1 parent 3f5867c commit b80f73b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions plugins/inputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,21 @@ func (c *CloudWatch) fetchNamespaceMetrics() ([]*cwClient.Metric, error) {
default:
recentlyActive = nil
}
params = &cwClient.ListMetricsInput{
Dimensions: []*cwClient.DimensionFilter{},
NextToken: token,
MetricName: nil,
RecentlyActive: recentlyActive,
}

for _, namespace := range c.Namespaces {
params.Namespace = aws.String(namespace)

params = &cwClient.ListMetricsInput{
Dimensions: []*cwClient.DimensionFilter{},
NextToken: token,
MetricName: nil,
RecentlyActive: recentlyActive,
Namespace: aws.String(namespace),
}

for {
resp, err := c.client.ListMetrics(params)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to list metrics with params per namespace: %v", err)
}

metrics = append(metrics, resp.Metrics...)
Expand All @@ -432,7 +435,6 @@ func (c *CloudWatch) fetchNamespaceMetrics() ([]*cwClient.Metric, error) {
params.NextToken = resp.NextToken
}
}

return metrics, nil
}

Expand Down

0 comments on commit b80f73b

Please sign in to comment.