From 896bdb0c13e34858ce3c768d1fe2bb95fd3f411e Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Wed, 29 Jan 2020 06:18:52 -0700 Subject: [PATCH] [Metricbeat] Add dedot for cloudwatch metric name (#15917) (#15918) * Add dedot for cloudwatch metric name * update changelog (cherry picked from commit 5193ce98ff2208659b1d2e7a40861a2391a69e6c) --- CHANGELOG.next.asciidoc | 1 + x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go | 3 ++- x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 7a941d9f9bd..c4cd32c4378 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -113,6 +113,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix CPU count in docker/cpu in cases where no `online_cpus` are reported {pull}15070[15070] - Add dedot for tags in ec2 metricset and cloudwatch metricset. {issue}15843[15843] {pull}15844[15844] - Use RFC3339 format for timestamps collected using the SQL module. {pull}15847[15847] +- Add dedot for cloudwatch metric name. {issue}15916[15916] {pull}15917[15917] *Packetbeat* diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go index 31b3bfc1a3e..40be8a846cd 100644 --- a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go +++ b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch.go @@ -391,7 +391,8 @@ func generateFieldName(namespace string, labels []string) string { // Check if statistic method is one of Sum, SampleCount, Minimum, Maximum, Average // With checkStatistics function, no need to check bool return value here statMethod, _ := statisticLookup(stat) - return "aws." + stripNamespace(namespace) + ".metrics." + labels[metricNameIdx] + "." + statMethod + // By default, replace dot "." using under bar "_" for metric names + return "aws." + stripNamespace(namespace) + ".metrics." + common.DeDot(labels[metricNameIdx]) + "." + statMethod } // stripNamespace converts Cloudwatch namespace into the root field we will use for metrics diff --git a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go index e13d1e7dce9..9ce957adc7b 100644 --- a/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go +++ b/x-pack/metricbeat/module/aws/cloudwatch/cloudwatch_test.go @@ -699,6 +699,12 @@ func TestGenerateFieldName(t *testing.T) { []string{"CPUUtilization", "AWS/EC2", "p10", "InstanceId", "i-1"}, "aws.ec2.metrics.CPUUtilization.p10", }, + { + "test metric name with dot", + "cloudwatch", + []string{"DeliveryToS3.Records", "AWS/Firehose", "Average", "DeliveryStreamName", "test-1"}, + "aws.firehose.metrics.DeliveryToS3_Records.avg", + }, } for _, c := range cases {