From 58f2ce8671fcc5121fc696b6962ba826fcf8a7f0 Mon Sep 17 00:00:00 2001
From: Guillaume Ballet <gballet@gmail.com>
Date: Fri, 22 Nov 2019 16:04:35 +0100
Subject: [PATCH] metrics: fix issues reported by staticcheck (#20365)

---
 metrics/counter_test.go       | 16 +++++------
 metrics/gauge_float64_test.go |  2 +-
 metrics/gauge_test.go         |  8 +++---
 metrics/histogram_test.go     | 34 +++++++++++-----------
 metrics/influxdb/influxdb.go  |  6 ++--
 metrics/json_test.go          |  2 +-
 metrics/librato/client.go     |  2 +-
 metrics/librato/librato.go    |  5 ++--
 metrics/meter_test.go         | 10 +++----
 metrics/registry_test.go      | 22 ++++++++------
 metrics/runtime_test.go       |  8 +++---
 metrics/sample.go             |  8 +++---
 metrics/sample_test.go        | 54 +++++++++++++++++------------------
 metrics/timer.go              |  5 +---
 metrics/timer_test.go         | 32 ++++++++++-----------
 15 files changed, 109 insertions(+), 105 deletions(-)

diff --git a/metrics/counter_test.go b/metrics/counter_test.go
index dfb03b4e8..af26ef154 100644
--- a/metrics/counter_test.go
+++ b/metrics/counter_test.go
@@ -14,7 +14,7 @@ func TestCounterClear(t *testing.T) {
 	c := NewCounter()
 	c.Inc(1)
 	c.Clear()
-	if count := c.Count(); 0 != count {
+	if count := c.Count(); count != 0 {
 		t.Errorf("c.Count(): 0 != %v\n", count)
 	}
 }
@@ -22,7 +22,7 @@ func TestCounterClear(t *testing.T) {
 func TestCounterDec1(t *testing.T) {
 	c := NewCounter()
 	c.Dec(1)
-	if count := c.Count(); -1 != count {
+	if count := c.Count(); count != -1 {
 		t.Errorf("c.Count(): -1 != %v\n", count)
 	}
 }
@@ -30,7 +30,7 @@ func TestCounterDec1(t *testing.T) {
 func TestCounterDec2(t *testing.T) {
 	c := NewCounter()
 	c.Dec(2)
-	if count := c.Count(); -2 != count {
+	if count := c.Count(); count != -2 {
 		t.Errorf("c.Count(): -2 != %v\n", count)
 	}
 }
@@ -38,7 +38,7 @@ func TestCounterDec2(t *testing.T) {
 func TestCounterInc1(t *testing.T) {
 	c := NewCounter()
 	c.Inc(1)
-	if count := c.Count(); 1 != count {
+	if count := c.Count(); count != 1 {
 		t.Errorf("c.Count(): 1 != %v\n", count)
 	}
 }
@@ -46,7 +46,7 @@ func TestCounterInc1(t *testing.T) {
 func TestCounterInc2(t *testing.T) {
 	c := NewCounter()
 	c.Inc(2)
-	if count := c.Count(); 2 != count {
+	if count := c.Count(); count != 2 {
 		t.Errorf("c.Count(): 2 != %v\n", count)
 	}
 }
@@ -56,14 +56,14 @@ func TestCounterSnapshot(t *testing.T) {
 	c.Inc(1)
 	snapshot := c.Snapshot()
 	c.Inc(1)
-	if count := snapshot.Count(); 1 != count {
+	if count := snapshot.Count(); count != 1 {
 		t.Errorf("c.Count(): 1 != %v\n", count)
 	}
 }
 
 func TestCounterZero(t *testing.T) {
 	c := NewCounter()
-	if count := c.Count(); 0 != count {
+	if count := c.Count(); count != 0 {
 		t.Errorf("c.Count(): 0 != %v\n", count)
 	}
 }
@@ -71,7 +71,7 @@ func TestCounterZero(t *testing.T) {
 func TestGetOrRegisterCounter(t *testing.T) {
 	r := NewRegistry()
 	NewRegisteredCounter("foo", r).Inc(47)
-	if c := GetOrRegisterCounter("foo", r); 47 != c.Count() {
+	if c := GetOrRegisterCounter("foo", r); c.Count() != 47 {
 		t.Fatal(c)
 	}
 }
diff --git a/metrics/gauge_float64_test.go b/metrics/gauge_float64_test.go
index 99e62a403..3ee568e7b 100644
--- a/metrics/gauge_float64_test.go
+++ b/metrics/gauge_float64_test.go
@@ -53,7 +53,7 @@ func TestFunctionalGaugeFloat64(t *testing.T) {
 func TestGetOrRegisterFunctionalGaugeFloat64(t *testing.T) {
 	r := NewRegistry()
 	NewRegisteredFunctionalGaugeFloat64("foo", r, func() float64 { return 47 })
-	if g := GetOrRegisterGaugeFloat64("foo", r); 47 != g.Value() {
+	if g := GetOrRegisterGaugeFloat64("foo", r); g.Value() != 47 {
 		t.Fatal(g)
 	}
 }
diff --git a/metrics/gauge_test.go b/metrics/gauge_test.go
index 1f2603d33..3aee14345 100644
--- a/metrics/gauge_test.go
+++ b/metrics/gauge_test.go
@@ -16,7 +16,7 @@ func BenchmarkGuage(b *testing.B) {
 func TestGauge(t *testing.T) {
 	g := NewGauge()
 	g.Update(int64(47))
-	if v := g.Value(); 47 != v {
+	if v := g.Value(); v != 47 {
 		t.Errorf("g.Value(): 47 != %v\n", v)
 	}
 }
@@ -26,7 +26,7 @@ func TestGaugeSnapshot(t *testing.T) {
 	g.Update(int64(47))
 	snapshot := g.Snapshot()
 	g.Update(int64(0))
-	if v := snapshot.Value(); 47 != v {
+	if v := snapshot.Value(); v != 47 {
 		t.Errorf("g.Value(): 47 != %v\n", v)
 	}
 }
@@ -34,7 +34,7 @@ func TestGaugeSnapshot(t *testing.T) {
 func TestGetOrRegisterGauge(t *testing.T) {
 	r := NewRegistry()
 	NewRegisteredGauge("foo", r).Update(47)
-	if g := GetOrRegisterGauge("foo", r); 47 != g.Value() {
+	if g := GetOrRegisterGauge("foo", r); g.Value() != 47 {
 		t.Fatal(g)
 	}
 }
@@ -55,7 +55,7 @@ func TestFunctionalGauge(t *testing.T) {
 func TestGetOrRegisterFunctionalGauge(t *testing.T) {
 	r := NewRegistry()
 	NewRegisteredFunctionalGauge("foo", r, func() int64 { return 47 })
-	if g := GetOrRegisterGauge("foo", r); 47 != g.Value() {
+	if g := GetOrRegisterGauge("foo", r); g.Value() != 47 {
 		t.Fatal(g)
 	}
 }
diff --git a/metrics/histogram_test.go b/metrics/histogram_test.go
index d7f4f0171..7c9f42fce 100644
--- a/metrics/histogram_test.go
+++ b/metrics/histogram_test.go
@@ -14,7 +14,7 @@ func TestGetOrRegisterHistogram(t *testing.T) {
 	r := NewRegistry()
 	s := NewUniformSample(100)
 	NewRegisteredHistogram("foo", r, s).Update(47)
-	if h := GetOrRegisterHistogram("foo", r, s); 1 != h.Count() {
+	if h := GetOrRegisterHistogram("foo", r, s); h.Count() != 1 {
 		t.Fatal(h)
 	}
 }
@@ -29,29 +29,29 @@ func TestHistogram10000(t *testing.T) {
 
 func TestHistogramEmpty(t *testing.T) {
 	h := NewHistogram(NewUniformSample(100))
-	if count := h.Count(); 0 != count {
+	if count := h.Count(); count != 0 {
 		t.Errorf("h.Count(): 0 != %v\n", count)
 	}
-	if min := h.Min(); 0 != min {
+	if min := h.Min(); min != 0 {
 		t.Errorf("h.Min(): 0 != %v\n", min)
 	}
-	if max := h.Max(); 0 != max {
+	if max := h.Max(); max != 0 {
 		t.Errorf("h.Max(): 0 != %v\n", max)
 	}
-	if mean := h.Mean(); 0.0 != mean {
+	if mean := h.Mean(); mean != 0.0 {
 		t.Errorf("h.Mean(): 0.0 != %v\n", mean)
 	}
-	if stdDev := h.StdDev(); 0.0 != stdDev {
+	if stdDev := h.StdDev(); stdDev != 0.0 {
 		t.Errorf("h.StdDev(): 0.0 != %v\n", stdDev)
 	}
 	ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
-	if 0.0 != ps[0] {
+	if ps[0] != 0.0 {
 		t.Errorf("median: 0.0 != %v\n", ps[0])
 	}
-	if 0.0 != ps[1] {
+	if ps[1] != 0.0 {
 		t.Errorf("75th percentile: 0.0 != %v\n", ps[1])
 	}
-	if 0.0 != ps[2] {
+	if ps[2] != 0.0 {
 		t.Errorf("99th percentile: 0.0 != %v\n", ps[2])
 	}
 }
@@ -67,29 +67,29 @@ func TestHistogramSnapshot(t *testing.T) {
 }
 
 func testHistogram10000(t *testing.T, h Histogram) {
-	if count := h.Count(); 10000 != count {
+	if count := h.Count(); count != 10000 {
 		t.Errorf("h.Count(): 10000 != %v\n", count)
 	}
-	if min := h.Min(); 1 != min {
+	if min := h.Min(); min != 1 {
 		t.Errorf("h.Min(): 1 != %v\n", min)
 	}
-	if max := h.Max(); 10000 != max {
+	if max := h.Max(); max != 10000 {
 		t.Errorf("h.Max(): 10000 != %v\n", max)
 	}
-	if mean := h.Mean(); 5000.5 != mean {
+	if mean := h.Mean(); mean != 5000.5 {
 		t.Errorf("h.Mean(): 5000.5 != %v\n", mean)
 	}
-	if stdDev := h.StdDev(); 2886.751331514372 != stdDev {
+	if stdDev := h.StdDev(); stdDev != 2886.751331514372 {
 		t.Errorf("h.StdDev(): 2886.751331514372 != %v\n", stdDev)
 	}
 	ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
-	if 5000.5 != ps[0] {
+	if ps[0] != 5000.5 {
 		t.Errorf("median: 5000.5 != %v\n", ps[0])
 	}
-	if 7500.75 != ps[1] {
+	if ps[1] != 7500.75 {
 		t.Errorf("75th percentile: 7500.75 != %v\n", ps[1])
 	}
-	if 9900.99 != ps[2] {
+	if ps[2] != 9900.99 {
 		t.Errorf("99th percentile: 9900.99 != %v\n", ps[2])
 	}
 }
diff --git a/metrics/influxdb/influxdb.go b/metrics/influxdb/influxdb.go
index 6619915fd..d4fc478e7 100644
--- a/metrics/influxdb/influxdb.go
+++ b/metrics/influxdb/influxdb.go
@@ -62,7 +62,7 @@ func InfluxDBWithTags(r metrics.Registry, d time.Duration, url, database, userna
 func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password, namespace string, tags map[string]string) error {
 	u, err := uurl.Parse(url)
 	if err != nil {
-		return fmt.Errorf("Unable to parse InfluxDB. url: %s, err: %v", url, err)
+		return fmt.Errorf("unable to parse InfluxDB. url: %s, err: %v", url, err)
 	}
 
 	rep := &reporter{
@@ -76,11 +76,11 @@ func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password,
 		cache:     make(map[string]int64),
 	}
 	if err := rep.makeClient(); err != nil {
-		return fmt.Errorf("Unable to make InfluxDB client. err: %v", err)
+		return fmt.Errorf("unable to make InfluxDB client. err: %v", err)
 	}
 
 	if err := rep.send(); err != nil {
-		return fmt.Errorf("Unable to send to InfluxDB. err: %v", err)
+		return fmt.Errorf("unable to send to InfluxDB. err: %v", err)
 	}
 
 	return nil
diff --git a/metrics/json_test.go b/metrics/json_test.go
index cf70051f7..f91fe8cfa 100644
--- a/metrics/json_test.go
+++ b/metrics/json_test.go
@@ -12,7 +12,7 @@ func TestRegistryMarshallJSON(t *testing.T) {
 	r := NewRegistry()
 	r.Register("counter", NewCounter())
 	enc.Encode(r)
-	if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s {
+	if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" {
 		t.Fatalf(s)
 	}
 }
diff --git a/metrics/librato/client.go b/metrics/librato/client.go
index 1f8920cb1..f7aed3e4e 100644
--- a/metrics/librato/client.go
+++ b/metrics/librato/client.go
@@ -96,7 +96,7 @@ func (c *LibratoClient) PostMetrics(batch Batch) (err error) {
 		if body, err = ioutil.ReadAll(resp.Body); err != nil {
 			body = []byte(fmt.Sprintf("(could not fetch response body for error: %s)", err))
 		}
-		err = fmt.Errorf("Unable to post to Librato: %d %s %s", resp.StatusCode, resp.Status, string(body))
+		err = fmt.Errorf("unable to post to Librato: %d %s %s", resp.StatusCode, resp.Status, string(body))
 	}
 	return
 }
diff --git a/metrics/librato/librato.go b/metrics/librato/librato.go
index 2138e01ae..b16493413 100644
--- a/metrics/librato/librato.go
+++ b/metrics/librato/librato.go
@@ -42,9 +42,10 @@ func Librato(r metrics.Registry, d time.Duration, e string, t string, s string,
 
 func (rep *Reporter) Run() {
 	log.Printf("WARNING: This client has been DEPRECATED! It has been moved to https://github.com/mihasya/go-metrics-librato and will be removed from rcrowley/go-metrics on August 5th 2015")
-	ticker := time.Tick(rep.Interval)
+	ticker := time.NewTicker(rep.Interval)
+	defer ticker.Stop()
 	metricsApi := &LibratoClient{rep.Email, rep.Token}
-	for now := range ticker {
+	for now := range ticker.C {
 		var metrics Batch
 		var err error
 		if metrics, err = rep.BuildRequest(now, rep.Registry); err != nil {
diff --git a/metrics/meter_test.go b/metrics/meter_test.go
index e88922260..0302c947d 100644
--- a/metrics/meter_test.go
+++ b/metrics/meter_test.go
@@ -16,7 +16,7 @@ func BenchmarkMeter(b *testing.B) {
 func TestGetOrRegisterMeter(t *testing.T) {
 	r := NewRegistry()
 	NewRegisteredMeter("foo", r).Mark(47)
-	if m := GetOrRegisterMeter("foo", r); 47 != m.Count() {
+	if m := GetOrRegisterMeter("foo", r); m.Count() != 47 {
 		t.Fatal(m)
 	}
 }
@@ -40,7 +40,7 @@ func TestMeterDecay(t *testing.T) {
 func TestMeterNonzero(t *testing.T) {
 	m := NewMeter()
 	m.Mark(3)
-	if count := m.Count(); 3 != count {
+	if count := m.Count(); count != 3 {
 		t.Errorf("m.Count(): 3 != %v\n", count)
 	}
 }
@@ -48,11 +48,11 @@ func TestMeterNonzero(t *testing.T) {
 func TestMeterStop(t *testing.T) {
 	l := len(arbiter.meters)
 	m := NewMeter()
-	if len(arbiter.meters) != l+1 {
+	if l+1 != len(arbiter.meters) {
 		t.Errorf("arbiter.meters: %d != %d\n", l+1, len(arbiter.meters))
 	}
 	m.Stop()
-	if len(arbiter.meters) != l {
+	if l != len(arbiter.meters) {
 		t.Errorf("arbiter.meters: %d != %d\n", l, len(arbiter.meters))
 	}
 }
@@ -67,7 +67,7 @@ func TestMeterSnapshot(t *testing.T) {
 
 func TestMeterZero(t *testing.T) {
 	m := NewMeter()
-	if count := m.Count(); 0 != count {
+	if count := m.Count(); count != 0 {
 		t.Errorf("m.Count(): 0 != %v\n", count)
 	}
 }
diff --git a/metrics/registry_test.go b/metrics/registry_test.go
index a63e485fe..6cfedfd88 100644
--- a/metrics/registry_test.go
+++ b/metrics/registry_test.go
@@ -19,20 +19,20 @@ func TestRegistry(t *testing.T) {
 	i := 0
 	r.Each(func(name string, iface interface{}) {
 		i++
-		if "foo" != name {
+		if name != "foo" {
 			t.Fatal(name)
 		}
 		if _, ok := iface.(Counter); !ok {
 			t.Fatal(iface)
 		}
 	})
-	if 1 != i {
+	if i != 1 {
 		t.Fatal(i)
 	}
 	r.Unregister("foo")
 	i = 0
 	r.Each(func(string, interface{}) { i++ })
-	if 0 != i {
+	if i != 0 {
 		t.Fatal(i)
 	}
 }
@@ -52,7 +52,7 @@ func TestRegistryDuplicate(t *testing.T) {
 			t.Fatal(iface)
 		}
 	})
-	if 1 != i {
+	if i != 1 {
 		t.Fatal(i)
 	}
 }
@@ -60,11 +60,11 @@ func TestRegistryDuplicate(t *testing.T) {
 func TestRegistryGet(t *testing.T) {
 	r := NewRegistry()
 	r.Register("foo", NewCounter())
-	if count := r.Get("foo").(Counter).Count(); 0 != count {
+	if count := r.Get("foo").(Counter).Count(); count != 0 {
 		t.Fatal(count)
 	}
 	r.Get("foo").(Counter).Inc(1)
-	if count := r.Get("foo").(Counter).Count(); 1 != count {
+	if count := r.Get("foo").(Counter).Count(); count != 1 {
 		t.Fatal(count)
 	}
 }
@@ -271,6 +271,9 @@ func TestChildPrefixedRegistryOfChildRegister(t *testing.T) {
 		t.Fatal(err.Error())
 	}
 	err = r2.Register("baz", NewCounter())
+	if err != nil {
+		t.Fatal(err.Error())
+	}
 	c := NewCounter()
 	Register("bars", c)
 
@@ -278,7 +281,7 @@ func TestChildPrefixedRegistryOfChildRegister(t *testing.T) {
 	r2.Each(func(name string, m interface{}) {
 		i++
 		if name != "prefix.prefix2.baz" {
-			//t.Fatal(name)
+			t.Fatal(name)
 		}
 	})
 	if i != 1 {
@@ -294,11 +297,14 @@ func TestWalkRegistries(t *testing.T) {
 		t.Fatal(err.Error())
 	}
 	err = r2.Register("baz", NewCounter())
+	if err != nil {
+		t.Fatal(err.Error())
+	}
 	c := NewCounter()
 	Register("bars", c)
 
 	_, prefix := findPrefix(r2, "")
-	if "prefix.prefix2." != prefix {
+	if prefix != "prefix.prefix2." {
 		t.Fatal(prefix)
 	}
 
diff --git a/metrics/runtime_test.go b/metrics/runtime_test.go
index ebbfd501a..f85f7868f 100644
--- a/metrics/runtime_test.go
+++ b/metrics/runtime_test.go
@@ -22,27 +22,27 @@ func TestRuntimeMemStats(t *testing.T) {
 	zero := runtimeMetrics.MemStats.PauseNs.Count() // Get a "zero" since GC may have run before these tests.
 	runtime.GC()
 	CaptureRuntimeMemStatsOnce(r)
-	if count := runtimeMetrics.MemStats.PauseNs.Count(); 1 != count-zero {
+	if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 1 {
 		t.Fatal(count - zero)
 	}
 	runtime.GC()
 	runtime.GC()
 	CaptureRuntimeMemStatsOnce(r)
-	if count := runtimeMetrics.MemStats.PauseNs.Count(); 3 != count-zero {
+	if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 3 {
 		t.Fatal(count - zero)
 	}
 	for i := 0; i < 256; i++ {
 		runtime.GC()
 	}
 	CaptureRuntimeMemStatsOnce(r)
-	if count := runtimeMetrics.MemStats.PauseNs.Count(); 259 != count-zero {
+	if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 259 {
 		t.Fatal(count - zero)
 	}
 	for i := 0; i < 257; i++ {
 		runtime.GC()
 	}
 	CaptureRuntimeMemStatsOnce(r)
-	if count := runtimeMetrics.MemStats.PauseNs.Count(); 515 != count-zero { // We lost one because there were too many GCs between captures.
+	if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 515 { // We lost one because there were too many GCs between captures.
 		t.Fatal(count - zero)
 	}
 }
diff --git a/metrics/sample.go b/metrics/sample.go
index 5c4845a4f..fa2bfb274 100644
--- a/metrics/sample.go
+++ b/metrics/sample.go
@@ -234,7 +234,7 @@ func (NilSample) Variance() float64 { return 0.0 }
 
 // SampleMax returns the maximum value of the slice of int64.
 func SampleMax(values []int64) int64 {
-	if 0 == len(values) {
+	if len(values) == 0 {
 		return 0
 	}
 	var max int64 = math.MinInt64
@@ -248,7 +248,7 @@ func SampleMax(values []int64) int64 {
 
 // SampleMean returns the mean value of the slice of int64.
 func SampleMean(values []int64) float64 {
-	if 0 == len(values) {
+	if len(values) == 0 {
 		return 0.0
 	}
 	return float64(SampleSum(values)) / float64(len(values))
@@ -256,7 +256,7 @@ func SampleMean(values []int64) float64 {
 
 // SampleMin returns the minimum value of the slice of int64.
 func SampleMin(values []int64) int64 {
-	if 0 == len(values) {
+	if len(values) == 0 {
 		return 0
 	}
 	var min int64 = math.MaxInt64
@@ -382,7 +382,7 @@ func SampleSum(values []int64) int64 {
 
 // SampleVariance returns the variance of the slice of int64.
 func SampleVariance(values []int64) float64 {
-	if 0 == len(values) {
+	if len(values) == 0 {
 		return 0.0
 	}
 	m := SampleMean(values)
diff --git a/metrics/sample_test.go b/metrics/sample_test.go
index 7bab0e3de..3250d8885 100644
--- a/metrics/sample_test.go
+++ b/metrics/sample_test.go
@@ -85,13 +85,13 @@ func TestExpDecaySample10(t *testing.T) {
 	for i := 0; i < 10; i++ {
 		s.Update(int64(i))
 	}
-	if size := s.Count(); 10 != size {
+	if size := s.Count(); size != 10 {
 		t.Errorf("s.Count(): 10 != %v\n", size)
 	}
-	if size := s.Size(); 10 != size {
+	if size := s.Size(); size != 10 {
 		t.Errorf("s.Size(): 10 != %v\n", size)
 	}
-	if l := len(s.Values()); 10 != l {
+	if l := len(s.Values()); l != 10 {
 		t.Errorf("len(s.Values()): 10 != %v\n", l)
 	}
 	for _, v := range s.Values() {
@@ -107,13 +107,13 @@ func TestExpDecaySample100(t *testing.T) {
 	for i := 0; i < 100; i++ {
 		s.Update(int64(i))
 	}
-	if size := s.Count(); 100 != size {
+	if size := s.Count(); size != 100 {
 		t.Errorf("s.Count(): 100 != %v\n", size)
 	}
-	if size := s.Size(); 100 != size {
+	if size := s.Size(); size != 100 {
 		t.Errorf("s.Size(): 100 != %v\n", size)
 	}
-	if l := len(s.Values()); 100 != l {
+	if l := len(s.Values()); l != 100 {
 		t.Errorf("len(s.Values()): 100 != %v\n", l)
 	}
 	for _, v := range s.Values() {
@@ -129,13 +129,13 @@ func TestExpDecaySample1000(t *testing.T) {
 	for i := 0; i < 1000; i++ {
 		s.Update(int64(i))
 	}
-	if size := s.Count(); 1000 != size {
+	if size := s.Count(); size != 1000 {
 		t.Errorf("s.Count(): 1000 != %v\n", size)
 	}
-	if size := s.Size(); 100 != size {
+	if size := s.Size(); size != 100 {
 		t.Errorf("s.Size(): 100 != %v\n", size)
 	}
-	if l := len(s.Values()); 100 != l {
+	if l := len(s.Values()); l != 100 {
 		t.Errorf("len(s.Values()): 100 != %v\n", l)
 	}
 	for _, v := range s.Values() {
@@ -209,13 +209,13 @@ func TestUniformSample(t *testing.T) {
 	for i := 0; i < 1000; i++ {
 		s.Update(int64(i))
 	}
-	if size := s.Count(); 1000 != size {
+	if size := s.Count(); size != 1000 {
 		t.Errorf("s.Count(): 1000 != %v\n", size)
 	}
-	if size := s.Size(); 100 != size {
+	if size := s.Size(); size != 100 {
 		t.Errorf("s.Size(): 100 != %v\n", size)
 	}
-	if l := len(s.Values()); 100 != l {
+	if l := len(s.Values()); l != 100 {
 		t.Errorf("len(s.Values()): 100 != %v\n", l)
 	}
 	for _, v := range s.Values() {
@@ -277,54 +277,54 @@ func benchmarkSample(b *testing.B, s Sample) {
 }
 
 func testExpDecaySampleStatistics(t *testing.T, s Sample) {
-	if count := s.Count(); 10000 != count {
+	if count := s.Count(); count != 10000 {
 		t.Errorf("s.Count(): 10000 != %v\n", count)
 	}
-	if min := s.Min(); 107 != min {
+	if min := s.Min(); min != 107 {
 		t.Errorf("s.Min(): 107 != %v\n", min)
 	}
-	if max := s.Max(); 10000 != max {
+	if max := s.Max(); max != 10000 {
 		t.Errorf("s.Max(): 10000 != %v\n", max)
 	}
-	if mean := s.Mean(); 4965.98 != mean {
+	if mean := s.Mean(); mean != 4965.98 {
 		t.Errorf("s.Mean(): 4965.98 != %v\n", mean)
 	}
-	if stdDev := s.StdDev(); 2959.825156930727 != stdDev {
+	if stdDev := s.StdDev(); stdDev != 2959.825156930727 {
 		t.Errorf("s.StdDev(): 2959.825156930727 != %v\n", stdDev)
 	}
 	ps := s.Percentiles([]float64{0.5, 0.75, 0.99})
-	if 4615 != ps[0] {
+	if ps[0] != 4615 {
 		t.Errorf("median: 4615 != %v\n", ps[0])
 	}
-	if 7672 != ps[1] {
+	if ps[1] != 7672 {
 		t.Errorf("75th percentile: 7672 != %v\n", ps[1])
 	}
-	if 9998.99 != ps[2] {
+	if ps[2] != 9998.99 {
 		t.Errorf("99th percentile: 9998.99 != %v\n", ps[2])
 	}
 }
 
 func testUniformSampleStatistics(t *testing.T, s Sample) {
-	if count := s.Count(); 10000 != count {
+	if count := s.Count(); count != 10000 {
 		t.Errorf("s.Count(): 10000 != %v\n", count)
 	}
-	if min := s.Min(); 37 != min {
+	if min := s.Min(); min != 37 {
 		t.Errorf("s.Min(): 37 != %v\n", min)
 	}
-	if max := s.Max(); 9989 != max {
+	if max := s.Max(); max != 9989 {
 		t.Errorf("s.Max(): 9989 != %v\n", max)
 	}
-	if mean := s.Mean(); 4748.14 != mean {
+	if mean := s.Mean(); mean != 4748.14 {
 		t.Errorf("s.Mean(): 4748.14 != %v\n", mean)
 	}
-	if stdDev := s.StdDev(); 2826.684117548333 != stdDev {
+	if stdDev := s.StdDev(); stdDev != 2826.684117548333 {
 		t.Errorf("s.StdDev(): 2826.684117548333 != %v\n", stdDev)
 	}
 	ps := s.Percentiles([]float64{0.5, 0.75, 0.99})
-	if 4599 != ps[0] {
+	if ps[0] != 4599 {
 		t.Errorf("median: 4599 != %v\n", ps[0])
 	}
-	if 7380.5 != ps[1] {
+	if ps[1] != 7380.5 {
 		t.Errorf("75th percentile: 7380.5 != %v\n", ps[1])
 	}
 	if math.Abs(9986.429999999998-ps[2]) > epsilonPercentile {
diff --git a/metrics/timer.go b/metrics/timer.go
index 89e22208f..a63c9dfb6 100644
--- a/metrics/timer.go
+++ b/metrics/timer.go
@@ -76,10 +76,7 @@ func NewTimer() Timer {
 }
 
 // NilTimer is a no-op Timer.
-type NilTimer struct {
-	h Histogram
-	m Meter
-}
+type NilTimer struct{}
 
 // Count is a no-op.
 func (NilTimer) Count() int64 { return 0 }
diff --git a/metrics/timer_test.go b/metrics/timer_test.go
index 8638a2270..330de609b 100644
--- a/metrics/timer_test.go
+++ b/metrics/timer_test.go
@@ -18,7 +18,7 @@ func BenchmarkTimer(b *testing.B) {
 func TestGetOrRegisterTimer(t *testing.T) {
 	r := NewRegistry()
 	NewRegisteredTimer("foo", r).Update(47)
-	if tm := GetOrRegisterTimer("foo", r); 1 != tm.Count() {
+	if tm := GetOrRegisterTimer("foo", r); tm.Count() != 1 {
 		t.Fatal(tm)
 	}
 }
@@ -27,7 +27,7 @@ func TestTimerExtremes(t *testing.T) {
 	tm := NewTimer()
 	tm.Update(math.MaxInt64)
 	tm.Update(0)
-	if stdDev := tm.StdDev(); 4.611686018427388e+18 != stdDev {
+	if stdDev := tm.StdDev(); stdDev != 4.611686018427388e+18 {
 		t.Errorf("tm.StdDev(): 4.611686018427388e+18 != %v\n", stdDev)
 	}
 }
@@ -35,11 +35,11 @@ func TestTimerExtremes(t *testing.T) {
 func TestTimerStop(t *testing.T) {
 	l := len(arbiter.meters)
 	tm := NewTimer()
-	if len(arbiter.meters) != l+1 {
+	if l+1 != len(arbiter.meters) {
 		t.Errorf("arbiter.meters: %d != %d\n", l+1, len(arbiter.meters))
 	}
 	tm.Stop()
-	if len(arbiter.meters) != l {
+	if l != len(arbiter.meters) {
 		t.Errorf("arbiter.meters: %d != %d\n", l, len(arbiter.meters))
 	}
 }
@@ -54,41 +54,41 @@ func TestTimerFunc(t *testing.T) {
 
 func TestTimerZero(t *testing.T) {
 	tm := NewTimer()
-	if count := tm.Count(); 0 != count {
+	if count := tm.Count(); count != 0 {
 		t.Errorf("tm.Count(): 0 != %v\n", count)
 	}
-	if min := tm.Min(); 0 != min {
+	if min := tm.Min(); min != 0 {
 		t.Errorf("tm.Min(): 0 != %v\n", min)
 	}
-	if max := tm.Max(); 0 != max {
+	if max := tm.Max(); max != 0 {
 		t.Errorf("tm.Max(): 0 != %v\n", max)
 	}
-	if mean := tm.Mean(); 0.0 != mean {
+	if mean := tm.Mean(); mean != 0.0 {
 		t.Errorf("tm.Mean(): 0.0 != %v\n", mean)
 	}
-	if stdDev := tm.StdDev(); 0.0 != stdDev {
+	if stdDev := tm.StdDev(); stdDev != 0.0 {
 		t.Errorf("tm.StdDev(): 0.0 != %v\n", stdDev)
 	}
 	ps := tm.Percentiles([]float64{0.5, 0.75, 0.99})
-	if 0.0 != ps[0] {
+	if ps[0] != 0.0 {
 		t.Errorf("median: 0.0 != %v\n", ps[0])
 	}
-	if 0.0 != ps[1] {
+	if ps[1] != 0.0 {
 		t.Errorf("75th percentile: 0.0 != %v\n", ps[1])
 	}
-	if 0.0 != ps[2] {
+	if ps[2] != 0.0 {
 		t.Errorf("99th percentile: 0.0 != %v\n", ps[2])
 	}
-	if rate1 := tm.Rate1(); 0.0 != rate1 {
+	if rate1 := tm.Rate1(); rate1 != 0.0 {
 		t.Errorf("tm.Rate1(): 0.0 != %v\n", rate1)
 	}
-	if rate5 := tm.Rate5(); 0.0 != rate5 {
+	if rate5 := tm.Rate5(); rate5 != 0.0 {
 		t.Errorf("tm.Rate5(): 0.0 != %v\n", rate5)
 	}
-	if rate15 := tm.Rate15(); 0.0 != rate15 {
+	if rate15 := tm.Rate15(); rate15 != 0.0 {
 		t.Errorf("tm.Rate15(): 0.0 != %v\n", rate15)
 	}
-	if rateMean := tm.RateMean(); 0.0 != rateMean {
+	if rateMean := tm.RateMean(); rateMean != 0.0 {
 		t.Errorf("tm.RateMean(): 0.0 != %v\n", rateMean)
 	}
 }
-- 
GitLab