s3store: Do not register metrics to default registry

This commit is contained in:
Marius 2021-05-24 23:45:54 +02:00
parent 0f24a80ea5
commit f4314dd360
2 changed files with 9 additions and 2 deletions

View File

@ -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. "+

View File

@ -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))