diff --git a/metrics/counter.go b/metrics/counter.go index 05ec419585..cb81599c21 100644 --- a/metrics/counter.go +++ b/metrics/counter.go @@ -82,7 +82,6 @@ func (c counterSnapshot) Count() int64 { return int64(c) } // NilCounter is a no-op Counter. type NilCounter struct{} -// Clear is a no-op. func (NilCounter) Clear() {} func (NilCounter) Dec(i int64) {} func (NilCounter) Inc(i int64) {} diff --git a/metrics/ewma.go b/metrics/ewma.go index e695c48d82..1d7a4f00cf 100644 --- a/metrics/ewma.go +++ b/metrics/ewma.go @@ -39,12 +39,12 @@ func NewEWMA15() EWMA { return NewEWMA(1 - math.Exp(-5.0/60.0/15)) } -// eWMASnapshot is a read-only copy of another EWMA. -type eWMASnapshot float64 +// ewmaSnapshot is a read-only copy of another EWMA. +type ewmaSnapshot float64 // Rate returns the rate of events per second at the time the snapshot was // taken. -func (a eWMASnapshot) Rate() float64 { return float64(a) } +func (a ewmaSnapshot) Rate() float64 { return float64(a) } // NilEWMA is a no-op EWMA. type NilEWMA struct{} @@ -67,7 +67,7 @@ type StandardEWMA struct { // Snapshot returns a read-only copy of the EWMA. func (a *StandardEWMA) Snapshot() EWMASnapshot { r := math.Float64frombits(a.rate.Load()) * float64(time.Second) - return eWMASnapshot(r) + return ewmaSnapshot(r) } // Tick ticks the clock to update the moving average. It assumes it is called diff --git a/metrics/gauge.go b/metrics/gauge.go index d1a56bbdda..68f8f11abc 100644 --- a/metrics/gauge.go +++ b/metrics/gauge.go @@ -76,8 +76,14 @@ func (g *StandardGauge) Update(v int64) { // Update updates the gauge's value if v is larger then the current valie. func (g *StandardGauge) UpdateIfGt(v int64) { - if g.value.Load() < v { - g.value.Store(v) + for { + exist := g.value.Load() + if exist >= v { + break + } + if g.value.CompareAndSwap(exist, v) { + break + } } } diff --git a/metrics/gauge_float64.go b/metrics/gauge_float64.go index 2f509b1cec..967f2bc60e 100644 --- a/metrics/gauge_float64.go +++ b/metrics/gauge_float64.go @@ -51,14 +51,9 @@ func (g gaugeFloat64Snapshot) Value() float64 { return float64(g) } // NilGauge is a no-op Gauge. type NilGaugeFloat64 struct{} -// Snapshot is a no-op. func (NilGaugeFloat64) Snapshot() GaugeFloat64Snapshot { return NilGaugeFloat64{} } - -// Update is a no-op. -func (NilGaugeFloat64) Update(v float64) {} - -// Value is a no-op. -func (NilGaugeFloat64) Value() float64 { return 0.0 } +func (NilGaugeFloat64) Update(v float64) {} +func (NilGaugeFloat64) Value() float64 { return 0.0 } // StandardGaugeFloat64 is the standard implementation of a GaugeFloat64 and uses // atomic to manage a single float64 value. diff --git a/metrics/sample.go b/metrics/sample.go index 96598aec71..d204024f6b 100644 --- a/metrics/sample.go +++ b/metrics/sample.go @@ -148,7 +148,7 @@ func (NilSample) Clear() {} func (NilSample) Snapshot() SampleSnapshot { return (*emptySnapshot)(nil) } func (NilSample) Update(v int64) {} -// CalculatePercentiles returns an arbitrary percentile of the slice of int64. +// SamplePercentiles returns an arbitrary percentile of the slice of int64. func SamplePercentile(values []int64, p float64) float64 { return CalculatePercentiles(values, []float64{p})[0] }