Skip to content

Commit

Permalink
implement seeker
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <crichter@owncloud.com>
  • Loading branch information
dragonchaser committed Sep 28, 2022
1 parent 1eb6465 commit ac0ed8b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
20 changes: 13 additions & 7 deletions pkg/storage/fs/s3ng/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac0ed8b

Please sign in to comment.