Repository: cortexproject/cortex (Go)

Issue:
Compactor meta fetcher metrics have wrong prefix
**Describe the bug**
When defining meta fetcher metrics in Cortex compactor, we keep the metric subsystem name as `blocks_meta`.https://github.com/cortexproject/cortex/blob/be90c4a9fe34f94b412dfcce6712dcce90243e8f/pkg/compactor/compactor_metrics.go#L77-L81

We should remove the subsystem as those compactor metrics have prefix of `blocks_meta`. The expectation should be those metric have prefix `cortex_compactor`. So instead of the metric name being `blocks_meta_cortex_compactor_meta_base_syncs_total`, the correct metric name should be `cortex_compactor_meta_base_syncs_total`.

<img width="1883" alt="Image" src="https://github.com/user-attachments/assets/b28bf9fc-72ec-47cc-8c53-60452d370c1b" />


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8195eb8b52..ad649752754 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,6 +59,7 @@
 * [BUGFIX] Fix race condition in active user. #6773
 * [BUGFIX] Ruler: Prevent counting 2xx and 4XX responses as failed writes. #6785
 * [BUGFIX] Ingester: Allow shipper to skip corrupted blocks. #6786
+* [BUGFIX] Compactor: Delete the prefix `blocks_meta` from the metadata fetcher metrics. #6832
 
 ## 1.19.0 2025-02-27
 
diff --git a/pkg/compactor/compactor_metrics.go b/pkg/compactor/compactor_metrics.go
index 03d4686ee1c..6c7f9c14087 100644
--- a/pkg/compactor/compactor_metrics.go
+++ b/pkg/compactor/compactor_metrics.go
@@ -75,34 +75,29 @@ func newCompactorMetricsWithLabels(reg prometheus.Registerer, commonLabels []str
 
 	// Copied from Thanos, pkg/block/fetcher.go
 	m.baseFetcherSyncs = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
-		Subsystem: block.FetcherSubSys,
-		Name:      "cortex_compactor_meta_base_syncs_total",
-		Help:      "Total blocks metadata synchronization attempts by base Fetcher.",
+		Name: "cortex_compactor_meta_base_syncs_total",
+		Help: "Total blocks metadata synchronization attempts by base Fetcher.",
 	}, nil)
 
 	// Copied from Thanos, pkg/block/fetcher.go
 	m.metaFetcherSyncs = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
-		Subsystem: block.FetcherSubSys,
-		Name:      "cortex_compactor_meta_syncs_total",
-		Help:      "Total blocks metadata synchronization attempts.",
+		Name: "cortex_compactor_meta_syncs_total",
+		Help: "Total blocks metadata synchronization attempts.",
 	}, nil)
 	m.metaFetcherSyncFailures = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
-		Subsystem: block.FetcherSubSys,
-		Name:      "cortex_compactor_meta_sync_failures_total",
-		Help:      "Total blocks metadata synchronization failures.",
+		Name: "cortex_compactor_meta_sync_failures_total",
+		Help: "Total blocks metadata synchronization failures.",
 	}, nil)
 	m.metaFetcherSyncDuration = promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
-		Subsystem: block.FetcherSubSys,
-		Name:      "cortex_compactor_meta_sync_duration_seconds",
-		Help:      "Duration of the blocks metadata synchronization in seconds.",
-		Buckets:   []float64{0.01, 1, 10, 100, 300, 600, 1000},
+		Name:    "cortex_compactor_meta_sync_duration_seconds",
+		Help:    "Duration of the blocks metadata synchronization in seconds.",
+		Buckets: []float64{0.01, 1, 10, 100, 300, 600, 1000},
 	}, nil)
 	m.metaFetcherSynced = extprom.NewTxGaugeVec(
 		reg,
 		prometheus.GaugeOpts{
-			Subsystem: block.FetcherSubSys,
-			Name:      "cortex_compactor_meta_synced",
-			Help:      "Number of block metadata synced",
+			Name: "cortex_compactor_meta_synced",
+			Help: "Number of block metadata synced",
 		},
 		[]string{"state"},
 		block.DefaultSyncedStateLabelValues()...,
@@ -110,9 +105,8 @@ func newCompactorMetricsWithLabels(reg prometheus.Registerer, commonLabels []str
 	m.metaFetcherModified = extprom.NewTxGaugeVec(
 		reg,
 		prometheus.GaugeOpts{
-			Subsystem: block.FetcherSubSys,
-			Name:      "cortex_compactor_meta_modified",
-			Help:      "Number of blocks whose metadata changed",
+			Name: "cortex_compactor_meta_modified",
+			Help: "Number of blocks whose metadata changed",
 		},
 		[]string{"modified"},
 		block.DefaultModifiedLabelValues()...,


Test patch:
diff --git a/pkg/compactor/compactor_metrics_test.go b/pkg/compactor/compactor_metrics_test.go
index b0e212962cc..75879f2d96a 100644
--- a/pkg/compactor/compactor_metrics_test.go
+++ b/pkg/compactor/compactor_metrics_test.go
@@ -18,42 +18,42 @@ func TestCompactorMetrics(t *testing.T) {
 	generateTestData(cm, 2222)
 
 	err := testutil.GatherAndCompare(reg, bytes.NewBufferString(`
-			# HELP blocks_meta_cortex_compactor_meta_base_syncs_total Total blocks metadata synchronization attempts by base Fetcher.
-			# TYPE blocks_meta_cortex_compactor_meta_base_syncs_total counter
-			blocks_meta_cortex_compactor_meta_base_syncs_total 11110
-			# HELP blocks_meta_cortex_compactor_meta_modified Number of blocks whose metadata changed
-			# TYPE blocks_meta_cortex_compactor_meta_modified gauge
-			blocks_meta_cortex_compactor_meta_modified{modified="replica-label-removed"} 0
-			# HELP blocks_meta_cortex_compactor_meta_sync_duration_seconds Duration of the blocks metadata synchronization in seconds.
-			# TYPE blocks_meta_cortex_compactor_meta_sync_duration_seconds histogram
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="0.01"} 0
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="1"} 2
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="10"} 3
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="100"} 3
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="300"} 3
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="600"} 3
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="1000"} 3
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_bucket{le="+Inf"} 3
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_sum 4.444
-			blocks_meta_cortex_compactor_meta_sync_duration_seconds_count 3
-			# HELP blocks_meta_cortex_compactor_meta_sync_failures_total Total blocks metadata synchronization failures.
-			# TYPE blocks_meta_cortex_compactor_meta_sync_failures_total counter
-			blocks_meta_cortex_compactor_meta_sync_failures_total 33330
-			# HELP blocks_meta_cortex_compactor_meta_synced Number of block metadata synced
-			# TYPE blocks_meta_cortex_compactor_meta_synced gauge
-			blocks_meta_cortex_compactor_meta_synced{state="corrupted-meta-json"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="duplicate"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="failed"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="label-excluded"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="loaded"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="marked-for-deletion"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="marked-for-no-compact"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="no-meta-json"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="time-excluded"} 0
-			blocks_meta_cortex_compactor_meta_synced{state="too-fresh"} 0
-			# HELP blocks_meta_cortex_compactor_meta_syncs_total Total blocks metadata synchronization attempts.
-			# TYPE blocks_meta_cortex_compactor_meta_syncs_total counter
-			blocks_meta_cortex_compactor_meta_syncs_total 22220
+			# HELP cortex_compactor_meta_base_syncs_total Total blocks metadata synchronization attempts by base Fetcher.
+			# TYPE cortex_compactor_meta_base_syncs_total counter
+			cortex_compactor_meta_base_syncs_total 11110
+			# HELP cortex_compactor_meta_modified Number of blocks whose metadata changed
+			# TYPE cortex_compactor_meta_modified gauge
+			cortex_compactor_meta_modified{modified="replica-label-removed"} 0
+			# HELP cortex_compactor_meta_sync_duration_seconds Duration of the blocks metadata synchronization in seconds.
+			# TYPE cortex_compactor_meta_sync_duration_seconds histogram
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="0.01"} 0
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="1"} 2
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="10"} 3
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="100"} 3
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="300"} 3
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="600"} 3
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="1000"} 3
+			cortex_compactor_meta_sync_duration_seconds_bucket{le="+Inf"} 3
+			cortex_compactor_meta_sync_duration_seconds_sum 4.444
+			cortex_compactor_meta_sync_duration_seconds_count 3
+			# HELP cortex_compactor_meta_sync_failures_total Total blocks metadata synchronization failures.
+			# TYPE cortex_compactor_meta_sync_failures_total counter
+			cortex_compactor_meta_sync_failures_total 33330
+			# HELP cortex_compactor_meta_synced Number of block metadata synced
+			# TYPE cortex_compactor_meta_synced gauge
+			cortex_compactor_meta_synced{state="corrupted-meta-json"} 0
+			cortex_compactor_meta_synced{state="duplicate"} 0
+			cortex_compactor_meta_synced{state="failed"} 0
+			cortex_compactor_meta_synced{state="label-excluded"} 0
+			cortex_compactor_meta_synced{state="loaded"} 0
+			cortex_compactor_meta_synced{state="marked-for-deletion"} 0
+			cortex_compactor_meta_synced{state="marked-for-no-compact"} 0
+			cortex_compactor_meta_synced{state="no-meta-json"} 0
+			cortex_compactor_meta_synced{state="time-excluded"} 0
+			cortex_compactor_meta_synced{state="too-fresh"} 0
+			# HELP cortex_compactor_meta_syncs_total Total blocks metadata synchronization attempts.
+			# TYPE cortex_compactor_meta_syncs_total counter
+			cortex_compactor_meta_syncs_total 22220
 			# HELP cortex_compact_group_compaction_planned_total Total number of compaction planned.
 			# TYPE cortex_compact_group_compaction_planned_total counter
 			cortex_compact_group_compaction_planned_total{user="aaa"} 211090