Skip to content

Commit 8a7a719

Browse files
[exporter/prometheusremotewrite] only append colliding attributes values if they are different (#36928)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description While translating two OTel attributes into Prometheus Labels, if both attributes results in the same Prometheus label and both have the same value, they won't be appended. **Example:** - "bar.one": "foo" - "bar/one": "foo" The above two attributes when translated to Prometheus label would become - Before the PR - "bar_one": "foo;foo" - After the PR: - "bar_one": "foo" <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #35896 <!--Describe what testing was performed and which tests were added.--> #### Testing - Unit test added <!--Describe the documentation added.--> #### Documentation - Change log entry added <!--Please delete paragraphs that you did not use before submitting.-->
1 parent d6c4bc6 commit 8a7a719

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: prometheusremotewriteexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Only append label values if they are different for colliding OTel attributes"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35896]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
This change ensures that, when translating colliding attributes from OTel attributes to Prometheus label, the label values are only appended if their values are different.
20+
This is a breaking change as it changes the value of label outputted.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [user]

pkg/translator/prometheusremotewrite/helper.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, externa
141141
for _, label := range labels {
142142
finalKey := prometheustranslator.NormalizeLabel(label.Name)
143143
if existingValue, alreadyExists := l[finalKey]; alreadyExists {
144-
l[finalKey] = existingValue + ";" + label.Value
144+
// Only append to existing value if the new value is different
145+
if existingValue != label.Value {
146+
l[finalKey] = existingValue + ";" + label.Value
147+
}
145148
} else {
146149
l[finalKey] = label.Value
147150
}

pkg/translator/prometheusremotewrite/helper_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ func Test_createLabelSet(t *testing.T) {
349349
[]string{label31, value31, label32, value32},
350350
getPromLabels(collidingSanitized, value11+";"+value12, label31, value31, label32, value32),
351351
},
352+
{
353+
"existing_attribute_value_is_the_same_as_the_new_label_value",
354+
pcommon.NewResource(),
355+
lbsCollidingSameValue,
356+
nil,
357+
[]string{label31, value31, label32, value32},
358+
getPromLabels(collidingSanitized, value11, label31, value31, label32, value32),
359+
},
352360
{
353361
"sanitize_labels_starts_with_underscore",
354362
pcommon.NewResource(),

pkg/translator/prometheusremotewrite/testutils_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ var (
5858
floatVal1 = 1.0
5959
floatVal2 = 2.0
6060

61-
lbs1 = getAttributes(label11, value11, label12, value12)
62-
lbs3 = getAttributes(label11, value11, label12, value12, label51, value51)
63-
lbs1Dirty = getAttributes(label11+dirty1, value11, dirty2+label12, value12)
64-
lbsColliding = getAttributes(colliding1, value11, colliding2, value12)
61+
lbs1 = getAttributes(label11, value11, label12, value12)
62+
lbs3 = getAttributes(label11, value11, label12, value12, label51, value51)
63+
lbs1Dirty = getAttributes(label11+dirty1, value11, dirty2+label12, value12)
64+
lbsColliding = getAttributes(colliding1, value11, colliding2, value12)
65+
lbsCollidingSameValue = getAttributes(colliding1, value11, colliding2, value11)
6566

6667
exlbs1 = map[string]string{label41: value41}
6768
exlbs2 = map[string]string{label11: value41}

0 commit comments

Comments
 (0)