Skip to content

Commit d613a65

Browse files
authored
storage/tsdb: extract per-tenant TSDBMetrics out of ingesters (#14363)
#### What this PR does This PR moves the per-tenant `TSDBMetrics` collector out of the `ingester` package to allow these metrics to be re-used in the block-builder (I've moved the changes in the `blockbuilder` package are to [a separate PR](#14364), to simplify the review). The changes here are aimed to be pure structural. I don't expect any changes in the existing metrics — currently testing that in a dev environment, and all relevant metrics look fine. --------- Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
1 parent a3a61fb commit d613a65

File tree

4 files changed

+410
-544
lines changed

4 files changed

+410
-544
lines changed

pkg/ingester/ingester.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ type Ingester struct {
330330

331331
costAttributionMgr *costattribution.Manager
332332

333-
tsdbMetrics *tsdbMetrics
333+
tsdbMetrics *mimir_tsdb.TSDBMetrics
334334

335335
forceCompactTrigger chan requestWithUsersAndCallback
336336
shipTrigger chan requestWithUsersAndCallback
@@ -387,7 +387,7 @@ func newIngester(cfg Config, limits *validation.Overrides, ingestersRing ring.Re
387387
replicationFactor.Set(int64(cfg.IngesterRing.ReplicationFactor))
388388
ringStoreName.Set(cfg.IngesterRing.KVStore.Store)
389389

390-
metrics := newTSDBMetrics(registerer, logger)
390+
metrics := mimir_tsdb.NewTSDBMetrics(prometheus.WrapRegistererWithPrefix("cortex_ingester_", registerer), logger)
391391

392392
return &Ingester{
393393
cfg: cfg,
@@ -414,7 +414,7 @@ func newIngester(cfg Config, limits *validation.Overrides, ingestersRing ring.Re
414414
MaxItems: cfg.BlocksStorageConfig.TSDB.HeadPostingsForMatchersCacheMaxItems,
415415
MaxBytes: cfg.BlocksStorageConfig.TSDB.HeadPostingsForMatchersCacheMaxBytes,
416416
Force: cfg.BlocksStorageConfig.TSDB.HeadPostingsForMatchersCacheForce,
417-
Metrics: metrics.headPostingsForMatchersCacheMetrics,
417+
Metrics: tsdb.NewPostingsForMatchersCacheMetrics(prometheus.WrapRegistererWithPrefix("cortex_ingester_tsdb_head_", registerer)),
418418
PostingsClonerFactory: lookupplan.ActualSelectedPostingsClonerFactory{},
419419
},
420420
),
@@ -428,7 +428,7 @@ func newIngester(cfg Config, limits *validation.Overrides, ingestersRing ring.Re
428428
MaxItems: cfg.BlocksStorageConfig.TSDB.BlockPostingsForMatchersCacheMaxItems,
429429
MaxBytes: cfg.BlocksStorageConfig.TSDB.BlockPostingsForMatchersCacheMaxBytes,
430430
Force: cfg.BlocksStorageConfig.TSDB.BlockPostingsForMatchersCacheForce,
431-
Metrics: metrics.blockPostingsForMatchersCacheMetrics,
431+
Metrics: tsdb.NewPostingsForMatchersCacheMetrics(prometheus.WrapRegistererWithPrefix("cortex_ingester_tsdb_block_", registerer)),
432432
PostingsClonerFactory: lookupplan.ActualSelectedPostingsClonerFactory{},
433433
},
434434
),
@@ -2839,7 +2839,7 @@ func (i *Ingester) createTSDB(userID string, walReplayConcurrency int) (*userTSD
28392839
}
28402840
}
28412841

2842-
i.tsdbMetrics.setRegistryForUser(userID, tsdbPromReg)
2842+
i.tsdbMetrics.SetRegistryForTenant(userID, tsdbPromReg)
28432843

28442844
if i.cfg.BlocksStorageConfig.TSDB.IndexLookupPlanning.Enabled {
28452845
// Generate initial statistics only after the TSDB has been opened and initialized.
@@ -3734,7 +3734,7 @@ func (i *Ingester) closeAndDeleteUserTSDBIfIdle(userID string) tsdbCloseCheckRes
37343734
}()
37353735

37363736
i.metrics.memUsers.Dec()
3737-
i.tsdbMetrics.removeRegistryForUser(userID)
3737+
i.tsdbMetrics.RemoveRegistryForTenant(userID)
37383738

37393739
i.deleteUserMetadata(userID)
37403740
i.metrics.deletePerUserMetrics(userID)
@@ -4418,7 +4418,7 @@ func (i *Ingester) UserRegistryHandler(w http.ResponseWriter, r *http.Request) {
44184418
return
44194419
}
44204420

4421-
reg := i.tsdbMetrics.regs.GetRegistryForTenant(userID)
4421+
reg := i.tsdbMetrics.RegistryForTenant(userID)
44224422
if reg == nil {
44234423
http.Error(w, "user registry not found", http.StatusNotFound)
44244424
return

0 commit comments

Comments
 (0)