Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Protasio <[email protected]>
  • Loading branch information
alanprot committed Sep 14, 2023
1 parent 803c49d commit fe94f7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/ruler/rulestore/bucketclient/bucket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cortexproject/cortex/pkg/ruler/rulespb"
"github.com/cortexproject/cortex/pkg/ruler/rulestore"
"github.com/cortexproject/cortex/pkg/storage/bucket"
"github.com/cortexproject/cortex/pkg/util/multierror"
)

const (
Expand Down Expand Up @@ -174,7 +175,7 @@ func (b *BucketRuleStore) ListRuleGroupsForUserAndNamespace(ctx context.Context,
func (b *BucketRuleStore) LoadRuleGroups(ctx context.Context, groupsToLoad map[string]rulespb.RuleGroupList) (map[string]rulespb.RuleGroupList, error) {
ch := make(chan *rulespb.RuleGroupDesc)
loadedGroups := make(map[string]rulespb.RuleGroupList, len(groupsToLoad))
var e error
errs := multierror.MultiError{}
m := sync.Mutex{}

// Given we store one file per rule group. With this, we create a pool of workers that will
Expand All @@ -187,22 +188,22 @@ func (b *BucketRuleStore) LoadRuleGroups(ctx context.Context, groupsToLoad map[s
user, namespace, group := gr.GetUser(), gr.GetNamespace(), gr.GetName()
if user == "" || namespace == "" || group == "" {
m.Lock()
e = fmt.Errorf("invalid rule group: user=%q, namespace=%q, group=%q", user, namespace, group)
errs.Add(fmt.Errorf("invalid rule group: user=%q, namespace=%q, group=%q", user, namespace, group))
m.Unlock()
continue
}

gr, err := b.getRuleGroup(gCtx, user, namespace, group, gr) // reuse group pointer from the map.
if err != nil {
m.Lock()
e = errors.Wrapf(err, "get rule group user=%q, namespace=%q, name=%q", user, namespace, group)
errs.Add(errors.Wrapf(err, "get rule group user=%q, namespace=%q, name=%q", user, namespace, group))
m.Unlock()
continue
}

if user != gr.User || namespace != gr.Namespace || group != gr.Name {
m.Lock()
e = fmt.Errorf("mismatch between requested rule group and loaded rule group, requested: user=%q, namespace=%q, group=%q, loaded: user=%q, namespace=%q, group=%q", user, namespace, group, gr.User, gr.Namespace, gr.Name)
errs.Add(fmt.Errorf("mismatch between requested rule group and loaded rule group, requested: user=%q, namespace=%q, group=%q, loaded: user=%q, namespace=%q, group=%q", user, namespace, group, gr.User, gr.Namespace, gr.Name))
m.Unlock()
continue
}
Expand Down Expand Up @@ -235,7 +236,7 @@ outer:
return loadedGroups, e
}

return loadedGroups, e
return loadedGroups, errs.Err()
}

// GetRuleGroup implements rules.RuleStore.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ruler/rulestore/bucketclient/bucket_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestLoadPartialRules(t *testing.T) {
// Fail user1
mockedBucketClient.GetFailures["rules/user2"] = testutil.ErrKeyAccessDeniedError
loadedGroups, err = bucketStore.LoadRuleGroups(context.Background(), allGroups)
require.ErrorIs(t, err, rulestore.ErrAccessDenied)
require.ErrorContains(t, err, "access denied")
require.Equal(t, 2, len(loadedGroups))
}

Expand Down

0 comments on commit fe94f7e

Please sign in to comment.