Merge pull request #7 from prometheus/refactor/pointers/only-on-mutation
Pointers to references for non-mutation calls.
This commit is contained in:
commit
643925d012
|
@ -59,7 +59,7 @@ func (b *AccumulatingBucket) Add(value float64) {
|
|||
heap.Push(&b.elements, &v)
|
||||
}
|
||||
|
||||
func (b *AccumulatingBucket) String() string {
|
||||
func (b AccumulatingBucket) String() string {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
|
||||
|
@ -76,7 +76,7 @@ func (b *AccumulatingBucket) String() string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
func (b *AccumulatingBucket) ValueForIndex(index int) float64 {
|
||||
func (b AccumulatingBucket) ValueForIndex(index int) float64 {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
|
||||
|
@ -102,7 +102,7 @@ func (b *AccumulatingBucket) ValueForIndex(index int) float64 {
|
|||
return sortedElements[targetIndex]
|
||||
}
|
||||
|
||||
func (b *AccumulatingBucket) Observations() int {
|
||||
func (b AccumulatingBucket) Observations() int {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ func (metric *counter) ResetAll() {
|
|||
}
|
||||
}
|
||||
|
||||
func (metric *counter) String() string {
|
||||
func (metric counter) String() string {
|
||||
formatString := "[Counter %s]"
|
||||
|
||||
metric.mutex.RLock()
|
||||
|
@ -133,7 +133,7 @@ func (metric *counter) Decrement(labels map[string]string) float64 {
|
|||
return metric.DecrementBy(labels, 1)
|
||||
}
|
||||
|
||||
func (metric *counter) AsMarshallable() map[string]interface{} {
|
||||
func (metric counter) AsMarshallable() map[string]interface{} {
|
||||
metric.mutex.RLock()
|
||||
defer metric.mutex.RUnlock()
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ type gauge struct {
|
|||
values map[string]*gaugeVector
|
||||
}
|
||||
|
||||
func (metric *gauge) String() string {
|
||||
func (metric gauge) String() string {
|
||||
formatString := "[Gauge %s]"
|
||||
|
||||
metric.mutex.RLock()
|
||||
|
@ -82,7 +82,7 @@ func (metric *gauge) ResetAll() {
|
|||
}
|
||||
}
|
||||
|
||||
func (metric *gauge) AsMarshallable() map[string]interface{} {
|
||||
func (metric gauge) AsMarshallable() map[string]interface{} {
|
||||
metric.mutex.RLock()
|
||||
defer metric.mutex.RUnlock()
|
||||
|
||||
|
|
|
@ -125,7 +125,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()
|
||||
|
||||
|
@ -160,7 +160,7 @@ func prospectiveIndexForPercentile(percentile float64, totalObservations int) in
|
|||
}
|
||||
|
||||
// Determine the next bucket element when interim bucket intervals may be empty.
|
||||
func (h *histogram) nextNonEmptyBucketElement(signature string, currentIndex, bucketCount int, observationsByBucket []int) (*Bucket, int) {
|
||||
func (h histogram) nextNonEmptyBucketElement(signature string, currentIndex, bucketCount int, observationsByBucket []int) (*Bucket, int) {
|
||||
for i := currentIndex; i < bucketCount; i++ {
|
||||
if observationsByBucket[i] == 0 {
|
||||
continue
|
||||
|
@ -179,7 +179,7 @@ func (h *histogram) nextNonEmptyBucketElement(signature string, currentIndex, bu
|
|||
// longer contained by the bucket, the index of the last item is returned. This
|
||||
// may occur if the underlying bucket catalogs values and employs an eviction
|
||||
// strategy.
|
||||
func (h *histogram) bucketForPercentile(signature string, percentile float64) (*Bucket, int) {
|
||||
func (h histogram) bucketForPercentile(signature string, percentile float64) (*Bucket, int) {
|
||||
bucketCount := len(h.bucketStarts)
|
||||
|
||||
// This captures the quantity of samples in a given bucket's range.
|
||||
|
@ -232,7 +232,7 @@ func (h *histogram) bucketForPercentile(signature string, percentile float64) (*
|
|||
// Return the histogram's estimate of the value for a given percentile of
|
||||
// collected samples. The requested percentile is expected to be a real
|
||||
// value within (0, 1.0].
|
||||
func (h *histogram) percentile(signature string, percentile float64) float64 {
|
||||
func (h histogram) percentile(signature string, percentile float64) float64 {
|
||||
bucket, index := h.bucketForPercentile(signature, percentile)
|
||||
|
||||
return (*bucket).ValueForIndex(index)
|
||||
|
@ -242,7 +242,7 @@ func formatFloat(value float64) string {
|
|||
return strconv.FormatFloat(value, floatFormat, floatPrecision, floatBitCount)
|
||||
}
|
||||
|
||||
func (h *histogram) AsMarshallable() map[string]interface{} {
|
||||
func (h histogram) AsMarshallable() map[string]interface{} {
|
||||
h.mutex.RLock()
|
||||
defer h.mutex.RUnlock()
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ func (b *TallyingBucket) Add(value float64) {
|
|||
b.largestObserved = math.Max(value, b.largestObserved)
|
||||
}
|
||||
|
||||
func (b *TallyingBucket) String() string {
|
||||
func (b TallyingBucket) String() string {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
|
||||
|
@ -101,14 +101,14 @@ func (b *TallyingBucket) String() string {
|
|||
return fmt.Sprintf("[TallyingBucket (%f, %f); %d items]", b.smallestObserved, b.largestObserved, observations)
|
||||
}
|
||||
|
||||
func (b *TallyingBucket) Observations() int {
|
||||
func (b TallyingBucket) Observations() int {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
|
||||
return b.observations
|
||||
}
|
||||
|
||||
func (b *TallyingBucket) ValueForIndex(index int) float64 {
|
||||
func (b TallyingBucket) ValueForIndex(index int) float64 {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
|
||||
|
|
Loading…
Reference in New Issue