From 4301c0a260aa7c01189c5d7a9fd0c2f4f5049fd1 Mon Sep 17 00:00:00 2001 From: Linu-Elias Date: Wed, 17 Jul 2024 19:20:35 +0530 Subject: [PATCH] x-pack/metricbeat/module/gcp: Add omitted labels (#40062) * gcp ommitted label fix * added comments * resolved comments * CHANGELOG.next.asciidoc --- CHANGELOG.next.asciidoc | 1 + .../module/gcp/timeseries_metadata_collector.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index f486f49553fc..cf93df233b71 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -179,6 +179,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Fix behavior of pagetypeinfo metrics {pull}39985[39985] - Fix query logic for temp and non-temp tablespaces in Oracle module. {issue}38051[38051] {pull}39787[39787] - Set GCP metrics config period to the default (60s) when the value is below the minimum allowed period. {issue}30434[30434] {pull}40020[40020] +- Add GCP 'instance_id' resource label in ECS cloud fields. {issue}40033[40033] {pull}40062[40062] - Fix missing metrics from CloudWatch when include_linked_accounts set to false. {issue}40071[40071] {pull}40135[40135] - Update beat module with apm-server monitoring metrics fields {pull}40127[40127] diff --git a/x-pack/metricbeat/module/gcp/timeseries_metadata_collector.go b/x-pack/metricbeat/module/gcp/timeseries_metadata_collector.go index 01dad3c22cbe..028f3d713e6a 100644 --- a/x-pack/metricbeat/module/gcp/timeseries_metadata_collector.go +++ b/x-pack/metricbeat/module/gcp/timeseries_metadata_collector.go @@ -100,7 +100,15 @@ func (s *StackdriverTimeSeriesMetadataCollector) Metadata(ctx context.Context, i // common.Mapstr seems to not work as expected when deleting keys so I have to iterate over all results to add // the ones I want for k, v := range s.timeSeries.Resource.Labels { - if k == TimeSeriesResponsePathForECSAvailabilityZone || k == TimeSeriesResponsePathForECSInstanceID || k == TimeSeriesResponsePathForECSAccountID { + + // We are omitting some labels here because they are added separately for services with additional metadata logic. + // However, we explicitly include the instance_id label to ensure it is not missed for services without additional metadata logic. + if k == TimeSeriesResponsePathForECSInstanceID { + _, _ = ecs.Put(ECSCloudInstanceIDKey, v) + continue + } + + if k == TimeSeriesResponsePathForECSAvailabilityZone || k == TimeSeriesResponsePathForECSAccountID { continue }