mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
relabel: blank replacement deletes label post-regexp
If `cfg.TargetLabel` is a template like `$1`, it won't match any labels, so no point calling `lb.Del` with it. Similarly if `target` is not a valid label name, it won't match any labels, so don't call with that either. The intention seems to have been that a blank _value_ would delete the target, so change that code to use `target` instead of `cfg.TargetLabel`. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
000182e4b8
commit
0289dd6157
|
@ -274,12 +274,11 @@ func relabel(cfg *Config, lb *labels.Builder) (keep bool) {
|
|||
}
|
||||
target := model.LabelName(cfg.Regex.ExpandString([]byte{}, cfg.TargetLabel, val, indexes))
|
||||
if !target.IsValid() {
|
||||
lb.Del(cfg.TargetLabel)
|
||||
break
|
||||
}
|
||||
res := cfg.Regex.ExpandString([]byte{}, cfg.Replacement, val, indexes)
|
||||
if len(res) == 0 {
|
||||
lb.Del(cfg.TargetLabel)
|
||||
lb.Del(string(target))
|
||||
break
|
||||
}
|
||||
lb.Set(string(target), string(res))
|
||||
|
|
|
@ -214,6 +214,25 @@ func TestRelabel(t *testing.T) {
|
|||
"a": "boo",
|
||||
}),
|
||||
},
|
||||
{
|
||||
// Blank replacement should delete the label.
|
||||
input: labels.FromMap(map[string]string{
|
||||
"a": "foo",
|
||||
"f": "baz",
|
||||
}),
|
||||
relabel: []*Config{
|
||||
{
|
||||
SourceLabels: model.LabelNames{"a"},
|
||||
Regex: MustNewRegexp("(f).*"),
|
||||
TargetLabel: "$1",
|
||||
Replacement: "$2",
|
||||
Action: Replace,
|
||||
},
|
||||
},
|
||||
output: labels.FromMap(map[string]string{
|
||||
"a": "foo",
|
||||
}),
|
||||
},
|
||||
{
|
||||
input: labels.FromMap(map[string]string{
|
||||
"a": "foo",
|
||||
|
|
Loading…
Reference in a new issue