From ac0ed8be05fd923ad7f54606f6cd51ed39aa117d Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 28 Sep 2022 09:11:29 +0200 Subject: [PATCH] implement seeker Signed-off-by: Christian Richter --- go.mod | 4 ++-- go.sum | 1 - pkg/storage/fs/s3ng/blobstore/blobstore.go | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index eab82d53d9..a835f236e7 100644 --- a/go.mod +++ b/go.mod @@ -58,12 +58,14 @@ require ( github.com/pkg/errors v0.9.1 github.com/pkg/xattr v0.4.7 github.com/prometheus/alertmanager v0.24.0 + github.com/prometheus/client_golang v1.13.0 github.com/rs/cors v1.8.2 github.com/rs/zerolog v1.28.0 github.com/sciencemesh/meshdirectory-web v1.0.4 github.com/sethvargo/go-password v0.2.0 github.com/stretchr/testify v1.8.0 github.com/studio-b12/gowebdav v0.0.0-20220128162035-c7b1ff8a5e62 + github.com/test-go/testify v1.1.4 github.com/thanhpk/randstr v1.0.4 github.com/tus/tusd v1.9.2 github.com/wk8/go-ordered-map v1.0.0 @@ -171,7 +173,6 @@ require ( github.com/pkg/term v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.1.0 // indirect - github.com/prometheus/client_golang v1.13.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect @@ -184,7 +185,6 @@ require ( github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect github.com/sirupsen/logrus v1.9.0 // indirect github.com/stretchr/objx v0.4.0 // indirect - github.com/test-go/testify v1.1.4 // indirect github.com/tidwall/pretty v1.2.0 // indirect github.com/urfave/cli/v2 v2.16.3 // indirect github.com/xanzy/ssh-agent v0.3.2 // indirect diff --git a/go.sum b/go.sum index 7a1b15e5e0..d4a112ccd1 100644 --- a/go.sum +++ b/go.sum @@ -824,7 +824,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= diff --git a/pkg/storage/fs/s3ng/blobstore/blobstore.go b/pkg/storage/fs/s3ng/blobstore/blobstore.go index 95bfe62484..6fcae9420c 100644 --- a/pkg/storage/fs/s3ng/blobstore/blobstore.go +++ b/pkg/storage/fs/s3ng/blobstore/blobstore.go @@ -46,9 +46,9 @@ type PrometheusAwareReader struct { m *prometheus.CounterVec } -// PrometheusAwareReadCloser provides an interface to a prometheus aware ReadCloser -type PrometheusAwareReadCloser struct { - r io.ReadCloser +// PrometheusAwareReadSeekCloser provides an interface to a prometheus aware ReadCloser +type PrometheusAwareReadSeekCloser struct { + r io.ReadSeekCloser m *prometheus.CounterVec } @@ -84,15 +84,21 @@ func (p *PrometheusAwareReader) Read(b []byte) (n int, err error) { return } -// Read implements the read function of the PrometheusAwareReadCloser -func (p *PrometheusAwareReadCloser) Read(b []byte) (n int, err error) { +// Read implements the read function of the PrometheusAwareReadSeekCloser +func (p *PrometheusAwareReadSeekCloser) Read(b []byte) (n int, err error) { n, err = p.r.Read(b) p.m.WithLabelValues().Add(float64(n)) return } +// Seek implements the seek function of the PrometheusAwareReadSeekCloser +func (p *PrometheusAwareReadSeekCloser) Seek(offset int64, whence int) (int64, error) { + return p.r.Seek(offset, whence) + +} + // Close implements the close function of the PrometheusAwareReadCloser -func (p *PrometheusAwareReadCloser) Close() error { +func (p *PrometheusAwareReadSeekCloser) Close() error { return p.r.Close() } @@ -125,7 +131,7 @@ func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) { if err != nil { return nil, errors.Wrapf(err, "could not download object '%s' from bucket '%s'", bs.path(node), bs.bucket) } - return &PrometheusAwareReadCloser{ + return &PrometheusAwareReadSeekCloser{ r: reader, m: metrics.Rx, }, nil