From fe94f7e18a77674ed05f5a58b6f91651f0129c6b Mon Sep 17 00:00:00 2001 From: Alan Protasio Date: Thu, 14 Sep 2023 16:02:18 -0700 Subject: [PATCH] comments Signed-off-by: Alan Protasio --- pkg/ruler/rulestore/bucketclient/bucket_client.go | 11 ++++++----- .../rulestore/bucketclient/bucket_client_test.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/ruler/rulestore/bucketclient/bucket_client.go b/pkg/ruler/rulestore/bucketclient/bucket_client.go index ff92deb2bb2..ae9dd2c05fa 100644 --- a/pkg/ruler/rulestore/bucketclient/bucket_client.go +++ b/pkg/ruler/rulestore/bucketclient/bucket_client.go @@ -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 ( @@ -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 @@ -187,7 +188,7 @@ 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 } @@ -195,14 +196,14 @@ func (b *BucketRuleStore) LoadRuleGroups(ctx context.Context, groupsToLoad map[s 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 } @@ -235,7 +236,7 @@ outer: return loadedGroups, e } - return loadedGroups, e + return loadedGroups, errs.Err() } // GetRuleGroup implements rules.RuleStore. diff --git a/pkg/ruler/rulestore/bucketclient/bucket_client_test.go b/pkg/ruler/rulestore/bucketclient/bucket_client_test.go index 6fd525ab20e..d371acd42fe 100644 --- a/pkg/ruler/rulestore/bucketclient/bucket_client_test.go +++ b/pkg/ruler/rulestore/bucketclient/bucket_client_test.go @@ -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)) }