From 4269b8fd8b492776b086b864a5e57e66b03185a5 Mon Sep 17 00:00:00 2001 From: yeya24 Date: Fri, 5 Mar 2021 21:43:37 -0500 Subject: [PATCH 1/2] Fix partial and empty matchers match Signed-off-by: yeya24 --- pkg/compactv2/compactor_test.go | 38 +++++++++++++++++++++++++++++++++ pkg/compactv2/modifiers.go | 5 +---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/pkg/compactv2/compactor_test.go b/pkg/compactv2/compactor_test.go index c1af292d1b..0d2d2a1f55 100644 --- a/pkg/compactv2/compactor_test.go +++ b/pkg/compactv2/compactor_test.go @@ -306,6 +306,44 @@ func TestCompactor_WriteSeries_e2e(t *testing.T) { NumChunks: 2, }, }, + { + name: "1 blocks + delete modifier. For deletion request, full match is required. Delete the first two series", + input: [][]seriesSamples{ + { + {lset: labels.Labels{{Name: "a", Value: "1"}, {Name: "b", Value: "2"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "1"}, {Name: "b", Value: "2"}, {Name: "foo", Value: "bar"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}, {10, 12}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "b", Value: "2"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}, {10, 12}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "c", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}, {10, 12}, {11, 11}, {20, 20}}}}, + }, + }, + modifiers: []Modifier{WithDeletionModifier( + metadata.DeletionRequest{ + Matchers: []*labels.Matcher{ + labels.MustNewMatcher(labels.MatchEqual, "a", "1"), + labels.MustNewMatcher(labels.MatchEqual, "b", "2"), + }, + })}, + expected: []seriesSamples{ + {lset: labels.Labels{{Name: "a", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}, {10, 12}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "b", Value: "2"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}, {10, 12}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "c", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}, {10, 12}, {11, 11}, {20, 20}}}}, + }, + expectedChanges: "Deleted {a=\"1\", b=\"2\"} [{0 20}]\nDeleted {a=\"1\", b=\"2\", foo=\"bar\"} [{0 20}]\n", + expectedStats: tsdb.BlockStats{ + NumSamples: 18, + NumSeries: 3, + NumChunks: 3, + }, + }, } { t.Run(tcase.name, func(t *testing.T) { tmpDir, err := ioutil.TempDir("", "test-series-writer") diff --git a/pkg/compactv2/modifiers.go b/pkg/compactv2/modifiers.go index 9d521c0fd2..aef4ec065e 100644 --- a/pkg/compactv2/modifiers.go +++ b/pkg/compactv2/modifiers.go @@ -62,12 +62,9 @@ SeriesLoop: for _, deletions := range d.d.deletions { for _, m := range deletions.Matchers { v := lbls.Get(m.Name) - if v == "" { - continue - } // Only if all matchers in the deletion request are matched can we proceed to deletion. - if !m.Matches(v) { + if v == "" || !m.Matches(v) { continue DeletionsLoop } } From 33073b37a713db65cbbe3dc86c53fbcad25a5c78 Mon Sep 17 00:00:00 2001 From: yeya24 Date: Fri, 5 Mar 2021 22:13:39 -0500 Subject: [PATCH 2/2] add testcase for non-equal matchers Signed-off-by: yeya24 --- pkg/compactv2/compactor_test.go | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/pkg/compactv2/compactor_test.go b/pkg/compactv2/compactor_test.go index 0d2d2a1f55..e5c979a053 100644 --- a/pkg/compactv2/compactor_test.go +++ b/pkg/compactv2/compactor_test.go @@ -344,6 +344,59 @@ func TestCompactor_WriteSeries_e2e(t *testing.T) { NumChunks: 3, }, }, + { + name: "1 blocks + delete modifier. Deletion request contains non-equal matchers.", + input: [][]seriesSamples{ + { + {lset: labels.Labels{{Name: "a", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "2"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "2"}, {Name: "foo", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "2"}, {Name: "foo", Value: "bar"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "3"}, {Name: "foo", Value: "baz"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "foo", Value: "bat"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + + // Label a is present but with an empty value. + {lset: labels.Labels{{Name: "a", Value: ""}, {Name: "foo", Value: "bat"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + // Series with unrelated labels. + {lset: labels.Labels{{Name: "c", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + }, + }, + modifiers: []Modifier{WithDeletionModifier( + metadata.DeletionRequest{ + Matchers: []*labels.Matcher{ + labels.MustNewMatcher(labels.MatchNotEqual, "a", "1"), + labels.MustNewMatcher(labels.MatchRegexp, "foo", "^ba.$"), + }, + })}, + expected: []seriesSamples{ + {lset: labels.Labels{{Name: "a", Value: ""}, {Name: "foo", Value: "bat"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "2"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "a", Value: "2"}, {Name: "foo", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "c", Value: "1"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + {lset: labels.Labels{{Name: "foo", Value: "bat"}}, + chunks: [][]sample{{{0, 0}, {1, 1}, {2, 2}}, {{10, 11}, {11, 11}, {20, 20}}}}, + }, + expectedChanges: "Deleted {a=\"2\", foo=\"bar\"} [{0 20}]\nDeleted {a=\"3\", foo=\"baz\"} [{0 20}]\n", + expectedStats: tsdb.BlockStats{ + NumSamples: 36, + NumSeries: 6, + NumChunks: 12, + }, + }, } { t.Run(tcase.name, func(t *testing.T) { tmpDir, err := ioutil.TempDir("", "test-series-writer")