fix data race when accessing h.sum during histogram marshaling
This commit is contained in:
parent
93f7956e2a
commit
f6ff0f32a2
14
histogram.go
14
histogram.go
@ -246,14 +246,22 @@ func (h *Histogram) marshalTo(prefix string, w io.Writer) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
name, filters := splitMetricName(prefix)
|
name, filters := splitMetricName(prefix)
|
||||||
if float64(int64(h.sum)) == h.sum {
|
sum := h.getSum()
|
||||||
fmt.Fprintf(w, "%s_sum%s %d\n", name, filters, int64(h.sum))
|
if float64(int64(sum)) == sum {
|
||||||
|
fmt.Fprintf(w, "%s_sum%s %d\n", name, filters, int64(sum))
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "%s_sum%s %g\n", name, filters, h.sum)
|
fmt.Fprintf(w, "%s_sum%s %g\n", name, filters, sum)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "%s_count%s %d\n", name, filters, countTotal)
|
fmt.Fprintf(w, "%s_count%s %d\n", name, filters, countTotal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Histogram) getSum() float64 {
|
||||||
|
h.mu.Lock()
|
||||||
|
sum := h.sum
|
||||||
|
h.mu.Unlock()
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
func getBucketIdxAndOffset(v float64) (int, uint) {
|
func getBucketIdxAndOffset(v float64) (int, uint) {
|
||||||
if v < 0 {
|
if v < 0 {
|
||||||
panic(fmt.Errorf("BUG: v must be positive; got %g", v))
|
panic(fmt.Errorf("BUG: v must be positive; got %g", v))
|
||||||
|
Loading…
Reference in New Issue
Block a user