Skip to content

Commit

Permalink
Added default first hist bucket if needed (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonatang authored Jul 16, 2020
1 parent d9b795a commit 83a3ce9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 83a3ce9

Please sign in to comment.