Skip to content

Commit

Permalink
Fix tests after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
akrantz01 committed Aug 9, 2021
1 parent e7884fe commit e929756
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
27 changes: 11 additions & 16 deletions plugins/inputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,23 @@ func (c *CloudWatch) Init() error {
c.Namespaces = append(c.Namespaces, c.Namespace)
}

err := c.initializeCloudWatch()
if err != nil {
return err
}

// Set config level filter (won't change throughout life of plugin).
c.statFilter, err = filter.NewIncludeExcludeFilter(c.StatisticInclude, c.StatisticExclude)
if err != nil {
return err
}

return nil
}

// Gather takes in an accumulator and adds the metrics that the Input
// gathers. This is called every "interval".
func (c *CloudWatch) Gather(acc telegraf.Accumulator) error {
if c.statFilter == nil {
var err error
// Set config level filter (won't change throughout life of plugin).
c.statFilter, err = filter.NewIncludeExcludeFilter(c.StatisticInclude, c.StatisticExclude)
if err != nil {
return err
}
}

if c.client == nil {
err := c.initializeCloudWatch()
if err != nil {
return err
}
}

filteredMetrics, err := getFilteredMetrics(c)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func TestGather(t *testing.T) {
}

var acc testutil.Accumulator
c.client = &mockGatherCloudWatchClient{}

require.NoError(t, c.Init())
c.client = &mockGatherCloudWatchClient{}
require.NoError(t, acc.GatherError(c.Gather))

fields := map[string]interface{}{}
Expand Down Expand Up @@ -147,8 +147,9 @@ func TestGather_MultipleNamespaces(t *testing.T) {
}

var acc testutil.Accumulator
c.client = &mockGatherCloudWatchClient{}

require.NoError(t, c.Init())
c.client = &mockGatherCloudWatchClient{}
require.NoError(t, acc.GatherError(c.Gather))

require.True(t, acc.HasMeasurement("cloudwatch_aws_elb"))
Expand Down Expand Up @@ -235,8 +236,7 @@ func TestSelectMetrics(t *testing.T) {
},
},
}
err := c.initializeCloudWatch()
require.NoError(t, err)
require.NoError(t, c.Init())
c.client = &mockSelectMetricsCloudWatchClient{}
filtered, err := getFilteredMetrics(c)
// We've asked for 2 (out of 4) metrics, over all 3 load balancers in all 2
Expand Down

0 comments on commit e929756

Please sign in to comment.