From c727d2219b0e829bb4748d83d830d45bd6e87551 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 14 Feb 2021 23:34:13 +0200 Subject: [PATCH] lib/storage: properly hanle regexp tag filters with dots, which can be converted to full string match filters. For example `{label=~"foo\.bar"}` should be converted to `{label="foo.bar"}`. Previously it has was mistakenly conveted to `{label="foo\.bar"}` . This could result in missing time series for such tag filters. --- docs/CHANGELOG.md | 1 + lib/storage/tag_filters.go | 3 ++- lib/storage/tag_filters_test.go | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 47307af5e7..4da46a4f50 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,7 @@ * FEATURE: vmauth: add ability to route requests from a single user to multiple destinations depending on the requested paths. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1064 * FEATURE: remove dependency on external programs such as `cat`, `grep` and `cut` when detecting cpu and memory limits inside Docker or LXC container. +* BUGFIX: properly convert regexp tag filters containing escaped dots to non-regexp tag filters. For example, `{foo=~"bar\.baz"}` should be converted to `{foo="bar.baz"}`. Previously it was incorrectly converted to `{foo="bar\.baz"}`, which could result in missing time series for this tag filter. * BUGFIX: do not spam error logs when discovering Docker Swarm targets without dedicated IP. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1028 . * BUGFIX: properly embed timezone data into VictoriaMetrics apps. This should fix `-loggerTimezone` usage inside Docker containers. * BUGFIX: properly build Docker images for non-amd64 architectures (arm, arm64, ppc64le, 386) on [Docker hub](https://hub.docker.com/u/victoriametrics/). Previously these images were incorrectly based on amd64 base image, so they didn't work. diff --git a/lib/storage/tag_filters.go b/lib/storage/tag_filters.go index 9a368f45c8..e2b2e92850 100644 --- a/lib/storage/tag_filters.go +++ b/lib/storage/tag_filters.go @@ -48,7 +48,7 @@ func convertToCompositeTagFilters(tfs *TagFilters) *TagFilters { } continue } - if string(tf.key) == "__graphite__" { + if string(tf.key) == "__graphite__" || bytes.Equal(tf.key, graphiteReverseTagKey) { tfsNew = append(tfsNew, tf) continue } @@ -367,6 +367,7 @@ func (tf *tagFilter) Init(commonPrefix, key, value []byte, isNegative, isRegexp if tf.isRegexp { prefix, expr = getRegexpPrefix(tf.value) if len(expr) == 0 { + tf.value = append(tf.value[:0], prefix...) tf.isRegexp = false } } diff --git a/lib/storage/tag_filters_test.go b/lib/storage/tag_filters_test.go index b434baf04a..80cc7fee9e 100644 --- a/lib/storage/tag_filters_test.go +++ b/lib/storage/tag_filters_test.go @@ -977,8 +977,9 @@ func TestTagFiltersString(t *testing.T) { mustAdd("tag_re", "re.value", false, true) mustAdd("tag_nre", "nre.value", true, true) mustAdd("tag_n", "n_value", true, false) + mustAdd("tag_re_graphite", "foo\\.bar", false, true) s := tfs.String() - sExpected := `{__name__="metric_name", tag_re=~"re.value", tag_nre!~"nre.value", tag_n!="n_value"}` + sExpected := `{__name__="metric_name", tag_re=~"re.value", tag_nre!~"nre.value", tag_n!="n_value", tag_re_graphite="foo.bar"}` if s != sExpected { t.Fatalf("unexpected TagFilters.String(); got %q; want %q", s, sExpected) }