@@ -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 ()
@@ -325,6 +326,7 @@ func runCompact(
325326
326327 ctx , cancel := context .WithCancel (context .Background ())
327328 ctx = tracing .ContextWithTracer (ctx , tracer )
329+ ctx = objstoretracing .ContextWithTracer (ctx , tracer ) // objstore tracing uses a different tracer key in context.
328330
329331 defer func () {
330332 if rerr != nil {
@@ -444,14 +446,16 @@ func runCompact(
444446
445447 var cleanMtx sync.Mutex
446448 // TODO(GiedriusS): we could also apply retention policies here but the logic would be a bit more complex.
447- cleanPartialMarked := func () error {
449+ cleanPartialMarked := func (progress * compact. Progress ) error {
448450 cleanMtx .Lock ()
449451 defer cleanMtx .Unlock ()
450-
452+ defer progress .Idle ()
453+ progress .Set (compact .SyncMeta )
451454 if err := sy .SyncMetas (ctx ); err != nil {
452455 return errors .Wrap (err , "syncing metas" )
453456 }
454457
458+ progress .Set (compact .CleanBlocks )
455459 compact .BestEffortCleanAbortedPartialUploads (ctx , logger , sy .Partial (), insBkt , compactMetrics .partialUploadDeleteAttempts , compactMetrics .blocksCleaned , compactMetrics .blockCleanupFailures )
456460 if err := blocksCleaner .DeleteMarkedBlocks (ctx ); err != nil {
457461 return errors .Wrap (err , "cleaning marked blocks" )
@@ -461,19 +465,23 @@ func runCompact(
461465 return nil
462466 }
463467
464- compactMainFn := func () error {
468+ compactMainFn := func (progress * compact.Progress ) error {
469+ defer progress .Idle ()
465470 // this should happen before any compaction to remove unnecessary process on backlogs beyond retention.
466471 if len (retentionByTenant ) != 0 && len (sy .Metas ()) == 0 {
467472 level .Info (logger ).Log ("msg" , "sync before tenant retention due to no blocks" )
473+ progress .Set (compact .SyncMeta )
468474 if err := sy .SyncMetas (ctx ); err != nil {
469475 return errors .Wrap (err , "sync before tenant retention" )
470476 }
471477 }
478+
479+ progress .Set (compact .ApplyRetention )
472480 if err := compact .ApplyRetentionPolicyByTenant (ctx , logger , insBkt , sy .Metas (), retentionByTenant , compactMetrics .blocksMarked .WithLabelValues (metadata .DeletionMarkFilename , metadata .TenantRetentionExpired )); err != nil {
473481 return errors .Wrap (err , "retention by tenant failed" )
474482 }
475483
476- if err := compactor .Compact (ctx ); err != nil {
484+ if err := compactor .Compact (ctx , progress ); err != nil {
477485 return errors .Wrap (err , "whole compaction error" )
478486 }
479487
@@ -482,10 +490,11 @@ func runCompact(
482490 // We run two passes of this to ensure that the 1h downsampling is generated
483491 // for 5m downsamplings created in the first run.
484492 level .Info (logger ).Log ("msg" , "start first pass of downsampling" )
493+ progress .Set (compact .SyncMeta )
485494 if err := sy .SyncMetas (ctx ); err != nil {
486495 return errors .Wrap (err , "sync before first pass of downsampling" )
487496 }
488-
497+ progress . Set ( compact . DownSampling )
489498 filteredMetas := sy .Metas ()
490499 noDownsampleBlocks := noDownsampleMarkerFilter .NoDownsampleMarkedBlocks ()
491500 for ul := range noDownsampleBlocks {
@@ -514,6 +523,7 @@ func runCompact(
514523 }
515524
516525 level .Info (logger ).Log ("msg" , "start second pass of downsampling" )
526+ progress .Set (compact .SyncMeta )
517527 if err := sy .SyncMetas (ctx ); err != nil {
518528 return errors .Wrap (err , "sync before second pass of downsampling" )
519529 }
@@ -547,27 +557,29 @@ func runCompact(
547557 }
548558
549559 // TODO(bwplotka): Find a way to avoid syncing if no op was done.
560+ progress .Set (compact .SyncMeta )
550561 if err := sy .SyncMetas (ctx ); err != nil {
551562 return errors .Wrap (err , "sync before retention" )
552563 }
553564
565+ progress .Set (compact .ApplyRetention )
554566 if err := compact .ApplyRetentionPolicyByResolution (ctx , logger , insBkt , sy .Metas (), retentionByResolution , compactMetrics .blocksMarked .WithLabelValues (metadata .DeletionMarkFilename , "" )); err != nil {
555567 return errors .Wrap (err , "retention failed" )
556568 }
557569
558- return cleanPartialMarked ()
570+ return cleanPartialMarked (progress )
559571 }
560572
561573 g .Add (func () error {
562574 defer runutil .CloseWithLogOnErr (logger , insBkt , "bucket client" )
563575
564576 if ! conf .wait {
565- return compactMainFn ()
577+ return compactMainFn (progressRegistry . Get ( compact . Main ) )
566578 }
567579
568580 // --wait=true is specified.
569581 return runutil .Repeat (conf .waitInterval , ctx .Done (), func () error {
570- err := compactMainFn ()
582+ err := compactMainFn (progressRegistry . Get ( compact . Main ) )
571583 if err == nil {
572584 compactMetrics .iterations .Inc ()
573585 return nil
@@ -633,9 +645,11 @@ func runCompact(
633645 // For /global state make sure to fetch periodically.
634646 return runutil .Repeat (conf .blockViewerSyncBlockInterval , ctx .Done (), func () error {
635647 return runutil .RetryWithLog (logger , time .Minute , ctx .Done (), func () error {
648+ progress := progressRegistry .Get (compact .Web )
649+ defer progress .Idle ()
636650 iterCtx , iterCancel := context .WithTimeout (ctx , conf .blockViewerSyncBlockTimeout )
637651 defer iterCancel ()
638-
652+ progress . Set ( compact . SyncMeta )
639653 _ , _ , err := f .Fetch (iterCtx )
640654 return err
641655 })
@@ -650,7 +664,7 @@ func runCompact(
650664 if conf .cleanupBlocksInterval > 0 {
651665 g .Add (func () error {
652666 return runutil .Repeat (conf .cleanupBlocksInterval , ctx .Done (), func () error {
653- err := cleanPartialMarked ()
667+ err := cleanPartialMarked (progressRegistry . Get ( compact . Cleanup ) )
654668 if err != nil && compact .IsRetryError (err ) {
655669 // The RetryError signals that we hit an retriable error (transient error, no connection).
656670 // You should alert on this being triggered too frequently.
@@ -678,7 +692,9 @@ func runCompact(
678692 }
679693
680694 return runutil .Repeat (conf .progressCalculateInterval , ctx .Done (), func () error {
681-
695+ progress := progressRegistry .Get (compact .Calculate )
696+ defer progress .Idle ()
697+ progress .Set (compact .SyncMeta )
682698 if err := sy .SyncMetas (ctx ); err != nil {
683699 // The RetryError signals that we hit an retriable error (transient error, no connection).
684700 // You should alert on this being triggered too frequently.
@@ -693,29 +709,34 @@ func runCompact(
693709 }
694710
695711 metas := sy .Metas ()
712+ progress .Set (compact .Grouping )
696713 groups , err := grouper .Groups (metas )
697714 if err != nil {
698715 return errors .Wrapf (err , "could not group metadata for compaction" )
699716 }
700-
717+ progress . Set ( compact . CalculateProgress )
701718 if err = ps .ProgressCalculate (ctx , groups ); err != nil {
702719 return errors .Wrapf (err , "could not calculate compaction progress" )
703720 }
704721
722+ progress .Set (compact .Grouping )
705723 retGroups , err := grouper .Groups (metas )
706724 if err != nil {
707725 return errors .Wrapf (err , "could not group metadata for retention" )
708726 }
709727
728+ progress .Set (compact .CalculateProgress )
710729 if err = rs .ProgressCalculate (ctx , retGroups ); err != nil {
711730 return errors .Wrapf (err , "could not calculate retention progress" )
712731 }
713732
714733 if ! conf .disableDownsampling {
734+ progress .Set (compact .Grouping )
715735 groups , err = grouper .Groups (metas )
716736 if err != nil {
717737 return errors .Wrapf (err , "could not group metadata into downsample groups" )
718738 }
739+ progress .Set (compact .CalculateProgress )
719740 if err := ds .ProgressCalculate (ctx , groups ); err != nil {
720741 return errors .Wrapf (err , "could not calculate downsampling progress" )
721742 }
0 commit comments