@@ -3,7 +3,6 @@ package compactor
33import (
44 "context"
55 "crypto/rand"
6- "errors"
76 "fmt"
87 "path"
98 "strings"
@@ -17,14 +16,12 @@ import (
1716 prom_testutil "github.com/prometheus/client_golang/prometheus/testutil"
1817 "github.com/stretchr/testify/assert"
1918 "github.com/stretchr/testify/require"
20- "github.com/thanos-io/objstore"
2119 "github.com/thanos-io/thanos/pkg/block"
2220 "github.com/thanos-io/thanos/pkg/block/metadata"
2321
2422 "github.com/cortexproject/cortex/pkg/storage/tsdb"
2523 "github.com/cortexproject/cortex/pkg/storage/tsdb/bucketindex"
2624 cortex_testutil "github.com/cortexproject/cortex/pkg/storage/tsdb/testutil"
27- "github.com/cortexproject/cortex/pkg/util"
2825 "github.com/cortexproject/cortex/pkg/util/services"
2926)
3027
@@ -57,6 +54,37 @@ func TestBlocksCleaner(t *testing.T) {
5754 }
5855}
5956
57+ func TestBlockCleaner_KeyPermissionDenied (t * testing.T ) {
58+ const userID = "user-1"
59+
60+ bucketClient , _ := cortex_testutil .PrepareFilesystemBucket (t )
61+ bucketClient = bucketindex .BucketWithGlobalMarkers (bucketClient )
62+
63+ // Create blocks.
64+ ctx := context .Background ()
65+ deletionDelay := 12 * time .Hour
66+ bucketClient = & cortex_testutil.MockBucketFailure {
67+ Bucket : bucketClient ,
68+ GetFailures : map [string ]error {
69+ path .Join (userID , "bucket-index.json.gz" ): cortex_testutil .ErrKeyAccessDeniedError ,
70+ },
71+ }
72+
73+ cfg := BlocksCleanerConfig {
74+ DeletionDelay : deletionDelay ,
75+ CleanupInterval : time .Minute ,
76+ CleanupConcurrency : 1 ,
77+ }
78+
79+ logger := log .NewNopLogger ()
80+ scanner := tsdb .NewUsersScanner (bucketClient , tsdb .AllUsers , logger )
81+ cfgProvider := newMockConfigProvider ()
82+
83+ cleaner := NewBlocksCleaner (cfg , bucketClient , scanner , cfgProvider , logger , nil )
84+ err := cleaner .cleanUser (ctx , userID , true )
85+ require .NoError (t , err )
86+ }
87+
6088func testBlocksCleanerWithOptions (t * testing.T , options testBlocksCleanerOptions ) {
6189 bucketClient , _ := cortex_testutil .PrepareFilesystemBucket (t )
6290
@@ -254,7 +282,7 @@ func TestBlocksCleaner_ShouldContinueOnBlockDeletionFailure(t *testing.T) {
254282 createDeletionMark (t , bucketClient , userID , block4 , now .Add (- deletionDelay ).Add (- time .Hour ))
255283
256284 // To emulate a failure deleting a block, we wrap the bucket client in a mocked one.
257- bucketClient = & mockBucketFailure {
285+ bucketClient = & cortex_testutil. MockBucketFailure {
258286 Bucket : bucketClient ,
259287 DeleteFailures : []string {path .Join (userID , block3 .String (), metadata .MetaFilename )},
260288 }
@@ -658,19 +686,6 @@ func TestBlocksCleaner_ShouldRemoveBlocksOutsideRetentionPeriod(t *testing.T) {
658686 }
659687}
660688
661- type mockBucketFailure struct {
662- objstore.Bucket
663-
664- DeleteFailures []string
665- }
666-
667- func (m * mockBucketFailure ) Delete (ctx context.Context , name string ) error {
668- if util .StringsContain (m .DeleteFailures , name ) {
669- return errors .New ("mocked delete failure" )
670- }
671- return m .Bucket .Delete (ctx , name )
672- }
673-
674689type mockConfigProvider struct {
675690 userRetentionPeriods map [string ]time.Duration
676691}
0 commit comments