From c4ed50ae54dcad45972209d4a0279c9f659ecef0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 18 May 2021 00:22:30 +0300 Subject: [PATCH] lib/promrelabel: add tests for conditional removal of label on another label match Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1294 --- lib/promrelabel/relabel_test.go | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/promrelabel/relabel_test.go b/lib/promrelabel/relabel_test.go index 58c51c81e4..742219921c 100644 --- a/lib/promrelabel/relabel_test.go +++ b/lib/promrelabel/relabel_test.go @@ -171,6 +171,56 @@ func TestApplyRelabelConfigs(t *testing.T) { }, }) }) + t.Run("replace-hit-remove-label", func(t *testing.T) { + f(` +- action: replace + source_labels: ["xxx", "foo"] + regex: "yyy;.+" + target_label: "foo" + replacement: "" +`, []prompbmarshal.Label{ + { + Name: "xxx", + Value: "yyy", + }, + { + Name: "foo", + Value: "bar", + }, + }, false, []prompbmarshal.Label{ + { + Name: "xxx", + Value: "yyy", + }, + }) + }) + t.Run("replace-miss-remove-label", func(t *testing.T) { + f(` +- action: replace + source_labels: ["xxx", "foo"] + regex: "yyy;.+" + target_label: "foo" + replacement: "" +`, []prompbmarshal.Label{ + { + Name: "xxx", + Value: "yyyz", + }, + { + Name: "foo", + Value: "bar", + }, + }, false, []prompbmarshal.Label{ + { + Name: "foo", + Value: "bar", + }, + { + Name: "xxx", + Value: "yyyz", + }, + }) + }) t.Run("replace-hit-target-label-with-capture-group", func(t *testing.T) { f(` - action: replace