diff --git a/metrics/accumulating_bucket.go b/metrics/accumulating_bucket.go index 4aa23f5..7651a5b 100644 --- a/metrics/accumulating_bucket.go +++ b/metrics/accumulating_bucket.go @@ -65,7 +65,7 @@ func (b *AccumulatingBucket) Add(value float64) { heap.Push(&b.elements, &v) } -func (b *AccumulatingBucket) Humanize() string { +func (b *AccumulatingBucket) String() string { b.mutex.RLock() defer b.mutex.RUnlock() diff --git a/metrics/accumulating_bucket_test.go b/metrics/accumulating_bucket_test.go index e83e5bc..765446e 100644 --- a/metrics/accumulating_bucket_test.go +++ b/metrics/accumulating_bucket_test.go @@ -27,25 +27,25 @@ func (s *S) TestAccumulatingBucketBuilderWithEvictOldest(c *C) { var b Bucket = bb() c.Assert(b, Not(IsNil)) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }") b.Add(1) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }") b.Add(2) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }") b.Add(3) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }") b.Add(4) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }") b.Add(5) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }") b.Add(6) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 4.000000, 5.000000, 6.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 4.000000, 5.000000, 6.000000, }") var bucket Bucket = b @@ -65,25 +65,25 @@ func (s *S) TestAccumulatingBucketBuilderWithEvictAndReplaceWithAverage(c *C) { c.Assert(b, Not(IsNil)) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }") b.Add(1) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }") b.Add(2) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }") b.Add(3) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }") b.Add(4) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }") b.Add(5) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }") b.Add(6) - c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 4.000000, 5.000000, 2.000000, 6.000000, }") + c.Check(b.String(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 4.000000, 5.000000, 2.000000, 6.000000, }") } func (s *S) TestAccumulatingBucket(c *C) { diff --git a/metrics/bucket.go b/metrics/bucket.go index a026306..649b66a 100644 --- a/metrics/bucket.go +++ b/metrics/bucket.go @@ -32,7 +32,7 @@ type Bucket interface { /* Provide a humanized representation hereof. */ - Humanize() string + String() string /* Provide a count of observations throughout the bucket's lifetime. */ diff --git a/metrics/gauge.go b/metrics/gauge.go index f988d28..ed8f448 100644 --- a/metrics/gauge.go +++ b/metrics/gauge.go @@ -24,7 +24,7 @@ type GaugeMetric struct { mutex sync.RWMutex } -func (metric *GaugeMetric) Humanize() string { +func (metric *GaugeMetric) String() string { formatString := "[GaugeMetric; value=%f]" metric.mutex.RLock() diff --git a/metrics/gauge_test.go b/metrics/gauge_test.go index 07fc106..ed479b4 100644 --- a/metrics/gauge_test.go +++ b/metrics/gauge_test.go @@ -19,9 +19,9 @@ func (s *S) TestCreate(c *C) { c.Check(m.Get(), Equals, 1.0) } -func (s *S) TestHumanize(c *C) { +func (s *S) TestString(c *C) { m := GaugeMetric{value: 2.0} - c.Check(m.Humanize(), Equals, "[GaugeMetric; value=2.000000]") + c.Check(m.String(), Equals, "[GaugeMetric; value=2.000000]") } func (s *S) TestSet(c *C) { @@ -38,7 +38,7 @@ func (s *S) TestIncrementBy(c *C) { m.IncrementBy(1.5) c.Check(m.Get(), Equals, 2.5) - c.Check(m.Humanize(), Equals, "[GaugeMetric; value=2.500000]") + c.Check(m.String(), Equals, "[GaugeMetric; value=2.500000]") } func (s *S) TestIncrement(c *C) { @@ -47,7 +47,7 @@ func (s *S) TestIncrement(c *C) { m.Increment() c.Check(m.Get(), Equals, 2.0) - c.Check(m.Humanize(), Equals, "[GaugeMetric; value=2.000000]") + c.Check(m.String(), Equals, "[GaugeMetric; value=2.000000]") } func (s *S) TestDecrementBy(c *C) { @@ -56,7 +56,7 @@ func (s *S) TestDecrementBy(c *C) { m.DecrementBy(1.0) c.Check(m.Get(), Equals, 0.0) - c.Check(m.Humanize(), Equals, "[GaugeMetric; value=0.000000]") + c.Check(m.String(), Equals, "[GaugeMetric; value=0.000000]") } func (s *S) TestDecrement(c *C) { @@ -65,7 +65,7 @@ func (s *S) TestDecrement(c *C) { m.Decrement() c.Check(m.Get(), Equals, 0.0) - c.Check(m.Humanize(), Equals, "[GaugeMetric; value=0.000000]") + c.Check(m.String(), Equals, "[GaugeMetric; value=0.000000]") } func (s *S) TestGaugeMetricMarshallable(c *C) { diff --git a/metrics/histogram.go b/metrics/histogram.go index 6213b33..e5baad8 100644 --- a/metrics/histogram.go +++ b/metrics/histogram.go @@ -106,13 +106,13 @@ func (h *Histogram) Add(value float64) { h.buckets[lastIndex].Add(value) } -func (h *Histogram) Humanize() string { +func (h *Histogram) String() string { stringBuffer := bytes.NewBufferString("") stringBuffer.WriteString("[Histogram { ") for i, bucketStart := range h.bucketStarts { bucket := h.buckets[i] - stringBuffer.WriteString(fmt.Sprintf("[%f, inf) = %s, ", bucketStart, bucket.Humanize())) + stringBuffer.WriteString(fmt.Sprintf("[%f, inf) = %s, ", bucketStart, bucket.String())) } stringBuffer.WriteString("}]") diff --git a/metrics/histogram_test.go b/metrics/histogram_test.go index f10d0d4..212dc54 100644 --- a/metrics/histogram_test.go +++ b/metrics/histogram_test.go @@ -53,11 +53,11 @@ func (s *S) TestCreateHistogram(c *C) { c.Assert(h, Not(IsNil)) - c.Check(h.Humanize(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (Empty)], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]") + c.Check(h.String(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (Empty)], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]") h.Add(1) - c.Check(h.Humanize(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (1.000000, 1.000000); 1 items], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]") + c.Check(h.String(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (1.000000, 1.000000); 1 items], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]") } func (s *S) TestBucketForPercentile(c *C) { diff --git a/metrics/metric.go b/metrics/metric.go index f33c636..ad7b26c 100644 --- a/metrics/metric.go +++ b/metrics/metric.go @@ -15,7 +15,7 @@ type Metric interface { /* Produce a human-consumable representation of the metric. */ - Humanize() string + String() string /* Produce a JSON-consumable representation of the metric. */ diff --git a/metrics/tallying_bucket.go b/metrics/tallying_bucket.go index 3209cc8..195db9b 100644 --- a/metrics/tallying_bucket.go +++ b/metrics/tallying_bucket.go @@ -104,7 +104,7 @@ func (b *TallyingBucket) Add(value float64) { b.largestObserved = math.Max(value, b.largestObserved) } -func (b *TallyingBucket) Humanize() string { +func (b *TallyingBucket) String() string { b.mutex.RLock() defer b.mutex.RUnlock() diff --git a/metrics/tallying_bucket_test.go b/metrics/tallying_bucket_test.go index f669de1..dfa5394 100644 --- a/metrics/tallying_bucket_test.go +++ b/metrics/tallying_bucket_test.go @@ -45,14 +45,14 @@ func (s *S) TestTallyingBucketBuilder(c *C) { c.Assert(bucket, Not(IsNil)) } -func (s *S) TestTallyingBucketHumanize(c *C) { +func (s *S) TestTallyingBucketString(c *C) { bucket := TallyingBucket{ observations: 3, smallestObserved: 2.0, largestObserved: 5.5, } - c.Check(bucket.Humanize(), Equals, "[TallyingBucket (2.000000, 5.500000); 3 items]") + c.Check(bucket.String(), Equals, "[TallyingBucket (2.000000, 5.500000); 3 items]") } func (s *S) TestTallyingBucketAdd(c *C) {