-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing problem on FilteredSelector when applying filter in series without filtered labels #163
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e4a6b0
Fixing problem on FilteredSelector when applying filter in series wit…
pedro-stanaka 8fc761a
adding new test case for negative match
pedro-stanaka 89d2c70
adding support for macos
pedro-stanaka b62d56b
Fixing linting
pedro-stanaka 1bfd526
Adding copyright
pedro-stanaka b83a85b
Using early return
pedro-stanaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) The Thanos Community Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package storage_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prometheus/prometheus/model/labels" | ||
promstg "github.com/prometheus/prometheus/storage" | ||
"github.com/prometheus/prometheus/tsdb/chunkenc" | ||
|
||
"github.com/thanos-community/promql-engine/execution/storage" | ||
) | ||
|
||
func TestFilter_Matches(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
matchers []*labels.Matcher | ||
series promstg.Series | ||
expected bool | ||
}{ | ||
{ | ||
name: "empty matchers", | ||
matchers: []*labels.Matcher{}, | ||
series: &mockLabelSeries{labels: labels.FromStrings("foo", "bar")}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "no match", | ||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "foo", "bar")}, | ||
series: &mockLabelSeries{labels: labels.FromStrings("foo", "baz")}, | ||
}, | ||
{ | ||
name: "regex match", | ||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "foo", "ba.")}, | ||
series: &mockLabelSeries{labels: labels.FromStrings("foo", "bar")}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "regex no match", | ||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "foo", "ba.")}, | ||
series: &mockLabelSeries{labels: labels.FromStrings("foo", "nope")}, | ||
}, | ||
{ | ||
name: "multiple matchers", | ||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"), labels.MustNewMatcher(labels.MatchEqual, "baz", "qux")}, | ||
series: &mockLabelSeries{labels: labels.FromStrings("foo", "bar", "baz", "qux")}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "single regex matcher, with label name not present", | ||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "foo", ".*")}, | ||
series: &mockLabelSeries{labels: labels.FromStrings("bar", "baz")}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "single regex matcher, with label name not present, negative regex", | ||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchNotRegexp, "foo", ".*")}, | ||
series: &mockLabelSeries{labels: labels.FromStrings("bar", "baz")}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
f := storage.NewFilter(tc.matchers) | ||
if got := f.Matches(tc.series); got != tc.expected { | ||
if tc.expected { | ||
t.Errorf("expected %s to match %s, but it did not.", tc.series.Labels().String(), tc.matchers) | ||
} else { | ||
t.Errorf("expected %s to not match %s, but it did.", tc.series.Labels().String(), tc.matchers) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
type mockLabelSeries struct { | ||
labels labels.Labels | ||
} | ||
|
||
func (s *mockLabelSeries) Labels() labels.Labels { | ||
return s.labels | ||
} | ||
|
||
func (s *mockLabelSeries) Iterator() chunkenc.Iterator { | ||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can return
false
immediately here.