Skip to content

Commit 04b5a37

Browse files
committed
rawvalue: fix thread safety and sum
1 parent a1546ad commit 04b5a37

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

val.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ func (v *RawVal) Observe(val float64) {
292292
// Stats implements the StatSource interface.
293293
func (v *RawVal) Stats(cb func(key SeriesKey, field string, val float64)) {
294294
v.mtx.Lock()
295+
defer v.mtx.Unlock()
295296
cb(v.key, "recent", v.value)
296-
v.mtx.Unlock()
297297
for _, s := range v.stats {
298298
field, value := s()
299299
cb(v.key, field, value)
@@ -320,9 +320,9 @@ func Count() (observe func(val float64), stat func() (field string, val float64)
320320

321321
// Sum is a value aggregator that summarizes the values measured.
322322
func Sum() (observe func(val float64), stat func() (field string, val float64)) {
323-
var sum int
323+
var sum float64
324324
return func(val float64) {
325-
sum += int(val)
325+
sum += val
326326
}, func() (field string, val float64) {
327327
return "sum", float64(sum)
328328
}

0 commit comments

Comments
 (0)