Skip to content

Commit 83a3ce9

Browse files
authored
Added default first hist bucket if needed (#532)
1 parent d9b795a commit 83a3ce9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/histogram.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ func (bs *Buckets) UnmarshalText(value []byte) error {
6868
if len(value) < 2 || value[0] != '[' || value[len(value)-1] != ']' {
6969
return fmt.Errorf("bad buckets: %s", value)
7070
}
71-
for _, v := range strings.Split(string(value[1:len(value)-1]), ",") {
71+
for i, v := range strings.Split(string(value[1:len(value)-1]), ",") {
7272
d, err := time.ParseDuration(strings.TrimSpace(v))
7373
if err != nil {
7474
return err
7575
}
76+
// add a default range of [0-Buckets[0]) if needed
77+
if i == 0 && d > 0 {
78+
*bs = append(*bs, 0)
79+
}
7680
*bs = append(*bs, d)
7781
}
7882
if len(*bs) == 0 {

lib/histogram_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func TestBuckets_UnmarshalText(t *testing.T) {
5757
"[0,5ms]": {0, 5 * time.Millisecond},
5858
"[0, 5ms]": {0, 5 * time.Millisecond},
5959
"[ 0,5ms, 10m ]": {0, 5 * time.Millisecond, 10 * time.Minute},
60+
"[3ms,10ms]": {0, 3 * time.Millisecond, 10 * time.Millisecond},
6061
} {
6162
var got Buckets
6263
if err := got.UnmarshalText([]byte(value)); err != nil {

0 commit comments

Comments
 (0)