From aad38c8283efacc9f5ce14158364d7f30885cbe4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 25 Jun 2020 17:18:55 +0300 Subject: [PATCH] lib/promrelabel: properly apply `^` and `$` anchors to `regex` value in Prometheus relabeling rules --- lib/promrelabel/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/promrelabel/config.go b/lib/promrelabel/config.go index 5a5d602861..ec0fc91f93 100644 --- a/lib/promrelabel/config.go +++ b/lib/promrelabel/config.go @@ -63,7 +63,7 @@ func parseRelabelConfig(dst []ParsedRelabelConfig, rc *RelabelConfig) ([]ParsedR if rc.Regex != nil { regex := *rc.Regex if rc.Action != "replace_all" && rc.Action != "labelmap_all" { - regex = "^" + *rc.Regex + "$" + regex = "^(?:" + *rc.Regex + ")$" } re, err := regexp.Compile(regex) if err != nil {