mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 01:24:04 -08:00
check new line in target
Signed-off-by: Xiaochao Dong (@damnever) <the.xcdong@gmail.com>
This commit is contained in:
parent
2d0d333371
commit
1601b2a79e
|
@ -269,6 +269,7 @@ func relabel(cfg *Config, lb *labels.Builder) (keep bool) {
|
|||
case Replace:
|
||||
// Fast path to add or delete label pair.
|
||||
if val == "" && cfg.Regex == DefaultRelabelConfig.Regex &&
|
||||
!containsNewLine(cfg.TargetLabel) &&
|
||||
!varInRegexTemplate(cfg.TargetLabel) && !varInRegexTemplate(cfg.Replacement) {
|
||||
if !model.LabelName(cfg.TargetLabel).IsValid() || cfg.Replacement == "" {
|
||||
lb.Del(cfg.TargetLabel)
|
||||
|
@ -331,3 +332,7 @@ func relabel(cfg *Config, lb *labels.Builder) (keep bool) {
|
|||
func varInRegexTemplate(template string) bool {
|
||||
return strings.Contains(template, "$")
|
||||
}
|
||||
|
||||
func containsNewLine(s string) bool {
|
||||
return strings.Contains(s, "\r\n") || strings.Contains(s, "\n")
|
||||
}
|
||||
|
|
|
@ -858,6 +858,8 @@ func BenchmarkRelabel_ReplaceAddLabel(b *testing.B) {
|
|||
"wwwwww": "wwwwww",
|
||||
"xxxxxxxxx": "xxxxxxxxx",
|
||||
"yyyyyyyyyyyy": "yyyyyyyyyyyy",
|
||||
"new\nline1": "dropped",
|
||||
"new\r\nline2": "dropped",
|
||||
"${0}": "dropped",
|
||||
"dropped": "${0}",
|
||||
} {
|
||||
|
@ -905,7 +907,7 @@ func BenchmarkRelabel_ReplaceAddLabel(b *testing.B) {
|
|||
labels.Label{Name: "abcdefg12", Value: "hijklmn12"},
|
||||
labels.Label{Name: "abcdefg13", Value: "hijklmn13"},
|
||||
}
|
||||
_, _ = Process(lset, cfgs...)
|
||||
// require.Equal(b, actual, expectLset)
|
||||
actual, _ := Process(lset, cfgs...)
|
||||
require.Equal(b, actual, expectLset)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue