@@ -47,23 +47,25 @@ type Histogram interface {
47
47
Observe (float64 )
48
48
}
49
49
50
- // DefBuckets are the default Histogram buckets. Most likely, you want to define
51
- // buckets customized to your use case.
50
+ // DefBuckets are the default Histogram buckets. The default buckets are
51
+ // tailored to broadly measure response time in seconds for a typical online
52
+ // serving system. Most likely, however, you will be required to define buckets
53
+ // customized to your use case.
52
54
var (
53
55
DefBuckets = []float64 {.005 , .01 , .025 , .05 , .1 , .25 , .5 , 1 , 2.5 , 5 , 10 }
54
56
)
55
57
56
58
// LinearBuckets creates 'count' buckets, each 'width' wide, where the lowest
57
- // bucket has an upper bound of 'start'. The final +Inf bucket is counted
58
- // towards the total 'count', but not included in the returned slice. The
59
- // returned slice is meant to be used for the Buckets field of HistogramOpts.
59
+ // bucket has an upper bound of 'start'. The final +Inf bucket is not counted
60
+ // and not included in the returned slice. The returned slice is meant to be
61
+ // used for the Buckets field of HistogramOpts.
60
62
//
61
- // The function panics if 'count' is less than 2 .
63
+ // The function panics if 'count' is zero or negative .
62
64
func LinearBuckets (start , width float64 , count int ) []float64 {
63
- if count < 2 {
64
- panic ("LinearBuckets needs a count > 1 " )
65
+ if count < 1 {
66
+ panic ("LinearBuckets needs a positive count " )
65
67
}
66
- buckets := make ([]float64 , count - 1 )
68
+ buckets := make ([]float64 , count )
67
69
for i := range buckets {
68
70
buckets [i ] = start
69
71
start += width
@@ -73,23 +75,23 @@ func LinearBuckets(start, width float64, count int) []float64 {
73
75
74
76
// ExponentialBuckets creates 'count' buckets, where the lowest bucket has an
75
77
// upper bound of 'start' and each following bucket's upper bound is 'factor'
76
- // times the previous bucket's upper bound. The final +Inf bucket is counted
77
- // towards the total 'count', but not included in the returned slice. The
78
- // returned slice is meant to be used for the Buckets field of HistogramOpts.
78
+ // times the previous bucket's upper bound. The final +Inf bucket is not counted
79
+ // and not included in the returned slice. The returned slice is meant to be
80
+ // used for the Buckets field of HistogramOpts.
79
81
//
80
- // The function panics if 'count' is less than 2 , if 'start' is 0 or negative,
82
+ // The function panics if 'count' is 0 or negative , if 'start' is 0 or negative,
81
83
// or if 'factor' is less than or equal 1.
82
84
func ExponentialBuckets (start , factor float64 , count int ) []float64 {
83
- if count < 2 {
84
- panic ("ExponentialBuckets needs a count > 1 " )
85
+ if count < 1 {
86
+ panic ("ExponentialBuckets needs a positive count " )
85
87
}
86
88
if start <= 0 {
87
89
panic ("ExponentialBuckets needs a positive start value" )
88
90
}
89
91
if factor <= 1 {
90
92
panic ("ExponentialBuckets needs a factor greater than 1" )
91
93
}
92
- buckets := make ([]float64 , count - 1 )
94
+ buckets := make ([]float64 , count )
93
95
for i := range buckets {
94
96
buckets [i ] = start
95
97
start *= factor
0 commit comments