Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metricbeat] Rename tags to tags_filter for cloudwatch metricset #16733

Merged
merged 9 commits into from
May 20, 2020
Prev Previous commit
Next Next commit
check config.Tags or config.TagsFilter once at the beginning of the f…
…or loop
  • Loading branch information
kaiyan-sheng committed Mar 3, 2020
commit b0203fd22a149bcf6f90cf2cb3e18c39a4e20d39
24 changes: 9 additions & 15 deletions x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pkg/errors"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/cfgwarn"
"github.com/elastic/beats/v7/metricbeat/mb"
awscommon "github.com/elastic/beats/v7/x-pack/libbeat/common/aws"
"github.com/elastic/beats/v7/x-pack/metricbeat/module/aws"
Expand Down Expand Up @@ -283,6 +284,11 @@ func (m *MetricSet) readCloudwatchConfig() (listMetricWithDetail, map[string][]n
resourceTypesWithTags := map[string][]aws.Tag{}

for _, config := range m.CloudwatchConfigs {
tagsFilter := config.Tags
if config.TagsFilter != nil {
tagsFilter = config.TagsFilter
}

// If there is no statistic method specified, then use the default.
if config.Statistic == nil {
config.Statistic = defaultStatistics
Expand Down Expand Up @@ -314,33 +320,21 @@ func (m *MetricSet) readCloudwatchConfig() (listMetricWithDetail, map[string][]n

if config.ResourceTypeFilter != "" {
if _, ok := resourceTypesWithTags[config.ResourceTypeFilter]; ok {
if config.TagsFilter != nil {
resourceTypesWithTags[config.ResourceTypeFilter] = config.TagsFilter
} else {
resourceTypesWithTags[config.ResourceTypeFilter] = config.Tags
}
resourceTypesWithTags[config.ResourceTypeFilter] = tagsFilter
} else {
if config.TagsFilter != nil {
resourceTypesWithTags[config.ResourceTypeFilter] = append(resourceTypesWithTags[config.ResourceTypeFilter], config.TagsFilter...)
} else {
resourceTypesWithTags[config.ResourceTypeFilter] = append(resourceTypesWithTags[config.ResourceTypeFilter], config.Tags...)
}
resourceTypesWithTags[config.ResourceTypeFilter] = append(resourceTypesWithTags[config.ResourceTypeFilter], tagsFilter...)
}
}
continue
}

configPerNamespace := namespaceDetail{
names: config.MetricName,
tags: tagsFilter,
statistics: config.Statistic,
resourceTypeFilter: config.ResourceTypeFilter,
dimensions: cloudwatchDimensions,
}
if config.TagsFilter != nil {
configPerNamespace.tags = config.TagsFilter
} else {
configPerNamespace.tags = config.Tags
}

if _, ok := namespaceDetailTotal[config.Namespace]; ok {
namespaceDetailTotal[config.Namespace] = append(namespaceDetailTotal[config.Namespace], configPerNamespace)
Expand Down