@@ -13,6 +13,7 @@ import (
1313 "github.com/go-kit/log"
1414 "github.com/pkg/errors"
1515 "github.com/prometheus/client_golang/prometheus"
16+ "github.com/stretchr/testify/require"
1617 "github.com/thanos-io/objstore"
1718 "github.com/thanos-io/thanos/pkg/block/metadata"
1819 "github.com/thanos-io/thanos/pkg/compact/downsample"
@@ -21,7 +22,7 @@ import (
2122func TestPreCompactionCallback (t * testing.T ) {
2223 reg := prometheus .NewRegistry ()
2324 logger := log .NewNopLogger ()
24- callback := NewOverlappingCompactionLifecycleCallback (reg , true )
25+ callback := NewOverlappingCompactionLifecycleCallback (reg , logger , true )
2526 for _ , tcase := range []struct {
2627 testName string
2728 input []* metadata.Meta
@@ -145,6 +146,57 @@ func TestPreCompactionCallback(t *testing.T) {
145146 }
146147}
147148
149+ func TestHandleError (t * testing.T ) {
150+ reg := prometheus .NewRegistry ()
151+ logger := log .NewNopLogger ()
152+ callback := NewOverlappingCompactionLifecycleCallback (reg , logger , true )
153+ for _ , tcase := range []struct {
154+ testName string
155+ input []* metadata.Meta
156+ err error
157+ handledErrs int
158+ errBlockIdx int
159+ }{
160+ {
161+ testName : "empty error" ,
162+ input : []* metadata.Meta {},
163+ },
164+ {
165+ testName : "non empty error but not handled" ,
166+ input : []* metadata.Meta {
167+ createCustomBlockMeta (1 , 1 , 2 , metadata .ReceiveSource , 1 ),
168+ createCustomBlockMeta (2 , 1 , 6 , metadata .CompactorSource , 1 ),
169+ },
170+ err : errors .New ("some error" ),
171+ handledErrs : 0 ,
172+ },
173+ {
174+ testName : "non empty error symbol table size exceeds" ,
175+ input : []* metadata.Meta {
176+ createCustomBlockMeta (1 , 1 , 2 , metadata .ReceiveSource , 1 ),
177+ createCustomBlockMeta (2 , 1 , 6 , metadata .CompactorSource , 1 ),
178+ createCustomBlockMeta (3 , 1 , 6 , metadata .ReceiveSource , 1024 * 1024 ),
179+ },
180+ err : errors .New (symbolTableSizeExceedsError + " 1024*1024" ),
181+ handledErrs : 1 ,
182+ errBlockIdx : 2 ,
183+ },
184+ } {
185+ t .Run (tcase .testName , func (t * testing.T ) {
186+ ctx := context .Background ()
187+ bkt := objstore .NewInMemBucket ()
188+ group := & Group {logger : log .NewNopLogger (), bkt : bkt }
189+ require .Equal (t , tcase .handledErrs , callback .HandleError (ctx , logger , group , tcase .input , tcase .err ))
190+ if tcase .handledErrs > 0 {
191+ for i := 0 ; i < len (tcase .input ); i ++ {
192+ ok , _ := bkt .Exists (ctx , path .Join (tcase .input [i ].ULID .String (), metadata .NoCompactMarkFilename ))
193+ require .Equal (t , i == tcase .errBlockIdx , ok )
194+ }
195+ }
196+ })
197+ }
198+ }
199+
148200func createCustomBlockMeta (id uint64 , minTime , maxTime int64 , source metadata.SourceType , numSeries uint64 ) * metadata.Meta {
149201 labels := map [string ]string {"a" : "1" }
150202 m := createBlockMeta (id , minTime , maxTime , labels , downsample .ResLevel0 , []uint64 {})
0 commit comments