Skip to content

Commit

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

Signed-off-by: Ben Ye <[email protected]>

* update changelog

Signed-off-by: Ben Ye <[email protected]>

---------

Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 authored Oct 18, 2023
1 parent 77fac93 commit e4b579f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit e4b579f

Please sign in to comment.