lib/promrelabel: properly apply ^ and $ anchors to regex value in Prometheus relabeling rules

This commit is contained in:
Aliaksandr Valialkin 2020-06-25 17:18:55 +03:00
parent a586b8b6d4
commit aad38c8283

View File

@ -63,7 +63,7 @@ func parseRelabelConfig(dst []ParsedRelabelConfig, rc *RelabelConfig) ([]ParsedR
if rc.Regex != nil { if rc.Regex != nil {
regex := *rc.Regex regex := *rc.Regex
if rc.Action != "replace_all" && rc.Action != "labelmap_all" { if rc.Action != "replace_all" && rc.Action != "labelmap_all" {
regex = "^" + *rc.Regex + "$" regex = "^(?:" + *rc.Regex + ")$"
} }
re, err := regexp.Compile(regex) re, err := regexp.Compile(regex)
if err != nil { if err != nil {