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

Ignore objects with names that end with / when listing rule groups #3999

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -21,6 +21,7 @@
* [BUGFIX] Distributor: reverted changes done to rate limiting in #3825. #3948
* [BUGFIX] Ingester: Fix race condition when opening and closing tsdb concurrently. #3959
* [BUGFIX] Querier: streamline tracing spans. #3924
* [BUGFIX] Ruler Storage: ignore objects with empty namespace or group in the name. #3999

## 1.8.0 in progress

Expand Down
9 changes: 8 additions & 1 deletion pkg/ruler/rulestore/bucketclient/bucket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,16 @@ func (b *BucketRuleStore) ListAllRuleGroups(ctx context.Context) (map[string]rul

// List rule groups for all tenants.
err := b.bucket.Iter(ctx, "", func(key string) error {
// Ignore objects that look like directories, ie. they have empty namespace or group name.
// Such objects can exist in the object store, but would cause trouble when loading them, because
// we check for user, namespace and group components not being empty.
if strings.HasSuffix(key, objstore.DirDelim) {
return nil
}

userID, namespace, group, err := parseRuleGroupObjectKeyWithUser(key)
if err != nil {
level.Warn(b.logger).Log("msg", "invalid rule group object key found while listing rule groups", "key", key)
level.Warn(b.logger).Log("msg", "invalid rule group object key found while listing rule groups", "key", key, "err", err)

// Do not fail just because of a spurious item in the bucket.
return nil
Expand Down
33 changes: 33 additions & 0 deletions pkg/ruler/rulestore/bucketclient/bucket_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,36 @@ func TestParseRuleGroupObjectKeyWithUser(t *testing.T) {
})
}
}

func TestListAllRuleGroupsWithNoNamespaceOrGroup(t *testing.T) {
obj := mockBucket{
names: []string{
"rules/user1/",
"rules/user2/bnM=/", // namespace "ns", ends with '/'
"rules/user3/bnM=/Z3JvdXAx", // namespace "ns", group "group1"
},
}

s := NewBucketRuleStore(obj, nil, log.NewNopLogger())
out, err := s.ListAllRuleGroups(context.Background())
require.NoError(t, err)

require.Equal(t, 1, len(out)) // one user
require.Equal(t, 1, len(out["user3"])) // one group
require.Equal(t, "group1", out["user3"][0].Name) // one group
}

type mockBucket struct {
objstore.Bucket

names []string
}

func (mb mockBucket) Iter(ctx context.Context, dir string, f func(string) error, options ...objstore.IterOption) error {
for _, n := range mb.names {
if err := f(n); err != nil {
return err
}
}
return nil
}