Skip to content

Commit 58f2ce8

Browse files
gballetfjl
authored andcommittedNov 22, 2019
metrics: fix issues reported by staticcheck (ethereum#20365)
1 parent dd21f07 commit 58f2ce8

15 files changed

+109
-105
lines changed
 

‎metrics/counter_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ func TestCounterClear(t *testing.T) {
1414
c := NewCounter()
1515
c.Inc(1)
1616
c.Clear()
17-
if count := c.Count(); 0 != count {
17+
if count := c.Count(); count != 0 {
1818
t.Errorf("c.Count(): 0 != %v\n", count)
1919
}
2020
}
2121

2222
func TestCounterDec1(t *testing.T) {
2323
c := NewCounter()
2424
c.Dec(1)
25-
if count := c.Count(); -1 != count {
25+
if count := c.Count(); count != -1 {
2626
t.Errorf("c.Count(): -1 != %v\n", count)
2727
}
2828
}
2929

3030
func TestCounterDec2(t *testing.T) {
3131
c := NewCounter()
3232
c.Dec(2)
33-
if count := c.Count(); -2 != count {
33+
if count := c.Count(); count != -2 {
3434
t.Errorf("c.Count(): -2 != %v\n", count)
3535
}
3636
}
3737

3838
func TestCounterInc1(t *testing.T) {
3939
c := NewCounter()
4040
c.Inc(1)
41-
if count := c.Count(); 1 != count {
41+
if count := c.Count(); count != 1 {
4242
t.Errorf("c.Count(): 1 != %v\n", count)
4343
}
4444
}
4545

4646
func TestCounterInc2(t *testing.T) {
4747
c := NewCounter()
4848
c.Inc(2)
49-
if count := c.Count(); 2 != count {
49+
if count := c.Count(); count != 2 {
5050
t.Errorf("c.Count(): 2 != %v\n", count)
5151
}
5252
}
@@ -56,22 +56,22 @@ func TestCounterSnapshot(t *testing.T) {
5656
c.Inc(1)
5757
snapshot := c.Snapshot()
5858
c.Inc(1)
59-
if count := snapshot.Count(); 1 != count {
59+
if count := snapshot.Count(); count != 1 {
6060
t.Errorf("c.Count(): 1 != %v\n", count)
6161
}
6262
}
6363

6464
func TestCounterZero(t *testing.T) {
6565
c := NewCounter()
66-
if count := c.Count(); 0 != count {
66+
if count := c.Count(); count != 0 {
6767
t.Errorf("c.Count(): 0 != %v\n", count)
6868
}
6969
}
7070

7171
func TestGetOrRegisterCounter(t *testing.T) {
7272
r := NewRegistry()
7373
NewRegisteredCounter("foo", r).Inc(47)
74-
if c := GetOrRegisterCounter("foo", r); 47 != c.Count() {
74+
if c := GetOrRegisterCounter("foo", r); c.Count() != 47 {
7575
t.Fatal(c)
7676
}
7777
}

‎metrics/gauge_float64_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestFunctionalGaugeFloat64(t *testing.T) {
5353
func TestGetOrRegisterFunctionalGaugeFloat64(t *testing.T) {
5454
r := NewRegistry()
5555
NewRegisteredFunctionalGaugeFloat64("foo", r, func() float64 { return 47 })
56-
if g := GetOrRegisterGaugeFloat64("foo", r); 47 != g.Value() {
56+
if g := GetOrRegisterGaugeFloat64("foo", r); g.Value() != 47 {
5757
t.Fatal(g)
5858
}
5959
}

‎metrics/gauge_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func BenchmarkGuage(b *testing.B) {
1616
func TestGauge(t *testing.T) {
1717
g := NewGauge()
1818
g.Update(int64(47))
19-
if v := g.Value(); 47 != v {
19+
if v := g.Value(); v != 47 {
2020
t.Errorf("g.Value(): 47 != %v\n", v)
2121
}
2222
}
@@ -26,15 +26,15 @@ func TestGaugeSnapshot(t *testing.T) {
2626
g.Update(int64(47))
2727
snapshot := g.Snapshot()
2828
g.Update(int64(0))
29-
if v := snapshot.Value(); 47 != v {
29+
if v := snapshot.Value(); v != 47 {
3030
t.Errorf("g.Value(): 47 != %v\n", v)
3131
}
3232
}
3333

3434
func TestGetOrRegisterGauge(t *testing.T) {
3535
r := NewRegistry()
3636
NewRegisteredGauge("foo", r).Update(47)
37-
if g := GetOrRegisterGauge("foo", r); 47 != g.Value() {
37+
if g := GetOrRegisterGauge("foo", r); g.Value() != 47 {
3838
t.Fatal(g)
3939
}
4040
}
@@ -55,7 +55,7 @@ func TestFunctionalGauge(t *testing.T) {
5555
func TestGetOrRegisterFunctionalGauge(t *testing.T) {
5656
r := NewRegistry()
5757
NewRegisteredFunctionalGauge("foo", r, func() int64 { return 47 })
58-
if g := GetOrRegisterGauge("foo", r); 47 != g.Value() {
58+
if g := GetOrRegisterGauge("foo", r); g.Value() != 47 {
5959
t.Fatal(g)
6060
}
6161
}

‎metrics/histogram_test.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestGetOrRegisterHistogram(t *testing.T) {
1414
r := NewRegistry()
1515
s := NewUniformSample(100)
1616
NewRegisteredHistogram("foo", r, s).Update(47)
17-
if h := GetOrRegisterHistogram("foo", r, s); 1 != h.Count() {
17+
if h := GetOrRegisterHistogram("foo", r, s); h.Count() != 1 {
1818
t.Fatal(h)
1919
}
2020
}
@@ -29,29 +29,29 @@ func TestHistogram10000(t *testing.T) {
2929

3030
func TestHistogramEmpty(t *testing.T) {
3131
h := NewHistogram(NewUniformSample(100))
32-
if count := h.Count(); 0 != count {
32+
if count := h.Count(); count != 0 {
3333
t.Errorf("h.Count(): 0 != %v\n", count)
3434
}
35-
if min := h.Min(); 0 != min {
35+
if min := h.Min(); min != 0 {
3636
t.Errorf("h.Min(): 0 != %v\n", min)
3737
}
38-
if max := h.Max(); 0 != max {
38+
if max := h.Max(); max != 0 {
3939
t.Errorf("h.Max(): 0 != %v\n", max)
4040
}
41-
if mean := h.Mean(); 0.0 != mean {
41+
if mean := h.Mean(); mean != 0.0 {
4242
t.Errorf("h.Mean(): 0.0 != %v\n", mean)
4343
}
44-
if stdDev := h.StdDev(); 0.0 != stdDev {
44+
if stdDev := h.StdDev(); stdDev != 0.0 {
4545
t.Errorf("h.StdDev(): 0.0 != %v\n", stdDev)
4646
}
4747
ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
48-
if 0.0 != ps[0] {
48+
if ps[0] != 0.0 {
4949
t.Errorf("median: 0.0 != %v\n", ps[0])
5050
}
51-
if 0.0 != ps[1] {
51+
if ps[1] != 0.0 {
5252
t.Errorf("75th percentile: 0.0 != %v\n", ps[1])
5353
}
54-
if 0.0 != ps[2] {
54+
if ps[2] != 0.0 {
5555
t.Errorf("99th percentile: 0.0 != %v\n", ps[2])
5656
}
5757
}
@@ -67,29 +67,29 @@ func TestHistogramSnapshot(t *testing.T) {
6767
}
6868

6969
func testHistogram10000(t *testing.T, h Histogram) {
70-
if count := h.Count(); 10000 != count {
70+
if count := h.Count(); count != 10000 {
7171
t.Errorf("h.Count(): 10000 != %v\n", count)
7272
}
73-
if min := h.Min(); 1 != min {
73+
if min := h.Min(); min != 1 {
7474
t.Errorf("h.Min(): 1 != %v\n", min)
7575
}
76-
if max := h.Max(); 10000 != max {
76+
if max := h.Max(); max != 10000 {
7777
t.Errorf("h.Max(): 10000 != %v\n", max)
7878
}
79-
if mean := h.Mean(); 5000.5 != mean {
79+
if mean := h.Mean(); mean != 5000.5 {
8080
t.Errorf("h.Mean(): 5000.5 != %v\n", mean)
8181
}
82-
if stdDev := h.StdDev(); 2886.751331514372 != stdDev {
82+
if stdDev := h.StdDev(); stdDev != 2886.751331514372 {
8383
t.Errorf("h.StdDev(): 2886.751331514372 != %v\n", stdDev)
8484
}
8585
ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
86-
if 5000.5 != ps[0] {
86+
if ps[0] != 5000.5 {
8787
t.Errorf("median: 5000.5 != %v\n", ps[0])
8888
}
89-
if 7500.75 != ps[1] {
89+
if ps[1] != 7500.75 {
9090
t.Errorf("75th percentile: 7500.75 != %v\n", ps[1])
9191
}
92-
if 9900.99 != ps[2] {
92+
if ps[2] != 9900.99 {
9393
t.Errorf("99th percentile: 9900.99 != %v\n", ps[2])
9494
}
9595
}

‎metrics/influxdb/influxdb.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func InfluxDBWithTags(r metrics.Registry, d time.Duration, url, database, userna
6262
func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password, namespace string, tags map[string]string) error {
6363
u, err := uurl.Parse(url)
6464
if err != nil {
65-
return fmt.Errorf("Unable to parse InfluxDB. url: %s, err: %v", url, err)
65+
return fmt.Errorf("unable to parse InfluxDB. url: %s, err: %v", url, err)
6666
}
6767

6868
rep := &reporter{
@@ -76,11 +76,11 @@ func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password,
7676
cache: make(map[string]int64),
7777
}
7878
if err := rep.makeClient(); err != nil {
79-
return fmt.Errorf("Unable to make InfluxDB client. err: %v", err)
79+
return fmt.Errorf("unable to make InfluxDB client. err: %v", err)
8080
}
8181

8282
if err := rep.send(); err != nil {
83-
return fmt.Errorf("Unable to send to InfluxDB. err: %v", err)
83+
return fmt.Errorf("unable to send to InfluxDB. err: %v", err)
8484
}
8585

8686
return nil

‎metrics/json_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestRegistryMarshallJSON(t *testing.T) {
1212
r := NewRegistry()
1313
r.Register("counter", NewCounter())
1414
enc.Encode(r)
15-
if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s {
15+
if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" {
1616
t.Fatalf(s)
1717
}
1818
}

‎metrics/librato/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (c *LibratoClient) PostMetrics(batch Batch) (err error) {
9696
if body, err = ioutil.ReadAll(resp.Body); err != nil {
9797
body = []byte(fmt.Sprintf("(could not fetch response body for error: %s)", err))
9898
}
99-
err = fmt.Errorf("Unable to post to Librato: %d %s %s", resp.StatusCode, resp.Status, string(body))
99+
err = fmt.Errorf("unable to post to Librato: %d %s %s", resp.StatusCode, resp.Status, string(body))
100100
}
101101
return
102102
}

‎metrics/librato/librato.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ func Librato(r metrics.Registry, d time.Duration, e string, t string, s string,
4242

4343
func (rep *Reporter) Run() {
4444
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")
45-
ticker := time.Tick(rep.Interval)
45+
ticker := time.NewTicker(rep.Interval)
46+
defer ticker.Stop()
4647
metricsApi := &LibratoClient{rep.Email, rep.Token}
47-
for now := range ticker {
48+
for now := range ticker.C {
4849
var metrics Batch
4950
var err error
5051
if metrics, err = rep.BuildRequest(now, rep.Registry); err != nil {

‎metrics/meter_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func BenchmarkMeter(b *testing.B) {
1616
func TestGetOrRegisterMeter(t *testing.T) {
1717
r := NewRegistry()
1818
NewRegisteredMeter("foo", r).Mark(47)
19-
if m := GetOrRegisterMeter("foo", r); 47 != m.Count() {
19+
if m := GetOrRegisterMeter("foo", r); m.Count() != 47 {
2020
t.Fatal(m)
2121
}
2222
}
@@ -40,19 +40,19 @@ func TestMeterDecay(t *testing.T) {
4040
func TestMeterNonzero(t *testing.T) {
4141
m := NewMeter()
4242
m.Mark(3)
43-
if count := m.Count(); 3 != count {
43+
if count := m.Count(); count != 3 {
4444
t.Errorf("m.Count(): 3 != %v\n", count)
4545
}
4646
}
4747

4848
func TestMeterStop(t *testing.T) {
4949
l := len(arbiter.meters)
5050
m := NewMeter()
51-
if len(arbiter.meters) != l+1 {
51+
if l+1 != len(arbiter.meters) {
5252
t.Errorf("arbiter.meters: %d != %d\n", l+1, len(arbiter.meters))
5353
}
5454
m.Stop()
55-
if len(arbiter.meters) != l {
55+
if l != len(arbiter.meters) {
5656
t.Errorf("arbiter.meters: %d != %d\n", l, len(arbiter.meters))
5757
}
5858
}
@@ -67,7 +67,7 @@ func TestMeterSnapshot(t *testing.T) {
6767

6868
func TestMeterZero(t *testing.T) {
6969
m := NewMeter()
70-
if count := m.Count(); 0 != count {
70+
if count := m.Count(); count != 0 {
7171
t.Errorf("m.Count(): 0 != %v\n", count)
7272
}
7373
}

‎metrics/registry_test.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ func TestRegistry(t *testing.T) {
1919
i := 0
2020
r.Each(func(name string, iface interface{}) {
2121
i++
22-
if "foo" != name {
22+
if name != "foo" {
2323
t.Fatal(name)
2424
}
2525
if _, ok := iface.(Counter); !ok {
2626
t.Fatal(iface)
2727
}
2828
})
29-
if 1 != i {
29+
if i != 1 {
3030
t.Fatal(i)
3131
}
3232
r.Unregister("foo")
3333
i = 0
3434
r.Each(func(string, interface{}) { i++ })
35-
if 0 != i {
35+
if i != 0 {
3636
t.Fatal(i)
3737
}
3838
}
@@ -52,19 +52,19 @@ func TestRegistryDuplicate(t *testing.T) {
5252
t.Fatal(iface)
5353
}
5454
})
55-
if 1 != i {
55+
if i != 1 {
5656
t.Fatal(i)
5757
}
5858
}
5959

6060
func TestRegistryGet(t *testing.T) {
6161
r := NewRegistry()
6262
r.Register("foo", NewCounter())
63-
if count := r.Get("foo").(Counter).Count(); 0 != count {
63+
if count := r.Get("foo").(Counter).Count(); count != 0 {
6464
t.Fatal(count)
6565
}
6666
r.Get("foo").(Counter).Inc(1)
67-
if count := r.Get("foo").(Counter).Count(); 1 != count {
67+
if count := r.Get("foo").(Counter).Count(); count != 1 {
6868
t.Fatal(count)
6969
}
7070
}
@@ -271,14 +271,17 @@ func TestChildPrefixedRegistryOfChildRegister(t *testing.T) {
271271
t.Fatal(err.Error())
272272
}
273273
err = r2.Register("baz", NewCounter())
274+
if err != nil {
275+
t.Fatal(err.Error())
276+
}
274277
c := NewCounter()
275278
Register("bars", c)
276279

277280
i := 0
278281
r2.Each(func(name string, m interface{}) {
279282
i++
280283
if name != "prefix.prefix2.baz" {
281-
//t.Fatal(name)
284+
t.Fatal(name)
282285
}
283286
})
284287
if i != 1 {
@@ -294,11 +297,14 @@ func TestWalkRegistries(t *testing.T) {
294297
t.Fatal(err.Error())
295298
}
296299
err = r2.Register("baz", NewCounter())
300+
if err != nil {
301+
t.Fatal(err.Error())
302+
}
297303
c := NewCounter()
298304
Register("bars", c)
299305

300306
_, prefix := findPrefix(r2, "")
301-
if "prefix.prefix2." != prefix {
307+
if prefix != "prefix.prefix2." {
302308
t.Fatal(prefix)
303309
}
304310

‎metrics/runtime_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ func TestRuntimeMemStats(t *testing.T) {
2222
zero := runtimeMetrics.MemStats.PauseNs.Count() // Get a "zero" since GC may have run before these tests.
2323
runtime.GC()
2424
CaptureRuntimeMemStatsOnce(r)
25-
if count := runtimeMetrics.MemStats.PauseNs.Count(); 1 != count-zero {
25+
if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 1 {
2626
t.Fatal(count - zero)
2727
}
2828
runtime.GC()
2929
runtime.GC()
3030
CaptureRuntimeMemStatsOnce(r)
31-
if count := runtimeMetrics.MemStats.PauseNs.Count(); 3 != count-zero {
31+
if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 3 {
3232
t.Fatal(count - zero)
3333
}
3434
for i := 0; i < 256; i++ {
3535
runtime.GC()
3636
}
3737
CaptureRuntimeMemStatsOnce(r)
38-
if count := runtimeMetrics.MemStats.PauseNs.Count(); 259 != count-zero {
38+
if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 259 {
3939
t.Fatal(count - zero)
4040
}
4141
for i := 0; i < 257; i++ {
4242
runtime.GC()
4343
}
4444
CaptureRuntimeMemStatsOnce(r)
45-
if count := runtimeMetrics.MemStats.PauseNs.Count(); 515 != count-zero { // We lost one because there were too many GCs between captures.
45+
if count := runtimeMetrics.MemStats.PauseNs.Count(); count-zero != 515 { // We lost one because there were too many GCs between captures.
4646
t.Fatal(count - zero)
4747
}
4848
}

‎metrics/sample.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (NilSample) Variance() float64 { return 0.0 }
234234

235235
// SampleMax returns the maximum value of the slice of int64.
236236
func SampleMax(values []int64) int64 {
237-
if 0 == len(values) {
237+
if len(values) == 0 {
238238
return 0
239239
}
240240
var max int64 = math.MinInt64
@@ -248,15 +248,15 @@ func SampleMax(values []int64) int64 {
248248

249249
// SampleMean returns the mean value of the slice of int64.
250250
func SampleMean(values []int64) float64 {
251-
if 0 == len(values) {
251+
if len(values) == 0 {
252252
return 0.0
253253
}
254254
return float64(SampleSum(values)) / float64(len(values))
255255
}
256256

257257
// SampleMin returns the minimum value of the slice of int64.
258258
func SampleMin(values []int64) int64 {
259-
if 0 == len(values) {
259+
if len(values) == 0 {
260260
return 0
261261
}
262262
var min int64 = math.MaxInt64
@@ -382,7 +382,7 @@ func SampleSum(values []int64) int64 {
382382

383383
// SampleVariance returns the variance of the slice of int64.
384384
func SampleVariance(values []int64) float64 {
385-
if 0 == len(values) {
385+
if len(values) == 0 {
386386
return 0.0
387387
}
388388
m := SampleMean(values)

‎metrics/sample_test.go

+27-27
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ func TestExpDecaySample10(t *testing.T) {
8585
for i := 0; i < 10; i++ {
8686
s.Update(int64(i))
8787
}
88-
if size := s.Count(); 10 != size {
88+
if size := s.Count(); size != 10 {
8989
t.Errorf("s.Count(): 10 != %v\n", size)
9090
}
91-
if size := s.Size(); 10 != size {
91+
if size := s.Size(); size != 10 {
9292
t.Errorf("s.Size(): 10 != %v\n", size)
9393
}
94-
if l := len(s.Values()); 10 != l {
94+
if l := len(s.Values()); l != 10 {
9595
t.Errorf("len(s.Values()): 10 != %v\n", l)
9696
}
9797
for _, v := range s.Values() {
@@ -107,13 +107,13 @@ func TestExpDecaySample100(t *testing.T) {
107107
for i := 0; i < 100; i++ {
108108
s.Update(int64(i))
109109
}
110-
if size := s.Count(); 100 != size {
110+
if size := s.Count(); size != 100 {
111111
t.Errorf("s.Count(): 100 != %v\n", size)
112112
}
113-
if size := s.Size(); 100 != size {
113+
if size := s.Size(); size != 100 {
114114
t.Errorf("s.Size(): 100 != %v\n", size)
115115
}
116-
if l := len(s.Values()); 100 != l {
116+
if l := len(s.Values()); l != 100 {
117117
t.Errorf("len(s.Values()): 100 != %v\n", l)
118118
}
119119
for _, v := range s.Values() {
@@ -129,13 +129,13 @@ func TestExpDecaySample1000(t *testing.T) {
129129
for i := 0; i < 1000; i++ {
130130
s.Update(int64(i))
131131
}
132-
if size := s.Count(); 1000 != size {
132+
if size := s.Count(); size != 1000 {
133133
t.Errorf("s.Count(): 1000 != %v\n", size)
134134
}
135-
if size := s.Size(); 100 != size {
135+
if size := s.Size(); size != 100 {
136136
t.Errorf("s.Size(): 100 != %v\n", size)
137137
}
138-
if l := len(s.Values()); 100 != l {
138+
if l := len(s.Values()); l != 100 {
139139
t.Errorf("len(s.Values()): 100 != %v\n", l)
140140
}
141141
for _, v := range s.Values() {
@@ -209,13 +209,13 @@ func TestUniformSample(t *testing.T) {
209209
for i := 0; i < 1000; i++ {
210210
s.Update(int64(i))
211211
}
212-
if size := s.Count(); 1000 != size {
212+
if size := s.Count(); size != 1000 {
213213
t.Errorf("s.Count(): 1000 != %v\n", size)
214214
}
215-
if size := s.Size(); 100 != size {
215+
if size := s.Size(); size != 100 {
216216
t.Errorf("s.Size(): 100 != %v\n", size)
217217
}
218-
if l := len(s.Values()); 100 != l {
218+
if l := len(s.Values()); l != 100 {
219219
t.Errorf("len(s.Values()): 100 != %v\n", l)
220220
}
221221
for _, v := range s.Values() {
@@ -277,54 +277,54 @@ func benchmarkSample(b *testing.B, s Sample) {
277277
}
278278

279279
func testExpDecaySampleStatistics(t *testing.T, s Sample) {
280-
if count := s.Count(); 10000 != count {
280+
if count := s.Count(); count != 10000 {
281281
t.Errorf("s.Count(): 10000 != %v\n", count)
282282
}
283-
if min := s.Min(); 107 != min {
283+
if min := s.Min(); min != 107 {
284284
t.Errorf("s.Min(): 107 != %v\n", min)
285285
}
286-
if max := s.Max(); 10000 != max {
286+
if max := s.Max(); max != 10000 {
287287
t.Errorf("s.Max(): 10000 != %v\n", max)
288288
}
289-
if mean := s.Mean(); 4965.98 != mean {
289+
if mean := s.Mean(); mean != 4965.98 {
290290
t.Errorf("s.Mean(): 4965.98 != %v\n", mean)
291291
}
292-
if stdDev := s.StdDev(); 2959.825156930727 != stdDev {
292+
if stdDev := s.StdDev(); stdDev != 2959.825156930727 {
293293
t.Errorf("s.StdDev(): 2959.825156930727 != %v\n", stdDev)
294294
}
295295
ps := s.Percentiles([]float64{0.5, 0.75, 0.99})
296-
if 4615 != ps[0] {
296+
if ps[0] != 4615 {
297297
t.Errorf("median: 4615 != %v\n", ps[0])
298298
}
299-
if 7672 != ps[1] {
299+
if ps[1] != 7672 {
300300
t.Errorf("75th percentile: 7672 != %v\n", ps[1])
301301
}
302-
if 9998.99 != ps[2] {
302+
if ps[2] != 9998.99 {
303303
t.Errorf("99th percentile: 9998.99 != %v\n", ps[2])
304304
}
305305
}
306306

307307
func testUniformSampleStatistics(t *testing.T, s Sample) {
308-
if count := s.Count(); 10000 != count {
308+
if count := s.Count(); count != 10000 {
309309
t.Errorf("s.Count(): 10000 != %v\n", count)
310310
}
311-
if min := s.Min(); 37 != min {
311+
if min := s.Min(); min != 37 {
312312
t.Errorf("s.Min(): 37 != %v\n", min)
313313
}
314-
if max := s.Max(); 9989 != max {
314+
if max := s.Max(); max != 9989 {
315315
t.Errorf("s.Max(): 9989 != %v\n", max)
316316
}
317-
if mean := s.Mean(); 4748.14 != mean {
317+
if mean := s.Mean(); mean != 4748.14 {
318318
t.Errorf("s.Mean(): 4748.14 != %v\n", mean)
319319
}
320-
if stdDev := s.StdDev(); 2826.684117548333 != stdDev {
320+
if stdDev := s.StdDev(); stdDev != 2826.684117548333 {
321321
t.Errorf("s.StdDev(): 2826.684117548333 != %v\n", stdDev)
322322
}
323323
ps := s.Percentiles([]float64{0.5, 0.75, 0.99})
324-
if 4599 != ps[0] {
324+
if ps[0] != 4599 {
325325
t.Errorf("median: 4599 != %v\n", ps[0])
326326
}
327-
if 7380.5 != ps[1] {
327+
if ps[1] != 7380.5 {
328328
t.Errorf("75th percentile: 7380.5 != %v\n", ps[1])
329329
}
330330
if math.Abs(9986.429999999998-ps[2]) > epsilonPercentile {

‎metrics/timer.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ func NewTimer() Timer {
7676
}
7777

7878
// NilTimer is a no-op Timer.
79-
type NilTimer struct {
80-
h Histogram
81-
m Meter
82-
}
79+
type NilTimer struct{}
8380

8481
// Count is a no-op.
8582
func (NilTimer) Count() int64 { return 0 }

‎metrics/timer_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func BenchmarkTimer(b *testing.B) {
1818
func TestGetOrRegisterTimer(t *testing.T) {
1919
r := NewRegistry()
2020
NewRegisteredTimer("foo", r).Update(47)
21-
if tm := GetOrRegisterTimer("foo", r); 1 != tm.Count() {
21+
if tm := GetOrRegisterTimer("foo", r); tm.Count() != 1 {
2222
t.Fatal(tm)
2323
}
2424
}
@@ -27,19 +27,19 @@ func TestTimerExtremes(t *testing.T) {
2727
tm := NewTimer()
2828
tm.Update(math.MaxInt64)
2929
tm.Update(0)
30-
if stdDev := tm.StdDev(); 4.611686018427388e+18 != stdDev {
30+
if stdDev := tm.StdDev(); stdDev != 4.611686018427388e+18 {
3131
t.Errorf("tm.StdDev(): 4.611686018427388e+18 != %v\n", stdDev)
3232
}
3333
}
3434

3535
func TestTimerStop(t *testing.T) {
3636
l := len(arbiter.meters)
3737
tm := NewTimer()
38-
if len(arbiter.meters) != l+1 {
38+
if l+1 != len(arbiter.meters) {
3939
t.Errorf("arbiter.meters: %d != %d\n", l+1, len(arbiter.meters))
4040
}
4141
tm.Stop()
42-
if len(arbiter.meters) != l {
42+
if l != len(arbiter.meters) {
4343
t.Errorf("arbiter.meters: %d != %d\n", l, len(arbiter.meters))
4444
}
4545
}
@@ -54,41 +54,41 @@ func TestTimerFunc(t *testing.T) {
5454

5555
func TestTimerZero(t *testing.T) {
5656
tm := NewTimer()
57-
if count := tm.Count(); 0 != count {
57+
if count := tm.Count(); count != 0 {
5858
t.Errorf("tm.Count(): 0 != %v\n", count)
5959
}
60-
if min := tm.Min(); 0 != min {
60+
if min := tm.Min(); min != 0 {
6161
t.Errorf("tm.Min(): 0 != %v\n", min)
6262
}
63-
if max := tm.Max(); 0 != max {
63+
if max := tm.Max(); max != 0 {
6464
t.Errorf("tm.Max(): 0 != %v\n", max)
6565
}
66-
if mean := tm.Mean(); 0.0 != mean {
66+
if mean := tm.Mean(); mean != 0.0 {
6767
t.Errorf("tm.Mean(): 0.0 != %v\n", mean)
6868
}
69-
if stdDev := tm.StdDev(); 0.0 != stdDev {
69+
if stdDev := tm.StdDev(); stdDev != 0.0 {
7070
t.Errorf("tm.StdDev(): 0.0 != %v\n", stdDev)
7171
}
7272
ps := tm.Percentiles([]float64{0.5, 0.75, 0.99})
73-
if 0.0 != ps[0] {
73+
if ps[0] != 0.0 {
7474
t.Errorf("median: 0.0 != %v\n", ps[0])
7575
}
76-
if 0.0 != ps[1] {
76+
if ps[1] != 0.0 {
7777
t.Errorf("75th percentile: 0.0 != %v\n", ps[1])
7878
}
79-
if 0.0 != ps[2] {
79+
if ps[2] != 0.0 {
8080
t.Errorf("99th percentile: 0.0 != %v\n", ps[2])
8181
}
82-
if rate1 := tm.Rate1(); 0.0 != rate1 {
82+
if rate1 := tm.Rate1(); rate1 != 0.0 {
8383
t.Errorf("tm.Rate1(): 0.0 != %v\n", rate1)
8484
}
85-
if rate5 := tm.Rate5(); 0.0 != rate5 {
85+
if rate5 := tm.Rate5(); rate5 != 0.0 {
8686
t.Errorf("tm.Rate5(): 0.0 != %v\n", rate5)
8787
}
88-
if rate15 := tm.Rate15(); 0.0 != rate15 {
88+
if rate15 := tm.Rate15(); rate15 != 0.0 {
8989
t.Errorf("tm.Rate15(): 0.0 != %v\n", rate15)
9090
}
91-
if rateMean := tm.RateMean(); 0.0 != rateMean {
91+
if rateMean := tm.RateMean(); rateMean != 0.0 {
9292
t.Errorf("tm.RateMean(): 0.0 != %v\n", rateMean)
9393
}
9494
}

0 commit comments

Comments
 (0)
Please sign in to comment.