diff --git a/lib/histogram.go b/lib/histogram.go index f8fd8446..acb546f1 100644 --- a/lib/histogram.go +++ b/lib/histogram.go @@ -68,11 +68,15 @@ func (bs *Buckets) UnmarshalText(value []byte) error { if len(value) < 2 || value[0] != '[' || value[len(value)-1] != ']' { return fmt.Errorf("bad buckets: %s", value) } - for _, v := range strings.Split(string(value[1:len(value)-1]), ",") { + for i, v := range strings.Split(string(value[1:len(value)-1]), ",") { d, err := time.ParseDuration(strings.TrimSpace(v)) if err != nil { return err } + // add a default range of [0-Buckets[0]) if needed + if i == 0 && d > 0 { + *bs = append(*bs, 0) + } *bs = append(*bs, d) } if len(*bs) == 0 { diff --git a/lib/histogram_test.go b/lib/histogram_test.go index 68b28154..8bdd366f 100644 --- a/lib/histogram_test.go +++ b/lib/histogram_test.go @@ -57,6 +57,7 @@ func TestBuckets_UnmarshalText(t *testing.T) { "[0,5ms]": {0, 5 * time.Millisecond}, "[0, 5ms]": {0, 5 * time.Millisecond}, "[ 0,5ms, 10m ]": {0, 5 * time.Millisecond, 10 * time.Minute}, + "[3ms,10ms]": {0, 3 * time.Millisecond, 10 * time.Millisecond}, } { var got Buckets if err := got.UnmarshalText([]byte(value)); err != nil {