Skip to content

Commit

Permalink
feat(prometheusremotewrite): only append colliding attributes values …
Browse files Browse the repository at this point in the history
…if they are different
  • Loading branch information
avanish-vaghela committed Dec 23, 2024
1 parent 58aaa64 commit 1d4cf32
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/translator/prometheusremotewrite/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, externa
for _, label := range labels {
finalKey := prometheustranslator.NormalizeLabel(label.Name)
if existingValue, alreadyExists := l[finalKey]; alreadyExists {
l[finalKey] = existingValue + ";" + label.Value
// Only append to existing value if the new value is different
if existingValue != label.Value {
l[finalKey] = existingValue + ";" + label.Value
}
} else {
l[finalKey] = label.Value
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/translator/prometheusremotewrite/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ func Test_createLabelSet(t *testing.T) {
[]string{label31, value31, label32, value32},
getPromLabels(collidingSanitized, value11+";"+value12, label31, value31, label32, value32),
},
{
"existing_attribute_value_is_the_same_as_the_new_label_value",
pcommon.NewResource(),
lbsCollidingSameValue,
nil,
[]string{label31, value31, label32, value32},
getPromLabels(collidingSanitized, value11, label31, value31, label32, value32),
},
{
"sanitize_labels_starts_with_underscore",
pcommon.NewResource(),
Expand Down
9 changes: 5 additions & 4 deletions pkg/translator/prometheusremotewrite/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ var (
floatVal1 = 1.0
floatVal2 = 2.0

lbs1 = getAttributes(label11, value11, label12, value12)
lbs3 = getAttributes(label11, value11, label12, value12, label51, value51)
lbs1Dirty = getAttributes(label11+dirty1, value11, dirty2+label12, value12)
lbsColliding = getAttributes(colliding1, value11, colliding2, value12)
lbs1 = getAttributes(label11, value11, label12, value12)
lbs3 = getAttributes(label11, value11, label12, value12, label51, value51)
lbs1Dirty = getAttributes(label11+dirty1, value11, dirty2+label12, value12)
lbsColliding = getAttributes(colliding1, value11, colliding2, value12)
lbsCollidingSameValue = getAttributes(colliding1, value11, colliding2, value11)

exlbs1 = map[string]string{label41: value41}
exlbs2 = map[string]string{label11: value41}
Expand Down

0 comments on commit 1d4cf32

Please sign in to comment.