Change FibonacciFitter to just be a utility method

It turns out that StackdriverWriter uses reflection on the class of
the DistributionFitter instance, so rather than giving it custom
handling for FibonacciFitters, it's easier to turn FibonacciFitter
into a single utility method that takes advantage of existing support
for CustomFitters.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158190147
This commit is contained in:
mcilwain 2017-06-06 14:27:04 -07:00 committed by Ben McIlwain
parent e8eabe01cf
commit 0fdde1cc9e

View file

@ -16,11 +16,10 @@ package google.registry.monitoring.metrics;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
/** /**
* A {@link DistributionFitter} with intervals of increasing size using the Fibonacci sequence. * Utility method to create a {@link CustomFitter} with intervals using the Fibonacci sequence.
* *
* <p>A Fibonacci fitter is useful in situations where you want more precision on the low end than * <p>A Fibonacci fitter is useful in situations where you want more precision on the low end than
* an {@link ExponentialFitter} with exponent base 2 would provide without the hassle of dealing * an {@link ExponentialFitter} with exponent base 2 would provide without the hassle of dealing
@ -31,17 +30,16 @@ import com.google.common.collect.ImmutableSortedSet;
* <p>The interval boundaries are chosen as {@code (-inf, 0), [0, 1), [1, 2), [2, 3), [3, 5), [5, * <p>The interval boundaries are chosen as {@code (-inf, 0), [0, 1), [1, 2), [2, 3), [3, 5), [5,
* 8), [8, 13)}, etc., up to {@code [fibonacciFloor(maxBucketSize), inf)}. * 8), [8, 13)}, etc., up to {@code [fibonacciFloor(maxBucketSize), inf)}.
*/ */
@AutoValue public final class FibonacciFitter {
public abstract class FibonacciFitter implements DistributionFitter {
/** /**
* Returns a new {@link FibonacciFitter}. * Returns a new {@link CustomFitter} with bounds corresponding to the Fibonacci sequence.
* *
* @param maxBucketSize the maximum bucket size to create (rounded down to the nearest Fibonacci * @param maxBucketSize the maximum bucket size to create (rounded down to the nearest Fibonacci
* number) * number)
* @throws IllegalArgumentException if {@code maxBucketSize <= 0} * @throws IllegalArgumentException if {@code maxBucketSize <= 0}
*/ */
public static FibonacciFitter create(long maxBucketSize) { public static CustomFitter create(long maxBucketSize) {
checkArgument(maxBucketSize > 0, "maxBucketSize must be greater than 0"); checkArgument(maxBucketSize > 0, "maxBucketSize must be greater than 0");
ImmutableSortedSet.Builder<Double> boundaries = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<Double> boundaries = ImmutableSortedSet.naturalOrder();
@ -56,9 +54,8 @@ public abstract class FibonacciFitter implements DistributionFitter {
k = i + j; k = i + j;
} }
return new AutoValue_FibonacciFitter(boundaries.build()); return CustomFitter.create(boundaries.build());
} }
@Override private FibonacciFitter() {}
public abstract ImmutableSortedSet<Double> boundaries();
} }