Merge branch '15209-python-arv-deps-pinned'
[arvados.git] / services / keepstore / s3_volume.go
index 5d7332ff62e653e285470b989559670443b75357..4c39dcd5c4f12fc9a8b8ad36d165545af952fb7a 100644 (file)
@@ -199,7 +199,7 @@ func (*S3Volume) Type() string {
 
 // Start populates private fields and verifies the configuration is
 // valid.
-func (v *S3Volume) Start(opsCounters, errCounters, ioBytes *prometheus.CounterVec) error {
+func (v *S3Volume) Start(vm *volumeMetricsVecs) error {
        region, ok := aws.Regions[v.Region]
        if v.Endpoint == "" {
                if !ok {
@@ -251,9 +251,7 @@ func (v *S3Volume) Start(opsCounters, errCounters, ioBytes *prometheus.CounterVe
        }
        // Set up prometheus metrics
        lbls := prometheus.Labels{"device_id": v.DeviceID()}
-       v.bucket.stats.opsCounters = opsCounters.MustCurryWith(lbls)
-       v.bucket.stats.errCounters = errCounters.MustCurryWith(lbls)
-       v.bucket.stats.ioBytes = ioBytes.MustCurryWith(lbls)
+       v.bucket.stats.opsCounters, v.bucket.stats.errCounters, v.bucket.stats.ioBytes = vm.getCounterVecsFor(lbls)
 
        return nil
 }
@@ -976,12 +974,7 @@ func (b *s3bucket) GetReader(path string) (io.ReadCloser, error) {
        b.stats.TickOps("get")
        b.stats.Tick(&b.stats.Ops, &b.stats.GetOps)
        b.stats.TickErr(err)
-       return NewCountingReader(
-               rdr,
-               func(c uint64) {
-                       b.stats.CountBytesIn(c)
-                       b.stats.TickInBytes(c)
-               }), err
+       return NewCountingReader(rdr, b.stats.TickInBytes), err
 }
 
 func (b *s3bucket) Head(path string, headers map[string][]string) (*http.Response, error) {
@@ -1002,12 +995,7 @@ func (b *s3bucket) PutReader(path string, r io.Reader, length int64, contType st
                // empty objects.
                r = nil
        } else {
-               r = NewCountingReader(
-                       r,
-                       func(c uint64) {
-                               b.stats.CountBytesOut(c)
-                               b.stats.TickOutBytes(c)
-                       })
+               r = NewCountingReader(r, b.stats.TickOutBytes)
        }
        err := b.Bucket.PutReader(path, r, length, contType, perm, options)
        b.stats.TickOps("put")
@@ -1032,10 +1020,6 @@ type s3bucketStats struct {
        HeadOps uint64
        DelOps  uint64
        ListOps uint64
-
-       opsCounters *prometheus.CounterVec
-       errCounters *prometheus.CounterVec
-       ioBytes     *prometheus.CounterVec
 }
 
 func (s *s3bucketStats) TickErr(err error) {
@@ -1046,32 +1030,5 @@ func (s *s3bucketStats) TickErr(err error) {
        if err, ok := err.(*s3.Error); ok {
                errType = errType + fmt.Sprintf(" %d %s", err.StatusCode, err.Code)
        }
-       if s.errCounters != nil {
-               s.errCounters.With(prometheus.Labels{"error_type": errType}).Inc()
-       }
        s.statsTicker.TickErr(err, errType)
 }
-
-func (s *s3bucketStats) TickOps(operations ...string) {
-       if s.opsCounters == nil {
-               return
-       }
-       for _, opType := range operations {
-               s.opsCounters.With(prometheus.Labels{"operation": opType}).Inc()
-       }
-}
-
-func (s *s3bucketStats) CountBytesIn(b uint64) {
-       s.countBytes("in", float64(b))
-}
-
-func (s *s3bucketStats) CountBytesOut(b uint64) {
-       s.countBytes("out", float64(b))
-}
-
-func (s *s3bucketStats) countBytes(direction string, bytes float64) {
-       if s.ioBytes == nil {
-               return
-       }
-       s.ioBytes.With(prometheus.Labels{"direction": direction}).Add(bytes)
-}