lib/promrelabel: add tests for conditional removal of label on another label match

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1294
This commit is contained in:
Aliaksandr Valialkin 2021-05-18 00:22:30 +03:00
parent 8764b0ae21
commit c4ed50ae54

View File

@ -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