Fix duplicate output vector if delayed name removal is disabled (#15975)

Fix duplicate output vector if delayed name removal is disabled

This error is emitted in cleanupMetricLabels, but is skipped if
enableDelayedNameRemoval is false.

This makes it consistent with label_replace

Signed-off-by: Joshua Hesketh <josh@nitrotech.org>

---------

Signed-off-by: Joshua Hesketh <josh@nitrotech.org>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
This commit is contained in:
Joshua Hesketh 2025-02-06 02:40:23 +11:00 committed by GitHub
parent c9320da61e
commit 5a5fdea7ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View file

@ -1689,6 +1689,9 @@ func (ev *evaluator) evalLabelJoin(ctx context.Context, args parser.Expressions)
matrix[i].DropName = el.DropName matrix[i].DropName = el.DropName
} }
} }
if matrix.ContainsSameLabelset() {
ev.errorf("vector cannot contain metrics with the same labelset")
}
return matrix, ws return matrix, ws
} }

View file

@ -499,6 +499,8 @@ eval instant at 20s timestamp(metric)
load 5m load 5m
testmetric{src="a",src1="b",src2="c",dst="original-destination-value"} 0 testmetric{src="a",src1="b",src2="c",dst="original-destination-value"} 0
testmetric{src="d",src1="e",src2="f",dst="original-destination-value"} 1 testmetric{src="d",src1="e",src2="f",dst="original-destination-value"} 1
dup{label="a", this="a"} 1.0
dup{label="b", this="a"} 1.0
# label_join joins all src values in order. # label_join joins all src values in order.
eval instant at 0m label_join(testmetric, "dst", "-", "src", "src1", "src2") eval instant at 0m label_join(testmetric, "dst", "-", "src", "src1", "src2")
@ -530,6 +532,9 @@ eval instant at 0m label_join(testmetric1, "dst", ", ", "src", "src1", "src2")
testmetric1{src="foo",src1="bar",src2="foobar",dst="foo, bar, foobar"} 0 testmetric1{src="foo",src1="bar",src2="foobar",dst="foo, bar, foobar"} 0
testmetric1{src="fizz",src1="buzz",src2="fizzbuzz",dst="fizz, buzz, fizzbuzz"} 1 testmetric1{src="fizz",src1="buzz",src2="fizzbuzz",dst="fizz, buzz, fizzbuzz"} 1
eval_fail instant at 0m label_join(dup, "label", "", "this")
expected_fail_message vector cannot contain metrics with the same labelset
clear clear
# Tests for vector. # Tests for vector.