diff --git a/app/vmagent/remotewrite/relabel.go b/app/vmagent/remotewrite/relabel.go index 1b796e24cb..44147439c1 100644 --- a/app/vmagent/remotewrite/relabel.go +++ b/app/vmagent/remotewrite/relabel.go @@ -86,7 +86,7 @@ func initLabelsGlobal() { } func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, extraLabels []prompbmarshal.Label, pcs *promrelabel.ParsedConfigs) []prompbmarshal.TimeSeries { - if len(extraLabels) == 0 && pcs.Len() == 0 { + if len(extraLabels) == 0 && pcs.Len() == 0 && !*usePromCompatibleNaming { // Nothing to change. return tss } diff --git a/app/vmagent/remotewrite/relabel_test.go b/app/vmagent/remotewrite/relabel_test.go new file mode 100644 index 0000000000..eb35400021 --- /dev/null +++ b/app/vmagent/remotewrite/relabel_test.go @@ -0,0 +1,49 @@ +package remotewrite + +import ( + "reflect" + "testing" + + "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" +) + +func TestApplyRelabeling(t *testing.T) { + f := func(extraLabels []prompbmarshal.Label, pcs *promrelabel.ParsedConfigs, sTss, sExpTss string) { + rctx := &relabelCtx{} + tss, expTss := parseSeries(sTss), parseSeries(sExpTss) + gotTss := rctx.applyRelabeling(tss, extraLabels, pcs) + if !reflect.DeepEqual(gotTss, expTss) { + t.Fatalf("expected to have: \n%v;\ngot: \n%v", expTss, gotTss) + } + } + + f(nil, nil, "up", "up") + f([]prompbmarshal.Label{{Name: "foo", Value: "bar"}}, nil, "up", `up{foo="bar"}`) + f([]prompbmarshal.Label{{Name: "foo", Value: "bar"}}, nil, `up{foo="baz"}`, `up{foo="bar"}`) + + pcs, err := promrelabel.ParseRelabelConfigsData([]byte(` +- target_label: "foo" + replacement: "aaa" +- action: labeldrop + regex: "env.*" +`)) + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + f(nil, pcs, `up{foo="baz", env="prod"}`, `up{foo="aaa"}`) + + oldVal := *usePromCompatibleNaming + *usePromCompatibleNaming = true + f(nil, nil, `foo.bar`, `foo_bar`) + *usePromCompatibleNaming = oldVal +} + +func parseSeries(data string) []prompbmarshal.TimeSeries { + var tss []prompbmarshal.TimeSeries + tss = append(tss, prompbmarshal.TimeSeries{ + Labels: promutils.MustNewLabelsFromString(data).GetLabels(), + }) + return tss +} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c37125df65..69722f387a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -20,6 +20,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * BUGFIX: fix `error when searching for TSIDs by metricIDs in the previous indexdb: EOF` error, which can occur during queries after unclean shutdown of VictoriaMetrics (e.g. via hardware reset, out of memory crash or `kill -9`). The error has been introduced in [v1.85.2](https://docs.victoriametrics.com/CHANGELOG.html#v1852). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3515). * BUGFIX: [VictoriaMetrics enterprise](https://docs.victoriametrics.com/enterprise.html): expose proper values for `vm_downsampling_partitions_scheduled` and `vm_downsampling_partitions_scheduled_size_bytes` metrics, which were added at [v1.78.0](https://docs.victoriametrics.com/CHANGELOG.html#v1780). See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2612). * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): never extend explicitly set lookbehind window for [rate()](https://docs.victoriametrics.com/MetricsQL.html#rate) function. This reduces the level of confusion when the user expects the needed results after explicitly seting the lookbehind window `[d]` in the query `rate(m[d])`. Previously VictoriaMetrics could silently extend the lookbehind window, so it covers at least two raw samples. Now this behavior works only if the lookbehind window in square brackets isn't set explicitly, e.g. in the case of `rate(m)`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3483) for details. +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): respect `-usePromCompatibleNaming` flag if no relabeling or extra labels were set. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3511) for details. * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix the wrong legend when queries are hidden. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3512).