@@ -45,17 +45,18 @@ type BlocksCleaner struct {
4545 lastOwnedUsers []string
4646
4747 // Metrics.
48- runsStarted prometheus.Counter
49- runsCompleted prometheus.Counter
50- runsFailed prometheus.Counter
51- runsLastSuccess prometheus.Gauge
52- blocksCleanedTotal prometheus.Counter
53- blocksFailedTotal prometheus.Counter
54- blocksMarkedForDeletion prometheus.Counter
55- tenantBlocks * prometheus.GaugeVec
56- tenantMarkedBlocks * prometheus.GaugeVec
57- tenantPartialBlocks * prometheus.GaugeVec
58- tenantBucketIndexLastUpdate * prometheus.GaugeVec
48+ runsStarted prometheus.Counter
49+ runsCompleted prometheus.Counter
50+ runsFailed prometheus.Counter
51+ runsLastSuccess prometheus.Gauge
52+ blocksCleanedTotal prometheus.Counter
53+ blocksFailedTotal prometheus.Counter
54+ blocksMarkedForDeletion prometheus.Counter
55+ tenantBlocks * prometheus.GaugeVec
56+ tenantBlocksMarkedForDelete * prometheus.GaugeVec
57+ tenantBlocksMarkedForNoCompaction * prometheus.GaugeVec
58+ tenantPartialBlocks * prometheus.GaugeVec
59+ tenantBucketIndexLastUpdate * prometheus.GaugeVec
5960}
6061
6162func NewBlocksCleaner (cfg BlocksCleanerConfig , bucketClient objstore.Bucket , usersScanner * cortex_tsdb.UsersScanner , cfgProvider ConfigProvider , logger log.Logger , reg prometheus.Registerer ) * BlocksCleaner {
@@ -102,10 +103,14 @@ func NewBlocksCleaner(cfg BlocksCleanerConfig, bucketClient objstore.Bucket, use
102103 Name : "cortex_bucket_blocks_count" ,
103104 Help : "Total number of blocks in the bucket. Includes blocks marked for deletion, but not partial blocks." ,
104105 }, []string {"user" }),
105- tenantMarkedBlocks : promauto .With (reg ).NewGaugeVec (prometheus.GaugeOpts {
106+ tenantBlocksMarkedForDelete : promauto .With (reg ).NewGaugeVec (prometheus.GaugeOpts {
106107 Name : "cortex_bucket_blocks_marked_for_deletion_count" ,
107108 Help : "Total number of blocks marked for deletion in the bucket." ,
108109 }, []string {"user" }),
110+ tenantBlocksMarkedForNoCompaction : promauto .With (reg ).NewGaugeVec (prometheus.GaugeOpts {
111+ Name : "cortex_bucket_blocks_marked_for_no_compaction_count" ,
112+ Help : "Total number of blocks marked for no compaction in the bucket." ,
113+ }, []string {"user" }),
109114 tenantPartialBlocks : promauto .With (reg ).NewGaugeVec (prometheus.GaugeOpts {
110115 Name : "cortex_bucket_blocks_partials_count" ,
111116 Help : "Total number of partial blocks." ,
@@ -168,7 +173,8 @@ func (c *BlocksCleaner) cleanUsers(ctx context.Context, firstRun bool) error {
168173 for _ , userID := range c .lastOwnedUsers {
169174 if ! isActive [userID ] && ! isDeleted [userID ] {
170175 c .tenantBlocks .DeleteLabelValues (userID )
171- c .tenantMarkedBlocks .DeleteLabelValues (userID )
176+ c .tenantBlocksMarkedForDelete .DeleteLabelValues (userID )
177+ c .tenantBlocksMarkedForNoCompaction .DeleteLabelValues (userID )
172178 c .tenantPartialBlocks .DeleteLabelValues (userID )
173179 c .tenantBucketIndexLastUpdate .DeleteLabelValues (userID )
174180 }
@@ -231,15 +237,16 @@ func (c *BlocksCleaner) deleteUserMarkedForDeletion(ctx context.Context, userID
231237 // to delete. We also consider them all marked for deletion given the next run will try
232238 // to delete them again.
233239 c .tenantBlocks .WithLabelValues (userID ).Set (float64 (failed ))
234- c .tenantMarkedBlocks .WithLabelValues (userID ).Set (float64 (failed ))
240+ c .tenantBlocksMarkedForDelete .WithLabelValues (userID ).Set (float64 (failed ))
235241 c .tenantPartialBlocks .WithLabelValues (userID ).Set (0 )
236242
237243 return errors .Errorf ("failed to delete %d blocks" , failed )
238244 }
239245
240246 // Given all blocks have been deleted, we can also remove the metrics.
241247 c .tenantBlocks .DeleteLabelValues (userID )
242- c .tenantMarkedBlocks .DeleteLabelValues (userID )
248+ c .tenantBlocksMarkedForDelete .DeleteLabelValues (userID )
249+ c .tenantBlocksMarkedForNoCompaction .DeleteLabelValues (userID )
243250 c .tenantPartialBlocks .DeleteLabelValues (userID )
244251
245252 if deletedBlocks > 0 {
@@ -330,7 +337,7 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userID string, firstRun b
330337
331338 // Generate an updated in-memory version of the bucket index.
332339 w := bucketindex .NewUpdater (c .bucketClient , userID , c .cfgProvider , c .logger )
333- idx , partials , err := w .UpdateIndex (ctx , idx )
340+ idx , partials , totalBlocksBlocksMarkedForNoCompaction , err := w .UpdateIndex (ctx , idx )
334341 if err != nil {
335342 return err
336343 }
@@ -367,9 +374,10 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userID string, firstRun b
367374 }
368375
369376 c .tenantBlocks .WithLabelValues (userID ).Set (float64 (len (idx .Blocks )))
370- c .tenantMarkedBlocks .WithLabelValues (userID ).Set (float64 (len (idx .BlockDeletionMarks )))
371- c .tenantPartialBlocks .WithLabelValues (userID ).Set (float64 (len ( partials ) ))
377+ c .tenantBlocksMarkedForDelete .WithLabelValues (userID ).Set (float64 (len (idx .BlockDeletionMarks )))
378+ c .tenantBlocksMarkedForNoCompaction .WithLabelValues (userID ).Set (float64 (totalBlocksBlocksMarkedForNoCompaction ))
372379 c .tenantBucketIndexLastUpdate .WithLabelValues (userID ).SetToCurrentTime ()
380+ c .tenantPartialBlocks .WithLabelValues (userID ).Set (float64 (len (partials )))
373381
374382 return nil
375383}
0 commit comments