Skip to content

Commit

Permalink
Add metric-specific labels in googlecloudmonitoringreceiver component (
Browse files Browse the repository at this point in the history
…#35828)

#### Description
Add metric-specific labels inside the googlecloudmonitoringreceiver
component

#### Link to tracking issue

#35711

#### Testing

#### Documentation
  • Loading branch information
abhishek-at-cloudwerx authored Dec 16, 2024
1 parent a2f3b3c commit 5eb2a16
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/add-metric-labels-in-googlecloudmonitoringreceiver.yaml
Original file line number Diff line number Diff line change
@@ -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: []
15 changes: 11 additions & 4 deletions receiver/googlecloudmonitoringreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5eb2a16

Please sign in to comment.