Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmagent relabeling error re-writing regex #3131

Closed
cskinfill opened this issue Sep 19, 2022 · 2 comments
Closed

vmagent relabeling error re-writing regex #3131

cskinfill opened this issue Sep 19, 2022 · 2 comments
Assignees
Labels
bug Something isn't working vmagent

Comments

@cskinfill
Copy link

Describe the bug
Regression when vmagent loads a relabeling config it is failing to parse regex because it is incorrectly rewriting it.

To Reproduce
It appears to be any relabeling regex with an escaped $ (so \$) at the end of the regex string.

For example

- source_labels: [__name__]
  action: replace
  regex: '(.*)\$$'
  target_label: "__name__"
  replacement: "$1"

Expected behavior
The relabeling config will continue to work.

Logs

2022-09-19T17:37:16.055Z	fatal	VictoriaMetrics/app/vmagent/remotewrite/remotewrite.go:139	cannot load relabel configs: cannot load -remoteWrite.relabelConfig="/etc/vm/relabeling/global_relabeling.yaml": cannot unmarshal `relabel_configs` from "/etc/vm/relabeling/global_relabeling.yaml": error when parsing `relabel_config` #5: cannot parse `regex` "^(?:(.*)\\)$": error parsing regexp: missing closing ): `^(?:(.*)\)$`

Version
The line returned when passing --version command line flag to the binary. For example:

vmagent-20220908-110742-tags-v1.81.2-0-gdd1126dcc

Used command-line flags

-graphiteListenAddr=":2003"
-httpListenAddr=":8429"
-influx.maxLineSize="8MB"
-promscrape.cluster.memberNum="1"
-promscrape.cluster.membersCount="5"
-promscrape.config="/etc/vmagent/config_out/vmagent.env.yaml"
-promscrape.maxScrapeSize="1GiB"
-promscrape.streamParse="true"
-promscrape.suppressDuplicateScrapeTargetErrors="true"
-promscrape.suppressScrapeErrors="true"
-remoteWrite.maxDiskUsagePerURL="1073741824"
-remoteWrite.relabelConfig="/etc/vm/relabeling/global_relabeling.yaml"
-remoteWrite.tmpDataPath="/tmp/vmagent-remotewrite-data"
-remoteWrite.url="secret"

It appears to be this function

func RemoveStartEndAnchors(expr string) string {
which will loop and remove any $ in the regex string or substrings.

@dmitryk-dk dmitryk-dk added bug Something isn't working vmagent labels Sep 21, 2022
@dmitryk-dk dmitryk-dk self-assigned this Sep 28, 2022
valyala added a commit that referenced this issue Sep 30, 2022
valyala added a commit that referenced this issue Sep 30, 2022
@valyala
Copy link
Collaborator

valyala commented Sep 30, 2022

The issue should be fixed in the commit fda60b3 . This commit will be included in the next release. In the mean time it is possible to build vmagent from this commit according to these instructions and verify whether it correctly handles regex ending with escaped $ in relabeling rules.

@valyala
Copy link
Collaborator

valyala commented Oct 7, 2022

vmagent should properly handle escaped $ char at the end of regex in relabeling configs starting from v1.82.0. Closing the issue as fixed.

@valyala valyala closed this as completed Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vmagent
Projects
None yet
Development

No branches or pull requests

3 participants