diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-12 16:06:44 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-12 16:32:36 +0300 |
commit | 4244b431635abe0385504649888c785b24ea528d (patch) | |
tree | 5780080bcafafbd7b21c191aea6b12689a0f1e12 | |
parent | 187f550dce577f1fb39503976a30a73a58b2b8e1 (diff) |
gitaly: Fix registration of metrics dependent on config
We've recently grown a metric in Gitaly which is dependent on the
configuration in order to set up its buckets. This metric is registered
as part of the global variables, but this is wrong as the global
configuration will not yet have been read at that point in time.
Ideally, we'd do the same as we do for Praefect, where we register and
inject metrics in Gitaly's main package. But given that this would
require quite some refactoring to do, this is deemed infeasible in the
context of this small change.
Let's instead fix this by lazily registering metrics via `sync.Once`.
-rw-r--r-- | changelogs/unreleased/pks-gitaly-metrics-registration.yml | 5 | ||||
-rw-r--r-- | internal/service/register.go | 18 |
2 files changed, 21 insertions, 2 deletions
diff --git a/changelogs/unreleased/pks-gitaly-metrics-registration.yml b/changelogs/unreleased/pks-gitaly-metrics-registration.yml new file mode 100644 index 000000000..1f7e79a80 --- /dev/null +++ b/changelogs/unreleased/pks-gitaly-metrics-registration.yml @@ -0,0 +1,5 @@ +--- +title: Fix registration of Gitaly metrics dependent on config +merge_request: 2467 +author: +type: fixed diff --git a/internal/service/register.go b/internal/service/register.go index e0bafdff7..69e29c8d5 100644 --- a/internal/service/register.go +++ b/internal/service/register.go @@ -1,6 +1,8 @@ package service import ( + "sync" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "gitlab.com/gitlab-org/gitaly/internal/config" @@ -30,6 +32,14 @@ import ( ) var ( + once sync.Once + + smarthttpPackfileNegotiationMetrics *prometheus.CounterVec + sshPackfileNegotiationMetrics *prometheus.CounterVec + votingDelayMetric prometheus.Histogram +) + +func registerMetrics(cfg config.Cfg) { smarthttpPackfileNegotiationMetrics = promauto.NewCounterVec( prometheus.CounterOpts{ Namespace: "gitaly", @@ -54,14 +64,18 @@ var ( prometheus.HistogramOpts{ Name: "gitaly_hook_transaction_voting_delay_seconds", Help: "Delay between calling out to transaction service and receiving a response", - Buckets: config.Config.Prometheus.GRPCLatencyBuckets, + Buckets: cfg.Prometheus.GRPCLatencyBuckets, }, ) -) +} // RegisterAll will register all the known grpc services with // the specified grpc service instance func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver.Server, gitlabAPI hook.GitlabAPI, locator storage.Locator) { + once.Do(func() { + registerMetrics(cfg) + }) + gitalypb.RegisterBlobServiceServer(grpcServer, blob.NewServer(rubyServer)) gitalypb.RegisterCleanupServiceServer(grpcServer, cleanup.NewServer()) gitalypb.RegisterCommitServiceServer(grpcServer, commit.NewServer(locator)) |