From e4037b3ec3654ad9016105e3da80f034a1ad2f5a Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Wed, 5 Feb 2025 22:24:13 +1100 Subject: [PATCH 1/2] Allow UTF-8 labels in label_replace This makes it consistent with label_join. Signed-off-by: Joshua Hesketh --- promql/functions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/promql/functions.go b/promql/functions.go index 938eefdf00..c2f292c3a6 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -1612,7 +1612,7 @@ func (ev *evaluator) evalLabelReplace(ctx context.Context, args parser.Expressio if err != nil { panic(fmt.Errorf("invalid regular expression in label_replace(): %s", regexStr)) } - if !model.LabelNameRE.MatchString(dst) { + if !model.LabelName(dst).IsValid() { panic(fmt.Errorf("invalid destination label name in label_replace(): %s", dst)) } From 5be31977016eb780da53c419c97b53cb52232338 Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Wed, 5 Feb 2025 23:08:24 +1100 Subject: [PATCH 2/2] Update the test to invalid utf-8 "invalid-label-name" is valid in utf-8 mode Signed-off-by: Joshua Hesketh --- promql/promqltest/testdata/functions.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/promql/promqltest/testdata/functions.test b/promql/promqltest/testdata/functions.test index 32838afe73..b0241d7ed9 100644 --- a/promql/promqltest/testdata/functions.test +++ b/promql/promqltest/testdata/functions.test @@ -466,7 +466,7 @@ eval instant at 0m label_replace(testmetric, "dst", "", "dst", ".*") eval_fail instant at 0m label_replace(testmetric, "dst", "value-$1", "src", "(.*") # label_replace fails when the destination label name is not a valid Prometheus label name. -eval_fail instant at 0m label_replace(testmetric, "invalid-label-name", "", "src", "(.*)") +eval_fail instant at 0m label_replace(testmetric, "\xff", "", "src", "(.*)") # label_replace fails when there would be duplicated identical output label sets. eval_fail instant at 0m label_replace(testmetric, "src", "", "", "")