lib/promrelabel: do not split regex into multiple lines if it contains groups

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2928
This commit is contained in:
Aliaksandr Valialkin 2022-08-08 03:15:23 +03:00
parent 23b7fa897a
commit 9039f23bd1
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
3 changed files with 30 additions and 0 deletions

View file

@ -31,6 +31,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): set `up` metric to `0` for partial scrapes in [stream parsing mode](https://docs.victoriametrics.com/vmagent.html#stream-parsing-mode). Previously the `up` metric was set to `1` when at least a single metric has been scraped before the error. This aligns the behaviour of `vmselect` with Prometheus.
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): restart all the scrape jobs during [config reload](https://docs.victoriametrics.com/vmagent.html#configuration-update) after `global` section is changed inside `-promscrape.config`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2884).
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly assume role with AWS ECS credentials. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2875). Thanks to @transacid for [the fix](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2876).
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): do not split regex in [relabeling rules](https://docs.victoriametrics.com/vmagent.html#relabeling) into multiple lines if it contains groups. This fixes [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2928).
* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): return series from `q1` if `q2` doesn't return matching time series in the query `q1 ifnot q2`. Previously series from `q1` weren't returned in this case.
* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly show date picker at `Table` tab. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2874).
* BUGFIX: properly generate http redirects if `-http.pathPrefix` command-line flag is set. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2918).

View file

@ -104,6 +104,11 @@ func stringValue(v interface{}) (string, error) {
// MarshalYAML marshals mlr to YAML.
func (mlr *MultiLineRegex) MarshalYAML() (interface{}, error) {
if strings.ContainsAny(mlr.S, "([") {
// The mlr.S contains groups. Fall back to returning the regexp as is without splitting it into parts.
// This fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2928 .
return mlr.S, nil
}
a := strings.Split(mlr.S, "|")
if len(a) == 1 {
return a[0], nil

View file

@ -7,6 +7,30 @@ import (
"gopkg.in/yaml.v2"
)
func TestMultiLineRegexUnmarshalMarshal(t *testing.T) {
f := func(data, resultExpected string) {
t.Helper()
var mlr MultiLineRegex
if err := yaml.UnmarshalStrict([]byte(data), &mlr); err != nil {
t.Fatalf("cannot unmarshal %q: %s", data, err)
}
result, err := yaml.Marshal(&mlr)
if err != nil {
t.Fatalf("cannot marshal %q: %s", data, err)
}
if string(result) != resultExpected {
t.Fatalf("unexpected marshaled data; got\n%q\nwant\n%q", result, resultExpected)
}
}
f(``, `""`+"\n")
f(`foo`, "foo\n")
f(`a|b||c`, "- a\n- b\n- \"\"\n- c\n")
f(`(a|b)`, "(a|b)\n")
f(`a|b[c|d]`, "a|b[c|d]\n")
f("- a\n- b", "- a\n- b\n")
f("- a\n- (b)", "a|(b)\n")
}
func TestRelabelConfigMarshalUnmarshal(t *testing.T) {
f := func(data, resultExpected string) {
t.Helper()