From 5a5fdea7ad9307fae83e1289e2f396d6f75d0f79 Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Thu, 6 Feb 2025 02:40:23 +1100 Subject: [PATCH] Fix duplicate output vector if delayed name removal is disabled (#15975) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --------- Signed-off-by: Joshua Hesketh Signed-off-by: Björn Rabenstein Co-authored-by: Björn Rabenstein --- promql/functions.go | 3 +++ promql/promqltest/testdata/functions.test | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/promql/functions.go b/promql/functions.go index 938eefdf00..d8b22ddd40 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -1689,6 +1689,9 @@ func (ev *evaluator) evalLabelJoin(ctx context.Context, args parser.Expressions) matrix[i].DropName = el.DropName } } + if matrix.ContainsSameLabelset() { + ev.errorf("vector cannot contain metrics with the same labelset") + } return matrix, ws } diff --git a/promql/promqltest/testdata/functions.test b/promql/promqltest/testdata/functions.test index 32838afe73..68cf5a09b4 100644 --- a/promql/promqltest/testdata/functions.test +++ b/promql/promqltest/testdata/functions.test @@ -499,6 +499,8 @@ eval instant at 20s timestamp(metric) load 5m testmetric{src="a",src1="b",src2="c",dst="original-destination-value"} 0 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. 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="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 # Tests for vector.