diff --git a/pkg/chunk/table_manager.go b/pkg/chunk/table_manager.go index 383a4cf5da..7426f19f32 100644 --- a/pkg/chunk/table_manager.go +++ b/pkg/chunk/table_manager.go @@ -12,6 +12,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/common/model" tsdberrors "github.com/prometheus/prometheus/tsdb/errors" "github.com/weaveworks/common/instrument" @@ -38,46 +39,36 @@ type tableManagerMetrics struct { func newTableManagerMetrics(r prometheus.Registerer) *tableManagerMetrics { m := tableManagerMetrics{} - m.syncTableDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ + m.syncTableDuration = promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{ Namespace: "cortex", Name: "table_manager_sync_duration_seconds", Help: "Time spent synching tables.", Buckets: prometheus.DefBuckets, }, []string{"operation", "status_code"}) - m.tableCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + m.tableCapacity = promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{ Namespace: "cortex", Name: "table_capacity_units", Help: "Per-table capacity, measured in DynamoDB capacity units.", }, []string{"op", "table"}) - m.createFailures = prometheus.NewGauge(prometheus.GaugeOpts{ + m.createFailures = promauto.With(r).NewGauge(prometheus.GaugeOpts{ Namespace: "cortex", Name: "table_manager_create_failures", Help: "Number of table creation failures during the last table-manager reconciliation", }) - m.deleteFailures = prometheus.NewGauge(prometheus.GaugeOpts{ + m.deleteFailures = promauto.With(r).NewGauge(prometheus.GaugeOpts{ Namespace: "cortex", Name: "table_manager_delete_failures", Help: "Number of table deletion failures during the last table-manager reconciliation", }) - m.lastSuccessfulSync = prometheus.NewGauge(prometheus.GaugeOpts{ + m.lastSuccessfulSync = promauto.With(r).NewGauge(prometheus.GaugeOpts{ Namespace: "cortex", Name: "table_manager_sync_success_timestamp_seconds", Help: "Timestamp of the last successful table manager sync.", }) - if r != nil { - r.MustRegister( - m.syncTableDuration, - m.tableCapacity, - m.createFailures, - m.deleteFailures, - m.lastSuccessfulSync, - ) - } - return &m } diff --git a/pkg/compactor/syncer_metrics.go b/pkg/compactor/syncer_metrics.go index 00c9a4dacf..f3ba2f491a 100644 --- a/pkg/compactor/syncer_metrics.go +++ b/pkg/compactor/syncer_metrics.go @@ -3,6 +3,7 @@ package compactor import ( "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/cortexproject/cortex/pkg/util" ) @@ -29,11 +30,11 @@ type syncerMetrics struct { func newSyncerMetrics(reg prometheus.Registerer) *syncerMetrics { var m syncerMetrics - m.metaSync = prometheus.NewCounter(prometheus.CounterOpts{ + m.metaSync = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_meta_syncs_total", Help: "Total blocks metadata synchronization attempts.", }) - m.metaSyncFailures = prometheus.NewCounter(prometheus.CounterOpts{ + m.metaSyncFailures = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_meta_sync_failures_total", Help: "Total blocks metadata synchronization failures.", }) @@ -41,16 +42,16 @@ func newSyncerMetrics(reg prometheus.Registerer) *syncerMetrics { "cortex_compactor_meta_sync_duration_seconds", "Duration of the blocks metadata synchronization in seconds.", nil, nil)) - m.metaSyncConsistencyDelay = prometheus.NewGauge(prometheus.GaugeOpts{ + m.metaSyncConsistencyDelay = promauto.With(reg).NewGauge(prometheus.GaugeOpts{ Name: "cortex_compactor_meta_sync_consistency_delay_seconds", Help: "Configured consistency delay in seconds.", }) - m.garbageCollections = prometheus.NewCounter(prometheus.CounterOpts{ + m.garbageCollections = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_garbage_collection_total", Help: "Total number of garbage collection operations.", }) - m.garbageCollectionFailures = prometheus.NewCounter(prometheus.CounterOpts{ + m.garbageCollectionFailures = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_garbage_collection_failures_total", Help: "Total number of failed garbage collection operations.", }) @@ -59,43 +60,31 @@ func newSyncerMetrics(reg prometheus.Registerer) *syncerMetrics { "Time it took to perform garbage collection iteration.", nil, nil)) - m.compactions = prometheus.NewCounter(prometheus.CounterOpts{ + m.compactions = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_group_compactions_total", Help: "Total number of group compaction attempts that resulted in a new block.", }) - m.compactionRunsStarted = prometheus.NewCounter(prometheus.CounterOpts{ + m.compactionRunsStarted = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_group_compaction_runs_started_total", Help: "Total number of group compaction attempts.", }) - m.compactionRunsCompleted = prometheus.NewCounter(prometheus.CounterOpts{ + m.compactionRunsCompleted = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_group_compaction_runs_completed_total", Help: "Total number of group completed compaction runs. This also includes compactor group runs that resulted with no compaction.", }) - m.compactionFailures = prometheus.NewCounter(prometheus.CounterOpts{ + m.compactionFailures = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_group_compactions_failures_total", Help: "Total number of failed group compactions.", }) - m.verticalCompactions = prometheus.NewCounter(prometheus.CounterOpts{ + m.verticalCompactions = promauto.With(reg).NewCounter(prometheus.CounterOpts{ Name: "cortex_compactor_group_vertical_compactions_total", Help: "Total number of group compaction attempts that resulted in a new block based on overlapping blocks.", }) if reg != nil { - reg.MustRegister( - m.metaSync, - m.metaSyncFailures, - m.metaSyncDuration, - m.metaSyncConsistencyDelay, - m.garbageCollections, - m.garbageCollectionFailures, - m.garbageCollectionDuration, - m.compactions, - m.compactionRunsStarted, - m.compactionRunsCompleted, - m.compactionFailures, - m.verticalCompactions, - ) + reg.MustRegister(m.metaSyncDuration, m.garbageCollectionDuration) } + return &m }