@@ -176,6 +176,7 @@ func runCompact(
176176) (rerr error ) {
177177 deleteDelay := time .Duration (conf .deleteDelay )
178178 compactMetrics := newCompactMetrics (reg , deleteDelay )
179+ progressRegistry := compact .NewProgressRegistry (reg , logger )
179180 downsampleMetrics := newDownsampleMetrics (reg )
180181
181182 httpProbe := prober .NewHTTP ()
@@ -444,14 +445,16 @@ func runCompact(
444445
445446 var cleanMtx sync.Mutex
446447 // TODO(GiedriusS): we could also apply retention policies here but the logic would be a bit more complex.
447- cleanPartialMarked := func () error {
448+ cleanPartialMarked := func (progress * compact. Progress ) error {
448449 cleanMtx .Lock ()
449450 defer cleanMtx .Unlock ()
450-
451+ defer progress .Idle ()
452+ progress .Set (compact .SyncMeta )
451453 if err := sy .SyncMetas (ctx ); err != nil {
452454 return errors .Wrap (err , "syncing metas" )
453455 }
454456
457+ progress .Set (compact .CleanBlocks )
455458 compact .BestEffortCleanAbortedPartialUploads (ctx , logger , sy .Partial (), insBkt , compactMetrics .partialUploadDeleteAttempts , compactMetrics .blocksCleaned , compactMetrics .blockCleanupFailures )
456459 if err := blocksCleaner .DeleteMarkedBlocks (ctx ); err != nil {
457460 return errors .Wrap (err , "cleaning marked blocks" )
@@ -461,19 +464,23 @@ func runCompact(
461464 return nil
462465 }
463466
464- compactMainFn := func () error {
467+ compactMainFn := func (progress * compact.Progress ) error {
468+ defer progress .Idle ()
465469 // this should happen before any compaction to remove unnecessary process on backlogs beyond retention.
466470 if len (retentionByTenant ) != 0 && len (sy .Metas ()) == 0 {
467471 level .Info (logger ).Log ("msg" , "sync before tenant retention due to no blocks" )
472+ progress .Set (compact .SyncMeta )
468473 if err := sy .SyncMetas (ctx ); err != nil {
469474 return errors .Wrap (err , "sync before tenant retention" )
470475 }
471476 }
477+
478+ progress .Set (compact .ApplyRetention )
472479 if err := compact .ApplyRetentionPolicyByTenant (ctx , logger , insBkt , sy .Metas (), retentionByTenant , compactMetrics .blocksMarked .WithLabelValues (metadata .DeletionMarkFilename , metadata .TenantRetentionExpired )); err != nil {
473480 return errors .Wrap (err , "retention by tenant failed" )
474481 }
475482
476- if err := compactor .Compact (ctx ); err != nil {
483+ if err := compactor .Compact (ctx , progress ); err != nil {
477484 return errors .Wrap (err , "whole compaction error" )
478485 }
479486
@@ -482,10 +489,11 @@ func runCompact(
482489 // We run two passes of this to ensure that the 1h downsampling is generated
483490 // for 5m downsamplings created in the first run.
484491 level .Info (logger ).Log ("msg" , "start first pass of downsampling" )
492+ progress .Set (compact .SyncMeta )
485493 if err := sy .SyncMetas (ctx ); err != nil {
486494 return errors .Wrap (err , "sync before first pass of downsampling" )
487495 }
488-
496+ progress . Set ( compact . DownSampling )
489497 filteredMetas := sy .Metas ()
490498 noDownsampleBlocks := noDownsampleMarkerFilter .NoDownsampleMarkedBlocks ()
491499 for ul := range noDownsampleBlocks {
@@ -514,6 +522,7 @@ func runCompact(
514522 }
515523
516524 level .Info (logger ).Log ("msg" , "start second pass of downsampling" )
525+ progress .Set (compact .SyncMeta )
517526 if err := sy .SyncMetas (ctx ); err != nil {
518527 return errors .Wrap (err , "sync before second pass of downsampling" )
519528 }
@@ -547,27 +556,29 @@ func runCompact(
547556 }
548557
549558 // TODO(bwplotka): Find a way to avoid syncing if no op was done.
559+ progress .Set (compact .SyncMeta )
550560 if err := sy .SyncMetas (ctx ); err != nil {
551561 return errors .Wrap (err , "sync before retention" )
552562 }
553563
564+ progress .Set (compact .ApplyRetention )
554565 if err := compact .ApplyRetentionPolicyByResolution (ctx , logger , insBkt , sy .Metas (), retentionByResolution , compactMetrics .blocksMarked .WithLabelValues (metadata .DeletionMarkFilename , "" )); err != nil {
555566 return errors .Wrap (err , "retention failed" )
556567 }
557568
558- return cleanPartialMarked ()
569+ return cleanPartialMarked (progress )
559570 }
560571
561572 g .Add (func () error {
562573 defer runutil .CloseWithLogOnErr (logger , insBkt , "bucket client" )
563574
564575 if ! conf .wait {
565- return compactMainFn ()
576+ return compactMainFn (progressRegistry . Get ( compact . Main ) )
566577 }
567578
568579 // --wait=true is specified.
569580 return runutil .Repeat (conf .waitInterval , ctx .Done (), func () error {
570- err := compactMainFn ()
581+ err := compactMainFn (progressRegistry . Get ( compact . Main ) )
571582 if err == nil {
572583 compactMetrics .iterations .Inc ()
573584 return nil
@@ -633,9 +644,11 @@ func runCompact(
633644 // For /global state make sure to fetch periodically.
634645 return runutil .Repeat (conf .blockViewerSyncBlockInterval , ctx .Done (), func () error {
635646 return runutil .RetryWithLog (logger , time .Minute , ctx .Done (), func () error {
647+ progress := progressRegistry .Get (compact .Web )
648+ defer progress .Idle ()
636649 iterCtx , iterCancel := context .WithTimeout (ctx , conf .blockViewerSyncBlockTimeout )
637650 defer iterCancel ()
638-
651+ progress . Set ( compact . SyncMeta )
639652 _ , _ , err := f .Fetch (iterCtx )
640653 return err
641654 })
@@ -650,7 +663,7 @@ func runCompact(
650663 if conf .cleanupBlocksInterval > 0 {
651664 g .Add (func () error {
652665 return runutil .Repeat (conf .cleanupBlocksInterval , ctx .Done (), func () error {
653- err := cleanPartialMarked ()
666+ err := cleanPartialMarked (progressRegistry . Get ( compact . Cleanup ) )
654667 if err != nil && compact .IsRetryError (err ) {
655668 // The RetryError signals that we hit an retriable error (transient error, no connection).
656669 // You should alert on this being triggered too frequently.
@@ -678,7 +691,9 @@ func runCompact(
678691 }
679692
680693 return runutil .Repeat (conf .progressCalculateInterval , ctx .Done (), func () error {
681-
694+ progress := progressRegistry .Get (compact .Calculate )
695+ defer progress .Idle ()
696+ progress .Set (compact .SyncMeta )
682697 if err := sy .SyncMetas (ctx ); err != nil {
683698 // The RetryError signals that we hit an retriable error (transient error, no connection).
684699 // You should alert on this being triggered too frequently.
@@ -693,29 +708,34 @@ func runCompact(
693708 }
694709
695710 metas := sy .Metas ()
711+ progress .Set (compact .Grouping )
696712 groups , err := grouper .Groups (metas )
697713 if err != nil {
698714 return errors .Wrapf (err , "could not group metadata for compaction" )
699715 }
700-
716+ progress . Set ( compact . CalculateProgress )
701717 if err = ps .ProgressCalculate (ctx , groups ); err != nil {
702718 return errors .Wrapf (err , "could not calculate compaction progress" )
703719 }
704720
721+ progress .Set (compact .Grouping )
705722 retGroups , err := grouper .Groups (metas )
706723 if err != nil {
707724 return errors .Wrapf (err , "could not group metadata for retention" )
708725 }
709726
727+ progress .Set (compact .CalculateProgress )
710728 if err = rs .ProgressCalculate (ctx , retGroups ); err != nil {
711729 return errors .Wrapf (err , "could not calculate retention progress" )
712730 }
713731
714732 if ! conf .disableDownsampling {
733+ progress .Set (compact .Grouping )
715734 groups , err = grouper .Groups (metas )
716735 if err != nil {
717736 return errors .Wrapf (err , "could not group metadata into downsample groups" )
718737 }
738+ progress .Set (compact .CalculateProgress )
719739 if err := ds .ProgressCalculate (ctx , groups ); err != nil {
720740 return errors .Wrapf (err , "could not calculate downsampling progress" )
721741 }
0 commit comments