From 5eb2a165a94b4980e2d3cfaf484b22c51e2d61c2 Mon Sep 17 00:00:00 2001 From: abhishek-at-cloudwerx Date: Mon, 16 Dec 2024 16:42:39 +0530 Subject: [PATCH] Add metric-specific labels in googlecloudmonitoringreceiver component (#35828) #### Description Add metric-specific labels inside the googlecloudmonitoringreceiver component #### Link to tracking issue https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35711 #### Testing #### Documentation --- ...bels-in-googlecloudmonitoringreceiver.yaml | 27 +++++++++++++++++++ .../googlecloudmonitoringreceiver/receiver.go | 15 ++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 .chloggen/add-metric-labels-in-googlecloudmonitoringreceiver.yaml diff --git a/.chloggen/add-metric-labels-in-googlecloudmonitoringreceiver.yaml b/.chloggen/add-metric-labels-in-googlecloudmonitoringreceiver.yaml new file mode 100644 index 000000000000..6d6f98d22ffa --- /dev/null +++ b/.chloggen/add-metric-labels-in-googlecloudmonitoringreceiver.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: googlecloudmonitoringreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add metric-specific labels to googlecloudmonitoringreceiver component + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [35711] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/googlecloudmonitoringreceiver/receiver.go b/receiver/googlecloudmonitoringreceiver/receiver.go index 25caf4707915..eb5cedea91b6 100644 --- a/receiver/googlecloudmonitoringreceiver/receiver.go +++ b/receiver/googlecloudmonitoringreceiver/receiver.go @@ -271,17 +271,24 @@ func (mr *monitoringReceiver) convertGCPTimeSeriesToMetrics(metrics pmetric.Metr } // Set metadata (user and system labels) - if timeSeries.Metadata != nil { - for k, v := range timeSeries.Metadata.UserLabels { + if timeSeries.GetMetadata() != nil { + for k, v := range timeSeries.GetMetadata().GetUserLabels() { resource.Attributes().PutStr(k, v) } - if timeSeries.Metadata.SystemLabels != nil { - for k, v := range timeSeries.Metadata.SystemLabels.Fields { + if timeSeries.GetMetadata().GetSystemLabels() != nil { + for k, v := range timeSeries.GetMetadata().GetSystemLabels().GetFields() { resource.Attributes().PutStr(k, fmt.Sprintf("%v", v)) } } } + // Add metric-specific labels if they are present + if len(timeSeries.GetMetric().Labels) > 0 { + for k, v := range timeSeries.GetMetric().GetLabels() { + resource.Attributes().PutStr(k, fmt.Sprintf("%v", v)) + } + } + // Store the newly created ResourceMetrics in the map resourceMetricsMap[resourceKey] = rm }