From 8d48921fe564ee31ca9483021e3b60b723be12ef Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Thu, 14 Nov 2019 13:59:04 -0700 Subject: [PATCH 1/3] Check length of the slice instead of comparing with nil --- x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go index 04ff0fcc6599..7fa9eb2d428a 100644 --- a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go +++ b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go @@ -450,7 +450,7 @@ func (m *MetricSet) createEvents(svcCloudwatch cloudwatchiface.ClientAPI, svcRes m.Logger().Info(errors.Wrap(err, "getResourcesTags failed, skipping region "+regionName)) } - if tagsFilter != nil && resourceTagMap == nil { + if len(tagsFilter) != 0 && resourceTagMap == nil { continue } @@ -472,7 +472,7 @@ func (m *MetricSet) createEvents(svcCloudwatch cloudwatchiface.ClientAPI, svcRes labels := strings.Split(*output.Label, labelSeperator) if len(labels) != 5 { // if there is no tag in labels but there is a tagsFilter, then no event should be reported. - if tagsFilter != nil { + if len(tagsFilter) != 0 { continue } eventNew := aws.InitEvent(regionName, m.AccountName, m.AccountID) @@ -483,7 +483,7 @@ func (m *MetricSet) createEvents(svcCloudwatch cloudwatchiface.ClientAPI, svcRes identifierValue := labels[identifierValueIdx] tags := resourceTagMap[identifierValue] - if tagsFilter != nil && tags == nil { + if len(tagsFilter) != 0 && tags == nil { continue } From 8c75e19c16b23a4c4076cb8f1fe9acc58e36749f Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Thu, 14 Nov 2019 14:03:04 -0700 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 6ad37cf027e3..c1a542be218e 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -251,6 +251,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Update azure configuration example. {issue}14224[14224] - Fix cloudwatch metricset with names and dimensions in config. {issue}14376[14376] {pull}14391[14391] - Fix marshaling of ms-since-epoch values in `elasticsearch/cluster_stats` metricset. {pull}14378[14378] +- Fix checking tagsFilter using length in cloudwatch metricset. {pull}14525[14525] *Packetbeat* From 0801a989412bc9b39e8365503300c685369c5601 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Thu, 14 Nov 2019 21:21:02 -0700 Subject: [PATCH 3/3] Change to check length for tags and resourceTagMap --- x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go index 7fa9eb2d428a..1b7e0ab4393a 100644 --- a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go +++ b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go @@ -450,7 +450,7 @@ func (m *MetricSet) createEvents(svcCloudwatch cloudwatchiface.ClientAPI, svcRes m.Logger().Info(errors.Wrap(err, "getResourcesTags failed, skipping region "+regionName)) } - if len(tagsFilter) != 0 && resourceTagMap == nil { + if len(tagsFilter) != 0 && len(resourceTagMap) == 0 { continue } @@ -483,7 +483,7 @@ func (m *MetricSet) createEvents(svcCloudwatch cloudwatchiface.ClientAPI, svcRes identifierValue := labels[identifierValueIdx] tags := resourceTagMap[identifierValue] - if len(tagsFilter) != 0 && tags == nil { + if len(tagsFilter) != 0 && len(tags) == 0 { continue }