From f4314dd3608a4cbba5a6f7e8579f2fbf7df85985 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 24 May 2021 23:45:54 +0200 Subject: [PATCH] s3store: Do not register metrics to default registry --- cmd/tusd/cli/composer.go | 5 +++++ pkg/s3store/s3store.go | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/tusd/cli/composer.go b/cmd/tusd/cli/composer.go index ecc87a1..c7e580c 100644 --- a/cmd/tusd/cli/composer.go +++ b/cmd/tusd/cli/composer.go @@ -5,6 +5,7 @@ import ( "path/filepath" "strings" + "github.com/prometheus/client_golang/prometheus" "github.com/tus/tusd/pkg/filelocker" "github.com/tus/tusd/pkg/filestore" "github.com/tus/tusd/pkg/gcsstore" @@ -64,6 +65,10 @@ func CreateComposer() { locker := memorylocker.New() locker.UseIn(Composer) + + // Attach the metrics from S3 store to the global Prometheus registry + // TODO: Do not use the global registry here. + store.RegisterMetrics(prometheus.DefaultRegisterer) } else if Flags.GCSBucket != "" { if Flags.GCSObjectPrefix != "" && strings.Contains(Flags.GCSObjectPrefix, "_") { stderr.Fatalf("gcs-object-prefix value (%s) can't contain underscore. "+ diff --git a/pkg/s3store/s3store.go b/pkg/s3store/s3store.go index ee1db66..0d2431f 100644 --- a/pkg/s3store/s3store.go +++ b/pkg/s3store/s3store.go @@ -207,8 +207,6 @@ func New(bucket string, service S3API) S3Store { Help: "Duration of requests sent to S3 in milliseconds per operation", Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, }, []string{"operation"}) - // TODO: Do not register them globally but to a specific prometheus handler - prometheus.MustRegister(requestDurationMetric) return S3Store{ Bucket: bucket, @@ -239,6 +237,10 @@ func (store S3Store) UseIn(composer *handler.StoreComposer) { composer.UseLengthDeferrer(store) } +func (store S3Store) RegisterMetrics(registry prometheus.Registerer) { + registry.MustRegister(store.requestDurationMetric) +} + func (store S3Store) observeRequestDuration(start time.Time, label string) { elapsed := time.Now().Sub(start) ms := float64(elapsed.Nanoseconds() / int64(time.Millisecond))