diff --git a/execution/storage/filter.go b/execution/storage/filter.go index 4af0f1a0..3a2f397b 100644 --- a/execution/storage/filter.go +++ b/execution/storage/filter.go @@ -21,7 +21,7 @@ func (n nopFilter) Matches(storage.Series) bool { return true } type filter struct { matchers []*labels.Matcher - matcherSet map[string]*labels.Matcher + matcherSet map[string][]*labels.Matcher } func NewFilter(matchers []*labels.Matcher) Filter { @@ -29,9 +29,9 @@ func NewFilter(matchers []*labels.Matcher) Filter { return &nopFilter{} } - matcherSet := make(map[string]*labels.Matcher) + matcherSet := make(map[string][]*labels.Matcher) for _, m := range matchers { - matcherSet[m.Name] = m + matcherSet[m.Name] = append(matcherSet[m.Name], m) } return &filter{ matchers: matchers, @@ -46,10 +46,13 @@ func (f filter) Matches(series storage.Series) bool { return true } - for name, m := range f.matcherSet { + for name, matchers := range f.matcherSet { label := series.Labels().Get(name) - if !m.Matches(label) { - return false + + for _, m := range matchers { + if !m.Matches(label) { + return false + } } } diff --git a/execution/storage/filter_test.go b/execution/storage/filter_test.go index 7c606e2e..d7d05903 100644 --- a/execution/storage/filter_test.go +++ b/execution/storage/filter_test.go @@ -9,10 +9,20 @@ import ( "github.com/prometheus/prometheus/model/labels" promstg "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/tsdb/chunkenc" + "github.com/stretchr/testify/require" "github.com/thanos-io/promql-engine/execution/storage" ) +func TestFilter_MultipleMatcherWithSameName(t *testing.T) { + f := storage.NewFilter([]*labels.Matcher{ + labels.MustNewMatcher(labels.MatchNotEqual, "phase", "Running"), + labels.MustNewMatcher(labels.MatchNotEqual, "phase", "Succeeded"), + }) + + require.Equal(t, false, f.Matches(&mockLabelSeries{labels: labels.FromStrings("phase", "Running")})) +} + func TestFilter_Matches(t *testing.T) { testCases := []struct { name string