From c003f9b2deedbfc0040fb40cae31d22c681ed9b5 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Sat, 16 Nov 2019 11:20:48 -0700 Subject: [PATCH] Cherry-pick #14525 to 7.x: [Metricbeat] Check length of the slice instead of comparing with nil in cloudwatch (#14539) * [Metricbeat] Check length of the slice instead of comparing with nil in cloudwatch (#14525) * Check length of the slice instead of comparing with nil (cherry picked from commit 8dce4b1e3a75af715b76c84523fa949746853176) * Update changelog --- CHANGELOG.next.asciidoc | 1 + x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index d2d7d935d17..d318cae0d48 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -249,6 +249,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* diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go index 04ff0fcc659..1b7e0ab4393 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 && len(resourceTagMap) == 0 { 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 && len(tags) == 0 { continue }