From bce72b93d91186785a675fcd45b5bca2669d30de Mon Sep 17 00:00:00 2001 From: Alex Le Date: Fri, 11 Apr 2025 01:17:45 -0700 Subject: [PATCH] tsdb: Introduced new constructor for LeveledCompactor to take in metrics (#16408) * Introduced new constructor for LeveledCompactor to take in metrics Signed-off-by: Alex Le * Added Metrics to LeveledCompactorOptions Signed-off-by: Alex Le --------- Signed-off-by: Alex Le --- tsdb/compact.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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,