Skip to content

Commit

Permalink
log compaction run total time from block download (#5739)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeya24 committed Sep 29, 2022
1 parent c766dfe commit 4d76444
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/compact/compact.go
Expand Up @@ -1009,7 +1009,8 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
uniqueSources := map[ulid.ULID]struct{}{}

// Once we have a plan we need to download the actual data.
begin := time.Now()
groupCompactionBegin := time.Now()
begin := groupCompactionBegin
g, errCtx := errgroup.WithContext(ctx)
g.SetLimit(cg.compactBlocksFetchConcurrency)

Expand Down Expand Up @@ -1061,12 +1062,13 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp

toCompactDirs = append(toCompactDirs, bdir)
}
sourceBlockStr := fmt.Sprintf("%v", toCompactDirs)

if err := g.Wait(); err != nil {
return false, ulid.ULID{}, err
}

level.Info(cg.logger).Log("msg", "downloaded and verified blocks; compacting blocks", "plan", fmt.Sprintf("%v", toCompactDirs), "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds())
level.Info(cg.logger).Log("msg", "downloaded and verified blocks; compacting blocks", "plan", sourceBlockStr, "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds())

begin = time.Now()
if err := tracing.DoInSpanWithErr(ctx, "compaction", func(ctx context.Context) (e error) {
Expand All @@ -1077,7 +1079,7 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
}
if compID == (ulid.ULID{}) {
// Prometheus compactor found that the compacted block would have no samples.
level.Info(cg.logger).Log("msg", "compacted block would have no samples, deleting source blocks", "blocks", fmt.Sprintf("%v", toCompactDirs))
level.Info(cg.logger).Log("msg", "compacted block would have no samples, deleting source blocks", "blocks", sourceBlockStr)
for _, meta := range toCompact {
if meta.Stats.NumSamples == 0 {
if err := cg.deleteBlock(meta.ULID, filepath.Join(dir, meta.ULID.String())); err != nil {
Expand All @@ -1093,7 +1095,7 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
cg.verticalCompactions.Inc()
}
level.Info(cg.logger).Log("msg", "compacted blocks", "new", compID,
"blocks", fmt.Sprintf("%v", toCompactDirs), "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds(), "overlapping_blocks", overlappingBlocks)
"blocks", sourceBlockStr, "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds(), "overlapping_blocks", overlappingBlocks)

bdir := filepath.Join(dir, compID.String())
index := filepath.Join(bdir, block.IndexFilename)
Expand Down Expand Up @@ -1150,6 +1152,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
}
cg.groupGarbageCollectedBlocks.Inc()
}

level.Info(cg.logger).Log("msg", "finished compacting blocks", "result_block", compID, "source_blocks", sourceBlockStr,
time.Since(groupCompactionBegin), "duration_ms", time.Since(groupCompactionBegin).Milliseconds())
return true, compID, nil
}

Expand Down

0 comments on commit 4d76444

Please sign in to comment.