Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit b55884e

Browse files
committed
Switch to using signed int64s for gauges.
1 parent b05b08d commit b55884e

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

metrics.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
// Gauges
1212
//
13-
// A gauge returns instantaneous measurements of something using 64-bit floating
14-
// point values.
13+
// A gauge returns instantaneous measurements of something using signed, 64-bit
14+
// integers. This value does not need to be monotonic.
1515
//
1616
// Histograms
1717
//
@@ -84,18 +84,18 @@ func (c Counter) SetBatchFunc(key interface{}, init func(), f func() uint64) {
8484
type Gauge string
8585

8686
// Set the gauge's value to the given value.
87-
func (g Gauge) Set(value float64) {
87+
func (g Gauge) Set(value int64) {
8888
gm.Lock()
8989
defer gm.Unlock()
9090

91-
gauges[string(g)] = func() float64 {
91+
gauges[string(g)] = func() int64 {
9292
return value
9393
}
9494
}
9595

9696
// SetFunc sets the gauge's value to the lazily-called return value of the given
9797
// function.
98-
func (g Gauge) SetFunc(f func() float64) {
98+
func (g Gauge) SetFunc(f func() int64) {
9999
gm.Lock()
100100
defer gm.Unlock()
101101

@@ -105,7 +105,7 @@ func (g Gauge) SetFunc(f func() float64) {
105105
// SetBatchFunc sets the gauge's value to the lazily-called return value of the
106106
// given function, with an additional initializer function for a related batch
107107
// of gauges, all of which are keyed by an arbitrary value.
108-
func (g Gauge) SetBatchFunc(key interface{}, init func(), f func() float64) {
108+
func (g Gauge) SetBatchFunc(key interface{}, init func(), f func() int64) {
109109
gm.Lock()
110110
defer gm.Unlock()
111111

@@ -128,13 +128,13 @@ func Reset() {
128128

129129
counters = make(map[string]uint64)
130130
counterFuncs = make(map[string]func() uint64)
131-
gauges = make(map[string]func() float64)
131+
gauges = make(map[string]func() int64)
132132
histograms = make(map[string]*Histogram)
133133
inits = make(map[interface{}]func())
134134
}
135135

136136
// Snapshot returns a copy of the values of all registered counters and gauges.
137-
func Snapshot() (c map[string]uint64, g map[string]float64) {
137+
func Snapshot() (c map[string]uint64, g map[string]int64) {
138138
cm.Lock()
139139
defer cm.Unlock()
140140

@@ -157,7 +157,7 @@ func Snapshot() (c map[string]uint64, g map[string]float64) {
157157
c[n] = f()
158158
}
159159

160-
g = make(map[string]float64, len(gauges))
160+
g = make(map[string]int64, len(gauges))
161161
for n, f := range gauges {
162162
g[n] = f()
163163
}
@@ -225,23 +225,23 @@ func (h *Histogram) merge() {
225225
h.m = h.hist.Merge()
226226
}
227227

228-
func (h *Histogram) valueAt(q float64) func() float64 {
229-
return func() float64 {
228+
func (h *Histogram) valueAt(q float64) func() int64 {
229+
return func() int64 {
230230
h.rw.RLock()
231231
defer h.rw.RUnlock()
232232

233233
if h.m == nil {
234234
return 0
235235
}
236236

237-
return float64(h.m.ValueAtQuantile(q))
237+
return h.m.ValueAtQuantile(q)
238238
}
239239
}
240240

241241
var (
242242
counters = make(map[string]uint64)
243243
counterFuncs = make(map[string]func() uint64)
244-
gauges = make(map[string]func() float64)
244+
gauges = make(map[string]func() int64)
245245
inits = make(map[interface{}]func())
246246
histograms = make(map[string]*Histogram)
247247

metrics_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ func TestCounterBatchFunc(t *testing.T) {
6969
func TestGaugeValue(t *testing.T) {
7070
metrics.Reset()
7171

72-
metrics.Gauge("whee").Set(100.01)
72+
metrics.Gauge("whee").Set(-100)
7373

7474
_, gauges := metrics.Snapshot()
75-
if v, want := gauges["whee"], 100.01; v != want {
75+
if v, want := gauges["whee"], int64(-100); v != want {
7676
t.Errorf("Gauge was %v, but expected %v", v, want)
7777
}
7878
}
7979

8080
func TestGaugeFunc(t *testing.T) {
8181
metrics.Reset()
8282

83-
metrics.Gauge("whee").SetFunc(func() float64 {
84-
return 100.03
83+
metrics.Gauge("whee").SetFunc(func() int64 {
84+
return -100
8585
})
8686

8787
_, gauges := metrics.Snapshot()
88-
if v, want := gauges["whee"], 100.03; v != want {
88+
if v, want := gauges["whee"], int64(-100); v != want {
8989
t.Errorf("Gauge was %v, but expected %v", v, want)
9090
}
9191
}
@@ -102,27 +102,27 @@ func TestHistogram(t *testing.T) {
102102

103103
_, gauges := metrics.Snapshot()
104104

105-
if v, want := gauges["heyo.P50"], 71.0; v != want {
105+
if v, want := gauges["heyo.P50"], int64(71); v != want {
106106
t.Errorf("P50 was %v, but expected %v", v, want)
107107
}
108108

109-
if v, want := gauges["heyo.P75"], 87.0; v != want {
109+
if v, want := gauges["heyo.P75"], int64(87); v != want {
110110
t.Errorf("P75 was %v, but expected %v", v, want)
111111
}
112112

113-
if v, want := gauges["heyo.P90"], 95.0; v != want {
113+
if v, want := gauges["heyo.P90"], int64(95); v != want {
114114
t.Errorf("P90 was %v, but expected %v", v, want)
115115
}
116116

117-
if v, want := gauges["heyo.P95"], 98.0; v != want {
117+
if v, want := gauges["heyo.P95"], int64(98); v != want {
118118
t.Errorf("P95 was %v, but expected %v", v, want)
119119
}
120120

121-
if v, want := gauges["heyo.P99"], 100.0; v != want {
121+
if v, want := gauges["heyo.P99"], int64(100); v != want {
122122
t.Errorf("P99 was %v, but expected %v", v, want)
123123
}
124124

125-
if v, want := gauges["heyo.P999"], 100.0; v != want {
125+
if v, want := gauges["heyo.P999"], int64(100); v != want {
126126
t.Errorf("P999 was %v, but expected %v", v, want)
127127
}
128128
}

runtime/fds.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ func getFDUsage() (uint64, error) {
2424
}
2525

2626
func init() {
27-
metrics.Gauge("FileDescriptors.Max").SetFunc(func() float64 {
27+
metrics.Gauge("FileDescriptors.Max").SetFunc(func() int64 {
2828
v, err := getFDLimit()
2929
if err != nil {
3030
return 0
3131
}
32-
return float64(v)
32+
return int64(v)
3333
})
3434

35-
metrics.Gauge("FileDescriptors.Used").SetFunc(func() float64 {
35+
metrics.Gauge("FileDescriptors.Used").SetFunc(func() int64 {
3636
v, err := getFDUsage()
3737
if err != nil {
3838
return 0
3939
}
40-
return float64(v)
40+
return int64(v)
4141
})
4242
}

runtime/memstats.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ func (msg *memStatGauges) totalPause() uint64 {
3535
return msg.stats.PauseTotalNs
3636
}
3737

38-
func (msg *memStatGauges) lastPause() float64 {
39-
return float64(msg.stats.LastGC)
38+
func (msg *memStatGauges) lastPause() int64 {
39+
return int64(msg.stats.LastGC)
4040
}
4141

42-
func (msg *memStatGauges) alloc() float64 {
43-
return float64(msg.stats.Alloc)
42+
func (msg *memStatGauges) alloc() int64 {
43+
return int64(msg.stats.Alloc)
4444
}
4545

46-
func (msg *memStatGauges) objects() float64 {
47-
return float64(msg.stats.HeapObjects)
46+
func (msg *memStatGauges) objects() int64 {
47+
return int64(msg.stats.HeapObjects)
4848
}

0 commit comments

Comments
 (0)