Skip to content
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

Fix matchersToPostingGroups vals variable shadow bug #6817

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
### Fixed

- [#6802](https://github.com/thanos-io/thanos/pull/6802) Receive: head series limiter should not run if no head series limit is set.
- [#6817](https://github.com/thanos-io/thanos/pull/6817) Store Gateway: fix `matchersToPostingGroups` label values variable got shadowed bug.

### Added

Expand Down
3 changes: 2 additions & 1 deletion pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2664,8 +2664,9 @@ func matchersToPostingGroups(ctx context.Context, lvalsFn func(name string) ([]s
}
// Cache label values because label name is the same.
if !valuesCached && vals != nil {
lvals := vals
lvalsFunc = func(_ string) ([]string, error) {
return vals, nil
return lvals, nil
}
valuesCached = true
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,29 @@ func TestMatchersToPostingGroup(t *testing.T) {
},
},
},
{
name: "Reproduce values shadow bug",
matchers: []*labels.Matcher{
labels.MustNewMatcher(labels.MatchRegexp, "name", "test.*"),
labels.MustNewMatcher(labels.MatchNotRegexp, "name", "testfoo"),
labels.MustNewMatcher(labels.MatchNotEqual, "name", ""),
},
labelValues: map[string][]string{
"name": {"testbar", "testfoo"},
},
expected: []*postingGroup{
{
name: "name",
addAll: false,
addKeys: []string{"testbar"},
matchers: []*labels.Matcher{
labels.MustNewMatcher(labels.MatchNotEqual, "name", ""),
labels.MustNewMatcher(labels.MatchRegexp, "name", "test.*"),
labels.MustNewMatcher(labels.MatchNotRegexp, "name", "testfoo"),
},
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
actual, err := matchersToPostingGroups(ctx, func(name string) ([]string, error) {
Expand Down
Loading