Skip to content

Commit

Permalink
Fix matchersToPostingGroups vals variable shadow bug (thanos-io#6817)
Browse files Browse the repository at this point in the history
* fix matchersToPostingGroups vals variable shadow bug

Signed-off-by: Ben Ye <benye@amazon.com>

* update changelog

Signed-off-by: Ben Ye <benye@amazon.com>

---------

Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 authored and saswatamcode committed Oct 18, 2023
1 parent b6bf619 commit 4ed9bb0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Fixed

- [#6817](https://github.com/thanos-io/thanos/pull/6817) Store Gateway: fix `matchersToPostingGroups` label values variable got shadowed bug.

### Added

### Changed
Expand Down
3 changes: 2 additions & 1 deletion pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2503,8 +2503,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 @@ -3076,6 +3076,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

0 comments on commit 4ed9bb0

Please sign in to comment.