13937: Moves statsTicker metrics init to its own func.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 13 Feb 2019 20:10:41 +0000 (17:10 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 13 Feb 2019 20:10:41 +0000 (17:10 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/keepstore/stats_ticker.go
services/keepstore/volume_unix.go

index 6742dbaa9aa1a8669c875266c9cac09dce7a8a48..7f52b744d501f571ecfb77d1d797a0d30a7ef8f6 100644 (file)
@@ -17,15 +17,22 @@ type statsTicker struct {
        OutBytes uint64
 
        // Prometheus metrics
-       PromErrors     prometheus.Counter
-       PromInBytes    prometheus.Counter
-       PromOutBytes   prometheus.Counter
-       PromErrorCodes *prometheus.CounterVec
+       errors      prometheus.Counter
+       inBytes     prometheus.Counter
+       outBytes    prometheus.Counter
+       errCounters *prometheus.CounterVec
 
        ErrorCodes map[string]uint64 `json:",omitempty"`
        lock       sync.Mutex
 }
 
+func (s *statsTicker) setup(m *volumeMetrics) {
+       s.errors = m.Errors
+       s.errCounters = m.ErrorCodes
+       s.inBytes = m.InBytes
+       s.outBytes = m.OutBytes
+}
+
 // Tick increments each of the given counters by 1 using
 // atomic.AddUint64.
 func (s *statsTicker) Tick(counters ...*uint64) {
@@ -41,7 +48,7 @@ func (s *statsTicker) TickErr(err error, errType string) {
        if err == nil {
                return
        }
-       s.PromErrors.Inc()
+       s.errors.Inc()
        s.Tick(&s.Errors)
 
        s.lock.Lock()
@@ -50,17 +57,17 @@ func (s *statsTicker) TickErr(err error, errType string) {
        }
        s.ErrorCodes[errType]++
        s.lock.Unlock()
-       s.PromErrorCodes.WithLabelValues(errType).Inc()
+       s.errCounters.WithLabelValues(errType).Inc()
 }
 
 // TickInBytes increments the incoming byte counter by n.
 func (s *statsTicker) TickInBytes(n uint64) {
-       s.PromInBytes.Add(float64(n))
+       s.inBytes.Add(float64(n))
        atomic.AddUint64(&s.InBytes, n)
 }
 
 // TickOutBytes increments the outgoing byte counter by n.
 func (s *statsTicker) TickOutBytes(n uint64) {
-       s.PromOutBytes.Add(float64(n))
+       s.outBytes.Add(float64(n))
        atomic.AddUint64(&s.OutBytes, n)
 }
index 10cd6398c01e79cf1c99b97da3523ff8dbbd70a8..5313059eaa6db52d74dc01e2e6c21208500a829a 100644 (file)
@@ -28,7 +28,7 @@ type unixVolumeAdder struct {
 }
 
 // String implements flag.Value
-func (s *unixVolumeAdder) String() string {
+func (vs *unixVolumeAdder) String() string {
        return "-"
 }
 
@@ -234,10 +234,7 @@ func (v *UnixVolume) Start(m *volumeMetrics) error {
        if err == nil {
                // Set up prometheus metrics
                v.metrics = m
-               v.os.stats.PromErrors = v.metrics.Errors
-               v.os.stats.PromErrorCodes = v.metrics.ErrorCodes
-               v.os.stats.PromInBytes = v.metrics.InBytes
-               v.os.stats.PromOutBytes = v.metrics.OutBytes
+               v.os.stats.statsTicker.setup(m)
                // Periodically update free/used volume space
                go func() {
                        for {
@@ -365,7 +362,7 @@ func (v *UnixVolume) Put(ctx context.Context, loc string, block []byte) error {
        return putWithPipe(ctx, loc, block, v)
 }
 
-// ReadBlock implements BlockWriter.
+// WriteBlock implements BlockWriter.
 func (v *UnixVolume) WriteBlock(ctx context.Context, loc string, rdr io.Reader) error {
        if v.ReadOnly {
                return MethodDisabledError