diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-05-13 14:57:55 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-05-15 10:09:11 +0300 |
commit | 80284bc249b14d31662e256fddf1efbb75f8d6bf (patch) | |
tree | ecd091f7d5e451f0a9db8501161a453213338390 | |
parent | 068f4821788d23542700ea344939b45bc41da6ec (diff) |
praefect: Wire up transaction metrics
Now that the transaction manager has a set of metrics, we need to wire
them up in Praefect. Let's do so.
-rw-r--r-- | cmd/praefect/main.go | 15 | ||||
-rw-r--r-- | internal/praefect/metrics/prometheus.go | 29 |
2 files changed, 43 insertions, 1 deletions
diff --git a/cmd/praefect/main.go b/cmd/praefect/main.go index 009734f0d..19d5e25fa 100644 --- a/cmd/praefect/main.go +++ b/cmd/praefect/main.go @@ -237,7 +237,20 @@ func run(cfgs []starter.Config, conf config.Config) error { } nodeManager.Start(1*time.Second, 3*time.Second) - transactionManager := transactions.NewManager() + transactionCounterMetric, err := metrics.RegisterTransactionCounter() + if err != nil { + return err + } + + transactionDelayMetric, err := metrics.RegisterTransactionDelay(conf.Prometheus) + if err != nil { + return err + } + + transactionManager := transactions.NewManager( + transactions.WithCounterMetric(transactionCounterMetric), + transactions.WithDelayMetric(transactionDelayMetric), + ) registry := protoregistry.New() if err = registry.RegisterFiles(protoregistry.GitalyProtoFileDescriptors...); err != nil { diff --git a/internal/praefect/metrics/prometheus.go b/internal/praefect/metrics/prometheus.go index 48ac91708..f49dfb9ba 100644 --- a/internal/praefect/metrics/prometheus.go +++ b/internal/praefect/metrics/prometheus.go @@ -66,6 +66,35 @@ func RegisterReplicationJobsInFlight() (metrics.Gauge, error) { return replicationJobsInFlight, prometheus.Register(replicationJobsInFlight) } +// RegisterTransactionCounter creates and registers a Prometheus counter to +// track the number of transactions and their outcomes. +func RegisterTransactionCounter() (*prometheus.CounterVec, error) { + transactionCounter := prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "gitaly", + Subsystem: "praefect", + Name: "transactions_total", + }, + []string{"action"}, + ) + return transactionCounter, prometheus.Register(transactionCounter) +} + +// RegisterTransactionDelay creates and registers a Prometheus histogram to +// track the delay of actions performed on transactions. +func RegisterTransactionDelay(conf promconfig.Config) (metrics.HistogramVec, error) { + transactionDelay := prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Namespace: "gitaly", + Subsystem: "praefect", + Name: "transactions_delay_seconds", + Buckets: conf.GRPCLatencyBuckets, + }, + []string{"action"}, + ) + return transactionDelay, prometheus.Register(transactionDelay) +} + var MethodTypeCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "gitaly", |