@@ -1615,8 +1615,8 @@ func (m *tsdbPlannerMock) getNoCompactBlocks() []string {
1615
1615
return result
1616
1616
}
1617
1617
1618
- func mockBlockMetaJSON (id string ) string {
1619
- meta := tsdb.BlockMeta {
1618
+ func mockBlockMeta (id string ) tsdb. BlockMeta {
1619
+ return tsdb.BlockMeta {
1620
1620
Version : 1 ,
1621
1621
ULID : ulid .MustParse (id ),
1622
1622
MinTime : 1574776800000 ,
@@ -1626,6 +1626,10 @@ func mockBlockMetaJSON(id string) string {
1626
1626
Sources : []ulid.ULID {ulid .MustParse (id )},
1627
1627
},
1628
1628
}
1629
+ }
1630
+
1631
+ func mockBlockMetaJSON (id string ) string {
1632
+ meta := mockBlockMeta (id )
1629
1633
1630
1634
content , err := json .Marshal (meta )
1631
1635
if err != nil {
@@ -1988,3 +1992,105 @@ func TestCompactor_ShouldNotFailCompactionIfAccessDeniedErrReturnedFromBucket(t
1988
1992
1989
1993
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), c ))
1990
1994
}
1995
+
1996
+ func TestCompactor_FailedWithRetriableError (t * testing.T ) {
1997
+ t .Parallel ()
1998
+
1999
+ ss := bucketindex.Status {Status : bucketindex .Ok , Version : bucketindex .SyncStatusFileVersion }
2000
+ content , err := json .Marshal (ss )
2001
+ require .NoError (t , err )
2002
+
2003
+ bucketClient := & bucket.ClientMock {}
2004
+ bucketClient .MockIter ("__markers__" , []string {}, nil )
2005
+ bucketClient .MockIter ("" , []string {"user-1" }, nil )
2006
+ bucketClient .MockIter ("user-1/" , []string {"user-1/01DTVP434PA9VFXSW2JKB3392D" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" }, nil )
2007
+ bucketClient .MockIter ("user-1/markers/" , nil , nil )
2008
+ bucketClient .MockExists (cortex_tsdb .GetGlobalDeletionMarkPath ("user-1" ), false , nil )
2009
+ bucketClient .MockExists (cortex_tsdb .GetLocalDeletionMarkPath ("user-1" ), false , nil )
2010
+ bucketClient .MockIter ("user-1/01DTVP434PA9VFXSW2JKB3392D" , nil , errors .New ("test retriable error" ))
2011
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , mockBlockMetaJSON ("01DTVP434PA9VFXSW2JKB3392D" ), nil )
2012
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
2013
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , nil )
2014
+ bucketClient .MockIter ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , nil , errors .New ("test retriable error" ))
2015
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" , mockBlockMetaJSON ("01DTW0ZCPDDNV4BV83Q2SV4QAZ" ), nil )
2016
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/deletion-mark.json" , "" , nil )
2017
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/no-compact-mark.json" , "" , nil )
2018
+ bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
2019
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , string (content ), nil )
2020
+ bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
2021
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
2022
+
2023
+ cfg := prepareConfig ()
2024
+ cfg .CompactionRetries = 2
2025
+
2026
+ c , _ , tsdbPlanner , _ , registry := prepare (t , cfg , bucketClient , nil )
2027
+ tsdbPlanner .On ("Plan" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return ([]* metadata.Meta {{BlockMeta : mockBlockMeta ("01DTVP434PA9VFXSW2JKB3392D" )}, {BlockMeta : mockBlockMeta ("01DTW0ZCPDDNV4BV83Q2SV4QAZ" )}}, nil )
2028
+
2029
+ require .NoError (t , services .StartAndAwaitRunning (context .Background (), c ))
2030
+
2031
+ cortex_testutil .Poll (t , 1 * time .Second , 2.0 , func () interface {} {
2032
+ return prom_testutil .ToFloat64 (c .compactorMetrics .compactionErrorsCount .WithLabelValues ("user-1" , retriableError ))
2033
+ })
2034
+
2035
+ require .NoError (t , services .StopAndAwaitTerminated (context .Background (), c ))
2036
+
2037
+ assert .NoError (t , prom_testutil .GatherAndCompare (registry , strings .NewReader (`
2038
+ # HELP cortex_compactor_compaction_error_total Total number of errors from compactions.
2039
+ # TYPE cortex_compactor_compaction_error_total counter
2040
+ cortex_compactor_compaction_error_total{type="retriable", user="user-1"} 2
2041
+ ` ),
2042
+ "cortex_compactor_compaction_retry_error_total" ,
2043
+ "cortex_compactor_compaction_error_total" ,
2044
+ ))
2045
+ }
2046
+
2047
+ func TestCompactor_FailedWithHaltError (t * testing.T ) {
2048
+ t .Parallel ()
2049
+
2050
+ ss := bucketindex.Status {Status : bucketindex .Ok , Version : bucketindex .SyncStatusFileVersion }
2051
+ content , err := json .Marshal (ss )
2052
+ require .NoError (t , err )
2053
+
2054
+ bucketClient := & bucket.ClientMock {}
2055
+ bucketClient .MockIter ("__markers__" , []string {}, nil )
2056
+ bucketClient .MockIter ("" , []string {"user-1" }, nil )
2057
+ bucketClient .MockIter ("user-1/" , []string {"user-1/01DTVP434PA9VFXSW2JKB3392D" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , "user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , "user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" }, nil )
2058
+ bucketClient .MockIter ("user-1/markers/" , nil , nil )
2059
+ bucketClient .MockExists (cortex_tsdb .GetGlobalDeletionMarkPath ("user-1" ), false , nil )
2060
+ bucketClient .MockExists (cortex_tsdb .GetLocalDeletionMarkPath ("user-1" ), false , nil )
2061
+ bucketClient .MockIter ("user-1/01DTVP434PA9VFXSW2JKB3392D" , nil , compact.HaltError {})
2062
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/meta.json" , mockBlockMetaJSON ("01DTVP434PA9VFXSW2JKB3392D" ), nil )
2063
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/deletion-mark.json" , "" , nil )
2064
+ bucketClient .MockGet ("user-1/01DTVP434PA9VFXSW2JKB3392D/no-compact-mark.json" , "" , nil )
2065
+ bucketClient .MockIter ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ" , nil , compact.HaltError {})
2066
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/meta.json" , mockBlockMetaJSON ("01DTW0ZCPDDNV4BV83Q2SV4QAZ" ), nil )
2067
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/deletion-mark.json" , "" , nil )
2068
+ bucketClient .MockGet ("user-1/01DTW0ZCPDDNV4BV83Q2SV4QAZ/no-compact-mark.json" , "" , nil )
2069
+ bucketClient .MockGet ("user-1/bucket-index.json.gz" , "" , nil )
2070
+ bucketClient .MockGet ("user-1/bucket-index-sync-status.json" , string (content ), nil )
2071
+ bucketClient .MockUpload ("user-1/bucket-index.json.gz" , nil )
2072
+ bucketClient .MockUpload ("user-1/bucket-index-sync-status.json" , nil )
2073
+
2074
+ cfg := prepareConfig ()
2075
+ cfg .CompactionRetries = 2
2076
+
2077
+ c , _ , tsdbPlanner , _ , registry := prepare (t , cfg , bucketClient , nil )
2078
+ tsdbPlanner .On ("Plan" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return ([]* metadata.Meta {{BlockMeta : mockBlockMeta ("01DTVP434PA9VFXSW2JKB3392D" )}, {BlockMeta : mockBlockMeta ("01DTW0ZCPDDNV4BV83Q2SV4QAZ" )}}, nil )
2079
+
2080
+ require .NoError (t , services .StartAndAwaitRunning (context .Background (), c ))
2081
+
2082
+ cortex_testutil .Poll (t , 1 * time .Second , 1.0 , func () interface {} {
2083
+ return prom_testutil .ToFloat64 (c .compactorMetrics .compactionErrorsCount .WithLabelValues ("user-1" , haltError ))
2084
+ })
2085
+
2086
+ require .NoError (t , services .StopAndAwaitTerminated (context .Background (), c ))
2087
+
2088
+ assert .NoError (t , prom_testutil .GatherAndCompare (registry , strings .NewReader (`
2089
+ # HELP cortex_compactor_compaction_error_total Total number of errors from compactions.
2090
+ # TYPE cortex_compactor_compaction_error_total counter
2091
+ cortex_compactor_compaction_error_total{type="halt", user="user-1"} 1
2092
+ ` ),
2093
+ "cortex_compactor_compaction_retry_error_total" ,
2094
+ "cortex_compactor_compaction_error_total" ,
2095
+ ))
2096
+ }
0 commit comments