forked from mirror/client_golang
Merge pull request #16 from prometheus/fix/race-conditions
Fix race conditions in metric methods
This commit is contained in:
commit
8296a0cb49
|
@ -73,7 +73,7 @@ func (metric *counter) ResetAll() {
|
|||
}
|
||||
}
|
||||
|
||||
func (metric counter) String() string {
|
||||
func (metric *counter) String() string {
|
||||
formatString := "[Counter %s]"
|
||||
|
||||
metric.mutex.RLock()
|
||||
|
@ -132,7 +132,7 @@ func (metric *counter) Decrement(labels map[string]string) float64 {
|
|||
return metric.DecrementBy(labels, 1)
|
||||
}
|
||||
|
||||
func (metric counter) MarshalJSON() ([]byte, error) {
|
||||
func (metric *counter) MarshalJSON() ([]byte, error) {
|
||||
metric.mutex.RLock()
|
||||
defer metric.mutex.RUnlock()
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ type gauge struct {
|
|||
values map[string]*gaugeVector
|
||||
}
|
||||
|
||||
func (metric gauge) String() string {
|
||||
func (metric *gauge) String() string {
|
||||
formatString := "[Gauge %s]"
|
||||
|
||||
metric.mutex.RLock()
|
||||
|
@ -80,7 +80,7 @@ func (metric *gauge) ResetAll() {
|
|||
}
|
||||
}
|
||||
|
||||
func (metric gauge) MarshalJSON() ([]byte, error) {
|
||||
func (metric *gauge) MarshalJSON() ([]byte, error) {
|
||||
metric.mutex.RLock()
|
||||
defer metric.mutex.RUnlock()
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ func (h *histogram) Add(labels map[string]string, value float64) {
|
|||
histogram.buckets[lastIndex].Add(value)
|
||||
}
|
||||
|
||||
func (h histogram) String() string {
|
||||
func (h *histogram) String() string {
|
||||
h.mutex.RLock()
|
||||
defer h.mutex.RUnlock()
|
||||
|
||||
|
@ -239,7 +239,7 @@ func formatFloat(value float64) string {
|
|||
return strconv.FormatFloat(value, floatFormat, floatPrecision, floatBitCount)
|
||||
}
|
||||
|
||||
func (h histogram) MarshalJSON() ([]byte, error) {
|
||||
func (h *histogram) MarshalJSON() ([]byte, error) {
|
||||
h.mutex.RLock()
|
||||
defer h.mutex.RUnlock()
|
||||
|
||||
|
|
Loading…
Reference in New Issue