Skip to content

DurationBuckets.exponential fails due to fractional nanoseconds #47

Open

Description

@evertlammerts

DurationBuckets.exponential throws an IllegalArgumentException for large set of factors, because it is not possible to create a Duration based on a fractional nanosecond.:

java.lang.IllegalArgumentException: Unable to create a precise Duration with the specified factor

	at com.uber.m3.util.Duration.multiply(Duration.java:313)
	at com.uber.m3.tally.DurationBuckets.exponential(DurationBuckets.java:101)

The below code gives an idea of how I tried looking for a factor between 1 and 2 that can be used to create 20 buckets:

        BigDecimal curr = new BigDecimal("1.01");
        BigDecimal step = new BigDecimal("0.01");
        BigDecimal end = new BigDecimal("1.99");
        while (curr.compareTo(end) <= 0) {
            try {
                DurationBuckets.exponential(
                    Duration.ofMillis(1), curr.floatValue(), 20
                );
                System.out.println(curr);
            } catch (IllegalArgumentException e) {}
            curr = curr.add(step);
        }

None of them work. This virtually renders DurationBuckets.exponential useless.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions