From 0caf177b78c5cf41f6a3a6f699bcebdee6aafb7f Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Wed, 13 Feb 2019 17:10:41 -0300 Subject: [PATCH] 13937: Moves statsTicker metrics init to its own func. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- services/keepstore/stats_ticker.go | 23 +++++++++++++++-------- services/keepstore/volume_unix.go | 9 +++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/services/keepstore/stats_ticker.go b/services/keepstore/stats_ticker.go index 6742dbaa9a..7f52b744d5 100644 --- a/services/keepstore/stats_ticker.go +++ b/services/keepstore/stats_ticker.go @@ -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) } diff --git a/services/keepstore/volume_unix.go b/services/keepstore/volume_unix.go index 10cd6398c0..5313059eaa 100644 --- a/services/keepstore/volume_unix.go +++ b/services/keepstore/volume_unix.go @@ -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 -- 2.30.2