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] Ignore empty events when reporting from cloudwatch metricset #13458

Merged
merged 3 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,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 panic in Redis Key metricset when collecting information from a removed key. {pull}13426[13426]
- Fix module-level fields in Kubernetes metricsets. {pull}13433[13433]
- 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
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
#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