@@ -2028,3 +2028,103 @@ func TestCompactor_ShouldNotTreatInterruptionsAsErrors(t *testing.T) {
2028
2028
require .Contains (t , lines , `level=info component=compactor msg="interrupting compaction of user blocks" user=user-1` )
2029
2029
require .NotContains (t , logs .String (), `level=error` )
2030
2030
}
2031
+
2032
+ func TestCompactor_ShouldNotFailCompactionIfAccessDeniedErrDuringMetaSync (t * testing.T ) {
2033
+ t .Parallel ()
2034
+
2035
+ ss := bucketindex.Status {Status : bucketindex .Ok , Version : bucketindex .SyncStatusFileVersion }
2036
+ content , err := json .Marshal (ss )
2037
+ require .NoError (t , err )
2038
+
2039
+ bucketClient := & bucket.ClientMock {}
2040
+ bucketClient .MockIter ("__markers__" , []string {}, nil )
2041
+ bucketClient .MockIter ("" , []string {"user-1" }, nil )
2042
+ bucketClient .MockIter ("user-1/" , []string {"user-1/01DTVP434PA9VFXSW2JKB3392D" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" }, nil )
2043
+ bucketClient .MockIter ("user-1/markers/" , nil , nil )
2044
+ bucketClient .MockGet ("user-1/markers/cleaner-visit-marker.json" , "" , nil )
2045
+ bucketClient .MockUpload ("user-1/markers/cleaner-visit-marker.json" , nil )
2046
+ bucketClient .MockDelete ("user-1/markers/cleaner-visit-marker.json" , nil )
2047
+ bucketClient .MockExists (cortex_tsdb .GetGlobalDeletionMarkPath ("user-1" ), false , nil )
2048
+ bucketClient .MockExists (cortex_tsdb .GetLocalDeletionMarkPath ("user-1" ), false , nil )
2049
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , mockBlockMetaJSON ("01DTVP434PA9VFXSW2JKB3392D" ), bucket .ErrKeyPermissionDenied )
2050
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , bucket .ErrKeyPermissionDenied )
2051
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , bucket .ErrKeyPermissionDenied )
2052
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" , mockBlockMetaJSON ("01DTW0ZCPDDNV4BV83Q2SV4QAZ" ), bucket .ErrKeyPermissionDenied )
2053
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/deletion-mark.json" , "" , bucket .ErrKeyPermissionDenied )
2054
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/no-compact-mark.json" , "" , bucket .ErrKeyPermissionDenied )
2055
+ bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
2056
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , string (content ), nil )
2057
+ bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
2058
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
2059
+
2060
+ ringStore , closer := consul .NewInMemoryClient (ring .GetCodec (), log .NewNopLogger (), nil )
2061
+ t .Cleanup (func () { assert .NoError (t , closer .Close ()) })
2062
+
2063
+ cfg := prepareConfig ()
2064
+ cfg .ShardingEnabled = true
2065
+ cfg .ShardingRing .InstanceID = "compactor-1"
2066
+ cfg .ShardingRing .InstanceAddr = "1.2.3.4"
2067
+ cfg .ShardingRing .KVStore .Mock = ringStore
2068
+
2069
+ c , _ , tsdbPlanner , _ , _ := prepare (t , cfg , bucketClient , nil )
2070
+ tsdbPlanner .On ("Plan" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return ([]* metadata.Meta {}, nil )
2071
+
2072
+ require .NoError (t , services .StartAndAwaitRunning (context .Background (), c ))
2073
+
2074
+ // Wait until a run has completed.
2075
+ cortex_testutil .Poll (t , 20 * time .Second , 1.0 , func () interface {} {
2076
+ return prom_testutil .ToFloat64 (c .compactionRunsCompleted )
2077
+ })
2078
+
2079
+ require .NoError (t , services .StopAndAwaitTerminated (context .Background (), c ))
2080
+ }
2081
+
2082
+ func TestCompactor_ShouldNotFailCompactionIfAccessDeniedErrReturnedFromBucket (t * testing.T ) {
2083
+ t .Parallel ()
2084
+
2085
+ ss := bucketindex.Status {Status : bucketindex .Ok , Version : bucketindex .SyncStatusFileVersion }
2086
+ content , err := json .Marshal (ss )
2087
+ require .NoError (t , err )
2088
+
2089
+ bucketClient := & bucket.ClientMock {}
2090
+ bucketClient .MockIter ("__markers__" , []string {}, nil )
2091
+ bucketClient .MockIter ("" , []string {"user-1" }, nil )
2092
+ bucketClient .MockIter ("user-1/" , []string {"user-1/01DTVP434PA9VFXSW2JKB3392D" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" }, nil )
2093
+ bucketClient .MockIter ("user-1/markers/" , nil , nil )
2094
+ bucketClient .MockGet ("user-1/markers/cleaner-visit-marker.json" , "" , nil )
2095
+ bucketClient .MockUpload ("user-1/markers/cleaner-visit-marker.json" , nil )
2096
+ bucketClient .MockDelete ("user-1/markers/cleaner-visit-marker.json" , nil )
2097
+ bucketClient .MockExists (cortex_tsdb .GetGlobalDeletionMarkPath ("user-1" ), false , nil )
2098
+ bucketClient .MockExists (cortex_tsdb .GetLocalDeletionMarkPath ("user-1" ), false , nil )
2099
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , mockBlockMetaJSON ("01DTVP434PA9VFXSW2JKB3392D" ), nil )
2100
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
2101
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , nil )
2102
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" , mockBlockMetaJSON ("01DTW0ZCPDDNV4BV83Q2SV4QAZ" ), nil )
2103
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/deletion-mark.json" , "" , nil )
2104
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/no-compact-mark.json" , "" , nil )
2105
+ bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
2106
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , string (content ), nil )
2107
+ bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
2108
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
2109
+
2110
+ ringStore , closer := consul .NewInMemoryClient (ring .GetCodec (), log .NewNopLogger (), nil )
2111
+ t .Cleanup (func () { assert .NoError (t , closer .Close ()) })
2112
+
2113
+ cfg := prepareConfig ()
2114
+ cfg .ShardingEnabled = true
2115
+ cfg .ShardingRing .InstanceID = "compactor-1"
2116
+ cfg .ShardingRing .InstanceAddr = "1.2.3.4"
2117
+ cfg .ShardingRing .KVStore .Mock = ringStore
2118
+
2119
+ c , _ , tsdbPlanner , _ , _ := prepare (t , cfg , bucketClient , nil )
2120
+ tsdbPlanner .On ("Plan" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return ([]* metadata.Meta {}, bucket .ErrKeyPermissionDenied )
2121
+
2122
+ require .NoError (t , services .StartAndAwaitRunning (context .Background (), c ))
2123
+
2124
+ // Wait until a run has completed.
2125
+ cortex_testutil .Poll (t , 20 * time .Second , 1.0 , func () interface {} {
2126
+ return prom_testutil .ToFloat64 (c .compactionRunsCompleted )
2127
+ })
2128
+
2129
+ require .NoError (t , services .StopAndAwaitTerminated (context .Background (), c ))
2130
+ }
0 commit comments