diff options
author | Paul Okstad <pokstad@gitlab.com> | 2020-03-26 23:33:38 +0300 |
---|---|---|
committer | Paul Okstad <pokstad@gitlab.com> | 2020-03-26 23:33:38 +0300 |
commit | 10028e0e226b9332b7ccdc5420681a83d943295f (patch) | |
tree | 9c9d48f805d0451e196d96412c07abab16a405da | |
parent | 57386335bfa2f46f3d74ac111eb5f750faf9a626 (diff) | |
parent | 37baf46c89a4ac511e01be9853c89884c864131e (diff) |
Merge branch 'pks-prometheus-metrics' into 'master'
Move Prometheus metric interfaces into their own package
See merge request gitlab-org/gitaly!1967
-rw-r--r-- | internal/praefect/metrics/prometheus.go | 22 | ||||
-rw-r--r-- | internal/praefect/nodes/manager.go | 7 | ||||
-rw-r--r-- | internal/praefect/replicator.go | 9 | ||||
-rw-r--r-- | internal/prometheus/metrics/metrics.go | 20 |
4 files changed, 33 insertions, 25 deletions
diff --git a/internal/praefect/metrics/prometheus.go b/internal/praefect/metrics/prometheus.go index 74aa2361a..d45a70af0 100644 --- a/internal/praefect/metrics/prometheus.go +++ b/internal/praefect/metrics/prometheus.go @@ -3,11 +3,12 @@ package metrics import ( "github.com/prometheus/client_golang/prometheus" promconfig "gitlab.com/gitlab-org/gitaly/internal/config/prometheus" + "gitlab.com/gitlab-org/gitaly/internal/prometheus/metrics" ) // RegisterReplicationLatency creates and registers a prometheus histogram // to observe replication latency times -func RegisterReplicationLatency(conf promconfig.Config) (Histogram, error) { +func RegisterReplicationLatency(conf promconfig.Config) (metrics.Histogram, error) { replicationLatency := prometheus.NewHistogram( prometheus.HistogramOpts{ Namespace: "gitaly", @@ -22,7 +23,7 @@ func RegisterReplicationLatency(conf promconfig.Config) (Histogram, error) { // RegisterNodeLatency creates and registers a prometheus histogram to // observe internal node latency -func RegisterNodeLatency(conf promconfig.Config) (HistogramVec, error) { +func RegisterNodeLatency(conf promconfig.Config) (metrics.HistogramVec, error) { nodeLatency := prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: "gitaly", @@ -37,7 +38,7 @@ func RegisterNodeLatency(conf promconfig.Config) (HistogramVec, error) { // RegisterReplicationJobsInFlight creates and registers a gauge // to track the size of the replication queue -func RegisterReplicationJobsInFlight() (Gauge, error) { +func RegisterReplicationJobsInFlight() (metrics.Gauge, error) { replicationJobsInFlight := prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: "gitaly", @@ -79,18 +80,3 @@ func init() { ChecksumMismatchCounter, ) } - -// Gauge is a subset of a prometheus Gauge -type Gauge interface { - Inc() - Dec() -} - -// Histogram is a subset of a prometheus Histogram -type Histogram interface { - Observe(float64) -} - -type HistogramVec interface { - WithLabelValues(lvs ...string) prometheus.Observer -} diff --git a/internal/praefect/nodes/manager.go b/internal/praefect/nodes/manager.go index 8fba66968..ad0a8309b 100644 --- a/internal/praefect/nodes/manager.go +++ b/internal/praefect/nodes/manager.go @@ -15,6 +15,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/praefect/grpc-proxy/proxy" "gitlab.com/gitlab-org/gitaly/internal/praefect/metrics" "gitlab.com/gitlab-org/gitaly/internal/praefect/models" + prommetrics "gitlab.com/gitlab-org/gitaly/internal/prometheus/metrics" correlation "gitlab.com/gitlab-org/labkit/correlation/grpc" grpctracing "gitlab.com/gitlab-org/labkit/tracing/grpc" "google.golang.org/grpc" @@ -82,7 +83,7 @@ type Mgr struct { var ErrPrimaryNotHealthy = errors.New("primary is not healthy") // NewNodeManager creates a new NodeMgr based on virtual storage configs -func NewManager(log *logrus.Entry, c config.Config, latencyHistogram metrics.HistogramVec, dialOpts ...grpc.DialOption) (*Mgr, error) { +func NewManager(log *logrus.Entry, c config.Config, latencyHistogram prommetrics.HistogramVec, dialOpts ...grpc.DialOption) (*Mgr, error) { shards := make(map[string]*shard) for _, virtualStorage := range c.VirtualStorages { var secondaries []*nodeStatus @@ -229,7 +230,7 @@ func (n *Mgr) checkShards() { } } -func newConnectionStatus(node models.Node, cc *grpc.ClientConn, l *logrus.Entry, latencyHist metrics.HistogramVec) *nodeStatus { +func newConnectionStatus(node models.Node, cc *grpc.ClientConn, l *logrus.Entry, latencyHist prommetrics.HistogramVec) *nodeStatus { return &nodeStatus{ Node: node, ClientConn: cc, @@ -244,7 +245,7 @@ type nodeStatus struct { *grpc.ClientConn statuses []healthpb.HealthCheckResponse_ServingStatus log *logrus.Entry - latencyHist metrics.HistogramVec + latencyHist prommetrics.HistogramVec } // GetStorage gets the storage name of a node diff --git a/internal/praefect/replicator.go b/internal/praefect/replicator.go index 9fa23eeb6..f70613111 100644 --- a/internal/praefect/replicator.go +++ b/internal/praefect/replicator.go @@ -12,6 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/internal/praefect/metrics" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" + prommetrics "gitlab.com/gitlab-org/gitaly/internal/prometheus/metrics" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc" "golang.org/x/sync/errgroup" @@ -185,8 +186,8 @@ type ReplMgr struct { nodeManager nodes.Manager virtualStorage string // which replica is this replicator responsible for? replicator Replicator // does the actual replication logic - replQueueMetric metrics.Gauge - replLatencyMetric metrics.Histogram + replQueueMetric prommetrics.Gauge + replLatencyMetric prommetrics.Histogram replJobTimeout time.Duration // whitelist contains the project names of the repos we wish to replicate whitelist map[string]struct{} @@ -196,14 +197,14 @@ type ReplMgr struct { type ReplMgrOpt func(*ReplMgr) // WithQueueMetric is an option to set the queue size prometheus metric -func WithQueueMetric(g metrics.Gauge) func(*ReplMgr) { +func WithQueueMetric(g prommetrics.Gauge) func(*ReplMgr) { return func(m *ReplMgr) { m.replQueueMetric = g } } // WithLatencyMetric is an option to set the queue size prometheus metric -func WithLatencyMetric(h metrics.Histogram) func(*ReplMgr) { +func WithLatencyMetric(h prommetrics.Histogram) func(*ReplMgr) { return func(m *ReplMgr) { m.replLatencyMetric = h } diff --git a/internal/prometheus/metrics/metrics.go b/internal/prometheus/metrics/metrics.go new file mode 100644 index 000000000..9ca576de6 --- /dev/null +++ b/internal/prometheus/metrics/metrics.go @@ -0,0 +1,20 @@ +package metrics + +import ( + "github.com/prometheus/client_golang/prometheus" +) + +// Gauge is a subset of a prometheus Gauge +type Gauge interface { + Inc() + Dec() +} + +// Histogram is a subset of a prometheus Histogram +type Histogram interface { + Observe(float64) +} + +type HistogramVec interface { + WithLabelValues(lvs ...string) prometheus.Observer +} |