Skip to content

Commit

Permalink
Use Promauto
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
  • Loading branch information
roidelapluie committed Oct 12, 2020
1 parent 9e8beee commit 57b9f20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 39 deletions.
21 changes: 6 additions & 15 deletions pkg/chunk/table_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down
37 changes: 13 additions & 24 deletions pkg/compactor/syncer_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -29,28 +30,28 @@ 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.",
})
m.metaSyncDuration = util.NewHistogramDataCollector(prometheus.NewDesc(
"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.",
})
Expand All @@ -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
}

Expand Down

0 comments on commit 57b9f20

Please sign in to comment.