Skip to content

Commit cd9707c

Browse files
committed
Creating new Metric cortex_compactor_blocks_marked_for_no_compaction_on_storage_total
1 parent 5958e20 commit cd9707c

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

pkg/compactor/blocks_cleaner.go

+18-11
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ type BlocksCleaner struct {
4545
lastOwnedUsers []string
4646

4747
// Metrics.
48-
runsStarted prometheus.Counter
49-
runsCompleted prometheus.Counter
50-
runsFailed prometheus.Counter
51-
runsLastSuccess prometheus.Gauge
52-
blocksCleanedTotal prometheus.Counter
53-
blocksFailedTotal prometheus.Counter
54-
blocksMarkedForDeletion prometheus.Counter
55-
tenantBlocks *prometheus.GaugeVec
56-
tenantMarkedBlocks *prometheus.GaugeVec
57-
tenantPartialBlocks *prometheus.GaugeVec
58-
tenantBucketIndexLastUpdate *prometheus.GaugeVec
48+
runsStarted prometheus.Counter
49+
runsCompleted prometheus.Counter
50+
runsFailed prometheus.Counter
51+
runsLastSuccess prometheus.Gauge
52+
blocksCleanedTotal prometheus.Counter
53+
blocksFailedTotal prometheus.Counter
54+
blocksMarkedForDeletion prometheus.Counter
55+
tenantBlocks *prometheus.GaugeVec
56+
tenantMarkedBlocks *prometheus.GaugeVec
57+
tenantPartialBlocks *prometheus.GaugeVec
58+
tenantBucketIndexLastUpdate *prometheus.GaugeVec
59+
blocksMarkedForNoCompactionOnStorage *prometheus.GaugeVec
5960
}
6061

6162
func NewBlocksCleaner(cfg BlocksCleanerConfig, bucketClient objstore.Bucket, usersScanner *cortex_tsdb.UsersScanner, cfgProvider ConfigProvider, logger log.Logger, reg prometheus.Registerer) *BlocksCleaner {
@@ -69,6 +70,10 @@ func NewBlocksCleaner(cfg BlocksCleanerConfig, bucketClient objstore.Bucket, use
6970
Name: "cortex_compactor_block_cleanup_started_total",
7071
Help: "Total number of blocks cleanup runs started.",
7172
}),
73+
blocksMarkedForNoCompactionOnStorage: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
74+
Name: "cortex_compactor_blocks_marked_for_no_compaction_on_storage_total",
75+
Help: "Total number of blocks marked for on storage.",
76+
}, []string{"user"}),
7277
runsCompleted: promauto.With(reg).NewCounter(prometheus.CounterOpts{
7378
Name: "cortex_compactor_block_cleanup_completed_total",
7479
Help: "Total number of blocks cleanup runs successfully completed.",
@@ -241,6 +246,7 @@ func (c *BlocksCleaner) deleteUserMarkedForDeletion(ctx context.Context, userID
241246
c.tenantBlocks.DeleteLabelValues(userID)
242247
c.tenantMarkedBlocks.DeleteLabelValues(userID)
243248
c.tenantPartialBlocks.DeleteLabelValues(userID)
249+
c.blocksMarkedForNoCompactionOnStorage.DeleteLabelValues(userID)
244250

245251
if deletedBlocks > 0 {
246252
level.Info(userLogger).Log("msg", "deleted blocks for tenant marked for deletion", "deletedBlocks", deletedBlocks)
@@ -331,6 +337,7 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userID string, firstRun b
331337
// Generate an updated in-memory version of the bucket index.
332338
w := bucketindex.NewUpdater(c.bucketClient, userID, c.cfgProvider, c.logger)
333339
idx, partials, err := w.UpdateIndex(ctx, idx)
340+
c.blocksMarkedForNoCompactionOnStorage.WithLabelValues(userID).Set(float64(idx.TotalBlocksBlocksMarkedForNoCompaction))
334341
if err != nil {
335342
return err
336343
}

pkg/storage/tsdb/bucketindex/index.go

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type Index struct {
4141
// UpdatedAt is a unix timestamp (seconds precision) of when the index has been updated
4242
// (written in the storage) the last time.
4343
UpdatedAt int64 `json:"updated_at"`
44+
45+
// TotalBlocksBlocksMarkedForNoCompaction is then number of blocks marked for no compaction
46+
TotalBlocksBlocksMarkedForNoCompaction int64 `json:"total_blocks_marked_for_no_compaction"`
4447
}
4548

4649
func (idx *Index) GetUpdatedAt() time.Time {

pkg/storage/tsdb/bucketindex/markers.go

+18
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ func IsBlockDeletionMarkFilename(name string) (ulid.ULID, bool) {
5151
return id, err == nil
5252
}
5353

54+
// IsBlockNoCompactMarkFilename returns whether the input filename matches the expected pattern
55+
// of block no compact markers stored in the markers location.
56+
func IsBlockNoCompactMarkFilename(name string) (ulid.ULID, bool) {
57+
parts := strings.SplitN(name, "-", 2)
58+
if len(parts) != 2 {
59+
return ulid.ULID{}, false
60+
}
61+
62+
// Ensure the 2nd part matches the block deletion mark filename.
63+
if parts[1] != metadata.NoCompactMarkFilename {
64+
return ulid.ULID{}, false
65+
}
66+
67+
// Ensure the 1st part is a valid block ID.
68+
id, err := ulid.Parse(filepath.Base(parts[0]))
69+
return id, err == nil
70+
}
71+
5472
// MigrateBlockDeletionMarksToGlobalLocation list all tenant's blocks and, for each of them, look for
5573
// a deletion mark in the block location. Found deletion marks are copied to the global markers location.
5674
// The migration continues on error and returns once all blocks have been checked.

pkg/storage/tsdb/bucketindex/markers_bucket_client.go

-10
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,3 @@ func (b *globalMarkersBucket) isMark(name string) (string, bool) {
148148

149149
return "", false
150150
}
151-
152-
func (b *globalMarkersBucket) isBlockDeletionMark(name string) (ulid.ULID, bool) {
153-
if path.Base(name) != metadata.DeletionMarkFilename {
154-
return ulid.ULID{}, false
155-
}
156-
157-
// Parse the block ID in the path. If there's not block ID, then it's not the per-block
158-
// deletion mark.
159-
return block.IsBlockDir(path.Dir(name))
160-
}

pkg/storage/tsdb/bucketindex/updater.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,17 @@ func (w *Updater) UpdateIndex(ctx context.Context, old *Index) (*Index, map[ulid
5757
return nil, nil, err
5858
}
5959

60-
blockDeletionMarks, err := w.updateBlockDeletionMarks(ctx, oldBlockDeletionMarks)
60+
blockDeletionMarks, totalBlocksBlocksMarkedForNoCompaction, err := w.updateBlockMarks(ctx, oldBlockDeletionMarks)
6161
if err != nil {
6262
return nil, nil, err
6363
}
6464

6565
return &Index{
66-
Version: IndexVersion1,
67-
Blocks: blocks,
68-
BlockDeletionMarks: blockDeletionMarks,
69-
UpdatedAt: time.Now().Unix(),
66+
Version: IndexVersion1,
67+
Blocks: blocks,
68+
BlockDeletionMarks: blockDeletionMarks,
69+
UpdatedAt: time.Now().Unix(),
70+
TotalBlocksBlocksMarkedForNoCompaction: totalBlocksBlocksMarkedForNoCompaction,
7071
}, partials, nil
7172
}
7273

@@ -163,19 +164,25 @@ func (w *Updater) updateBlockIndexEntry(ctx context.Context, id ulid.ULID) (*Blo
163164
return block, nil
164165
}
165166

166-
func (w *Updater) updateBlockDeletionMarks(ctx context.Context, old []*BlockDeletionMark) ([]*BlockDeletionMark, error) {
167+
func (w *Updater) updateBlockMarks(ctx context.Context, old []*BlockDeletionMark) ([]*BlockDeletionMark, int64, error) {
167168
out := make([]*BlockDeletionMark, 0, len(old))
168169
discovered := map[ulid.ULID]struct{}{}
170+
totalBlocksBlocksMarkedForNoCompaction := int64(0)
169171

170172
// Find all markers in the storage.
171173
err := w.bkt.Iter(ctx, MarkersPathname+"/", func(name string) error {
172174
if blockID, ok := IsBlockDeletionMarkFilename(path.Base(name)); ok {
173175
discovered[blockID] = struct{}{}
174176
}
177+
178+
if _, ok := IsBlockNoCompactMarkFilename(path.Base(name)); ok {
179+
totalBlocksBlocksMarkedForNoCompaction++
180+
}
181+
175182
return nil
176183
})
177184
if err != nil {
178-
return nil, errors.Wrap(err, "list block deletion marks")
185+
return nil, totalBlocksBlocksMarkedForNoCompaction, errors.Wrap(err, "list block deletion marks")
179186
}
180187

181188
// Since deletion marks are immutable, all markers already existing in the index can just be copied.
@@ -199,13 +206,13 @@ func (w *Updater) updateBlockDeletionMarks(ctx context.Context, old []*BlockDele
199206
continue
200207
}
201208
if err != nil {
202-
return nil, err
209+
return nil, totalBlocksBlocksMarkedForNoCompaction, err
203210
}
204211

205212
out = append(out, m)
206213
}
207214

208-
return out, nil
215+
return out, totalBlocksBlocksMarkedForNoCompaction, nil
209216
}
210217

211218
func (w *Updater) updateBlockDeletionMarkIndexEntry(ctx context.Context, id ulid.ULID) (*BlockDeletionMark, error) {

0 commit comments

Comments
 (0)