diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index b8ad862124cc..c2547091ee4e 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -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 } diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index 631ff7c831b1..c27c1fde2b31 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -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(), diff --git a/pkg/translator/prometheusremotewrite/testutils_test.go b/pkg/translator/prometheusremotewrite/testutils_test.go index 42a8dc48f9e7..16f78a1177ae 100644 --- a/pkg/translator/prometheusremotewrite/testutils_test.go +++ b/pkg/translator/prometheusremotewrite/testutils_test.go @@ -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}