diff --git a/tsdb/compact.go b/tsdb/compact.go index 2e9e01e852..b66f7eed8f 100644 --- a/tsdb/compact.go +++ b/tsdb/compact.go @@ -169,6 +169,8 @@ type LeveledCompactorOptions struct { // EnableOverlappingCompaction enables compaction of overlapping blocks. In Prometheus it is always enabled. // It is useful for downstream projects like Mimir, Cortex, Thanos where they have a separate component that does compaction. EnableOverlappingCompaction bool + // Metrics is set of metrics for Compactor. By default, NewCompactorMetrics would be called to initialize metrics unless it is provided. + Metrics *CompactorMetrics } type PostingsDecoderFactory func(meta *BlockMeta) index.PostingsDecoder @@ -214,11 +216,14 @@ func NewLeveledCompactorWithOptions(ctx context.Context, r prometheus.Registerer if pe == nil { pe = index.EncodePostingsRaw } + if opts.Metrics == nil { + opts.Metrics = NewCompactorMetrics(r) + } return &LeveledCompactor{ ranges: ranges, chunkPool: pool, logger: l, - metrics: NewCompactorMetrics(r), + metrics: opts.Metrics, ctx: ctx, maxBlockChunkSegmentSize: maxBlockChunkSegmentSize, mergeFunc: mergeFunc,