From dfae91cca21c9cbd3db1d302b1a5896115a187ca Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Fri, 3 Apr 2020 08:02:40 -0600 Subject: [PATCH] [Metricbeat AWS] check if cpuOptions is nil in DescribeInstances output (#17418) (#17458) * check if cpuOptions is nil (cherry picked from commit 8d431691401478bc8d6ed3c80e64b6092e2a332a) --- CHANGELOG.next.asciidoc | 1 + x-pack/metricbeat/module/aws/ec2/ec2.go | 27 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 0156f12ff416..11abca0b4d9a 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -180,6 +180,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix missing Accept header for Prometheus and OpenMetrics module. {issue}16870[16870] {pull}17291[17291] - Further revise check for bad data in docker/memory. {pull}17400[17400] - Combine cloudwatch aggregated metrics into single event. {pull}17345[17345] +- check if cpuOptions field is nil in DescribeInstances output in ec2 metricset. {pull}17418[17418] *Packetbeat* diff --git a/x-pack/metricbeat/module/aws/ec2/ec2.go b/x-pack/metricbeat/module/aws/ec2/ec2.go index 50030477412f..9e9c94678290 100644 --- a/x-pack/metricbeat/module/aws/ec2/ec2.go +++ b/x-pack/metricbeat/module/aws/ec2/ec2.go @@ -209,7 +209,11 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met events[instanceID].RootFields.Put("cloud.instance.id", instanceID) events[instanceID].RootFields.Put("cloud.machine.type", machineType) - events[instanceID].RootFields.Put("cloud.availability_zone", *instanceOutput[instanceID].Placement.AvailabilityZone) + + placement := instanceOutput[instanceID].Placement + if placement != nil { + events[instanceID].RootFields.Put("cloud.availability_zone", *placement.AvailabilityZone) + } if len(output.Values) > timestampIdx { metricSetFieldResults[instanceID][labels[metricNameIdx]] = fmt.Sprint(output.Values[timestampIdx]) @@ -227,23 +231,28 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met monitoringStates[instanceID] = monitoringState - events[instanceID].MetricSetFields.Put("instance.image.id", *instanceOutput[instanceID].ImageId) - events[instanceID].MetricSetFields.Put("instance.state.name", instanceStateName) - events[instanceID].MetricSetFields.Put("instance.state.code", *instanceOutput[instanceID].State.Code) - events[instanceID].MetricSetFields.Put("instance.monitoring.state", monitoringState) - events[instanceID].MetricSetFields.Put("instance.core.count", *instanceOutput[instanceID].CpuOptions.CoreCount) - events[instanceID].MetricSetFields.Put("instance.threads_per_core", *instanceOutput[instanceID].CpuOptions.ThreadsPerCore) + cpuOptions := instanceOutput[instanceID].CpuOptions + if cpuOptions != nil { + events[instanceID].MetricSetFields.Put("instance.core.count", *cpuOptions.CoreCount) + events[instanceID].MetricSetFields.Put("instance.threads_per_core", *cpuOptions.ThreadsPerCore) + } + publicIP := instanceOutput[instanceID].PublicIpAddress if publicIP != nil { events[instanceID].MetricSetFields.Put("instance.public.ip", *publicIP) } - events[instanceID].MetricSetFields.Put("instance.public.dns_name", *instanceOutput[instanceID].PublicDnsName) - events[instanceID].MetricSetFields.Put("instance.private.dns_name", *instanceOutput[instanceID].PrivateDnsName) privateIP := instanceOutput[instanceID].PrivateIpAddress if privateIP != nil { events[instanceID].MetricSetFields.Put("instance.private.ip", *privateIP) } + + events[instanceID].MetricSetFields.Put("instance.image.id", *instanceOutput[instanceID].ImageId) + events[instanceID].MetricSetFields.Put("instance.state.name", instanceStateName) + events[instanceID].MetricSetFields.Put("instance.state.code", *instanceOutput[instanceID].State.Code) + events[instanceID].MetricSetFields.Put("instance.monitoring.state", monitoringState) + events[instanceID].MetricSetFields.Put("instance.public.dns_name", *instanceOutput[instanceID].PublicDnsName) + events[instanceID].MetricSetFields.Put("instance.private.dns_name", *instanceOutput[instanceID].PrivateDnsName) } } }