Skip to content

Commit

Permalink
[Metricbeat] Ignore empty events when reporting from cloudwatch metri…
Browse files Browse the repository at this point in the history
…cset (#13458) (#13477)
  • Loading branch information
kaiyan-sheng authored Sep 4, 2019
1 parent da6b9f2 commit 370bce6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix issue with aws cloudwatch module where dimensions and/or namespaces that contain space are not being parsed correctly {pull}13389[13389]
- Fix module-level fields in Kubernetes metricsets. {pull}13433[13433]
- Fix panic in Redis Key metricset when collecting information from a removed key. {pull}13426[13426]
- Fix reporting empty events in cloudwatch metricset. {pull}13458[13458]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion x-pack/metricbeat/module/aws/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
metrics:
- namespace: AWS/EC2
name: ["CPUUtilization", "DiskWriteOps"]
tags.resource_type_filter: ec2:intance
tags.resource_type_filter: ec2:instance
#dimensions:
# - name: InstanceId
# value: i-0686946e22cf9494a
Expand Down
46 changes: 6 additions & 40 deletions x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,39 +323,6 @@ func constructLabel(metric cloudwatch.Metric, statistic string) string {
return label
}

func getIdentifiers(metricsWithStatsTotal []metricsWithStatistics) map[string][]string {
if len(metricsWithStatsTotal) == 0 {
return nil
}

identifiers := map[string][]string{}
for _, metricsWithStats := range metricsWithStatsTotal {
identifierName := ""
identifierValue := ""
if len(metricsWithStats.cloudwatchMetric.Dimensions) == 0 {
continue
}

for i, dim := range metricsWithStats.cloudwatchMetric.Dimensions {
identifierName += *dim.Name
identifierValue += *dim.Value
if i != len(metricsWithStats.cloudwatchMetric.Dimensions)-1 {
identifierName += ","
identifierValue += ","
}
}

if identifiers[identifierName] != nil {
if !aws.StringInSlice(identifierValue, identifiers[identifierName]) {
identifiers[identifierName] = append(identifiers[identifierName], identifierValue)
}
} else {
identifiers[identifierName] = []string{identifierValue}
}
}
return identifiers
}

func statisticLookup(stat string) (string, bool) {
statisticLookupTable := map[string]string{
"Average": "avg",
Expand Down Expand Up @@ -405,14 +372,9 @@ func (m *MetricSet) createEvents(svcCloudwatch cloudwatchiface.ClientAPI, svcRes
m.Logger().Info(errors.Wrap(err, "getResourcesTags failed, skipping region "+regionName))
}

identifiers := getIdentifiers(listMetricWithStatsTotal)
// Initialize events map per region, which stores one event per identifierValue
// Initialize events for each identifier.
events := map[string]mb.Event{}
for _, values := range identifiers {
for _, v := range values {
events[v] = aws.InitEvent(regionName)
}
}

// Initialize events for the ones without identifiers.
var eventsNoIdentifier []mb.Event

Expand Down Expand Up @@ -441,6 +403,10 @@ func (m *MetricSet) createEvents(svcCloudwatch cloudwatchiface.ClientAPI, svcRes
labels := strings.Split(*output.Label, labelSeperator)
if len(labels) == 5 {
identifierValue := labels[identifierValueIdx]
if _, ok := events[identifierValue]; !ok {
events[identifierValue] = aws.InitEvent(regionName)
}

events[identifierValue] = insertRootFields(events[identifierValue], output.Values[timestampIdx], labels)
tags := resourceTagMap[identifierValue]
for _, tag := range tags {
Expand Down
6 changes: 0 additions & 6 deletions x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@ var (
}
)

func TestGetIdentifiers(t *testing.T) {
listMetricDetailTotal := []metricsWithStatistics{metricsWithStat1, metricsWithStat2, metricsWithStat3, metricsWithStat4}
identifiers := getIdentifiers(listMetricDetailTotal)
assert.Equal(t, []string{instanceID1, instanceID2}, identifiers["InstanceId"])
}

func TestConstructLabel(t *testing.T) {
cases := []struct {
listMetricDetail cloudwatch.Metric
Expand Down
2 changes: 1 addition & 1 deletion x-pack/metricbeat/modules.d/aws.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
metrics:
- namespace: AWS/EC2
name: ["CPUUtilization", "DiskWriteOps"]
tags.resource_type_filter: ec2:intance
tags.resource_type_filter: ec2:instance
#dimensions:
# - name: InstanceId
# value: i-0686946e22cf9494a
Expand Down

0 comments on commit 370bce6

Please sign in to comment.