/** * Returns a function that maps age values to a set of buckets. Example use-case would be * tracking the age of data flowing through a processing pipeline. Values that are less than * 0 will be marked as "future". These typically occur due to minor variations in the clocks * across nodes. In addition to a bucket at the max, it will create buckets at max / 2, max / 4, * and max / 8. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction age(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.age(max, unit)); }
@Test public void latency100ms() { BucketFunction f = BucketFunctions.latency(100, TimeUnit.MILLISECONDS); Assertions.assertEquals("negative_latency", f.apply(TimeUnit.MILLISECONDS.toNanos(-1))); Assertions.assertEquals("012ms", f.apply(TimeUnit.MILLISECONDS.toNanos(1))); Assertions.assertEquals("025ms", f.apply(TimeUnit.MILLISECONDS.toNanos(13))); Assertions.assertEquals("025ms", f.apply(TimeUnit.MILLISECONDS.toNanos(25))); Assertions.assertEquals("100ms", f.apply(TimeUnit.MILLISECONDS.toNanos(99))); Assertions.assertEquals("slow", f.apply(TimeUnit.MILLISECONDS.toNanos(101))); }
@Test public void latency100msBiasSlow() { BucketFunction f = BucketFunctions.latencyBiasSlow(100, TimeUnit.MILLISECONDS); Assertions.assertEquals("negative_latency", f.apply(TimeUnit.MILLISECONDS.toNanos(-1))); Assertions.assertEquals("050ms", f.apply(TimeUnit.MILLISECONDS.toNanos(1))); Assertions.assertEquals("050ms", f.apply(TimeUnit.MILLISECONDS.toNanos(13))); Assertions.assertEquals("050ms", f.apply(TimeUnit.MILLISECONDS.toNanos(25))); Assertions.assertEquals("075ms", f.apply(TimeUnit.MILLISECONDS.toNanos(74))); Assertions.assertEquals("075ms", f.apply(TimeUnit.MILLISECONDS.toNanos(75))); Assertions.assertEquals("100ms", f.apply(TimeUnit.MILLISECONDS.toNanos(99))); Assertions.assertEquals("slow", f.apply(TimeUnit.MILLISECONDS.toNanos(101))); }
@Test public void age60s() { BucketFunction f = BucketFunctions.age(60, TimeUnit.SECONDS); Assertions.assertEquals("future", f.apply(TimeUnit.SECONDS.toNanos(-1))); Assertions.assertEquals("07s", f.apply(TimeUnit.SECONDS.toNanos(1))); Assertions.assertEquals("07s", f.apply(TimeUnit.SECONDS.toNanos(6))); Assertions.assertEquals("07s", f.apply(TimeUnit.SECONDS.toNanos(7))); Assertions.assertEquals("15s", f.apply(TimeUnit.SECONDS.toNanos(10))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(20))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(30))); Assertions.assertEquals("60s", f.apply(TimeUnit.SECONDS.toNanos(42))); Assertions.assertEquals("60s", f.apply(TimeUnit.SECONDS.toNanos(60))); Assertions.assertEquals("old", f.apply(TimeUnit.SECONDS.toNanos(61))); }
@Test public void age60sBiasOld() { BucketFunction f = BucketFunctions.ageBiasOld(60, TimeUnit.SECONDS); Assertions.assertEquals("future", f.apply(TimeUnit.SECONDS.toNanos(-1))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(1))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(6))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(7))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(10))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(20))); Assertions.assertEquals("30s", f.apply(TimeUnit.SECONDS.toNanos(30))); Assertions.assertEquals("45s", f.apply(TimeUnit.SECONDS.toNanos(42))); Assertions.assertEquals("52s", f.apply(TimeUnit.SECONDS.toNanos(48))); Assertions.assertEquals("60s", f.apply(TimeUnit.SECONDS.toNanos(59))); Assertions.assertEquals("60s", f.apply(TimeUnit.SECONDS.toNanos(60))); Assertions.assertEquals("old", f.apply(TimeUnit.SECONDS.toNanos(61))); }
@Test public void latency3s() { BucketFunction f = BucketFunctions.latency(3, TimeUnit.SECONDS); Assertions.assertEquals("negative_latency", f.apply(TimeUnit.MILLISECONDS.toNanos(-1))); Assertions.assertEquals("0375ms", f.apply(TimeUnit.MILLISECONDS.toNanos(25))); Assertions.assertEquals("0750ms", f.apply(TimeUnit.MILLISECONDS.toNanos(740))); Assertions.assertEquals("1500ms", f.apply(TimeUnit.MILLISECONDS.toNanos(1000))); Assertions.assertEquals("3000ms", f.apply(TimeUnit.MILLISECONDS.toNanos(1567))); Assertions.assertEquals("slow", f.apply(TimeUnit.MILLISECONDS.toNanos(3001))); } }
/** * Returns a function that maps age values to a set of buckets. Example use-case would be * tracking the age of data flowing through a processing pipeline. Values that are less than * 0 will be marked as "future". These typically occur due to minor variations in the clocks * across nodes. In addition to a bucket at the max, it will create buckets at max - max / 8, * max - max / 4, and max - max / 2. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction ageBiasOld(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.ageBiasOld(max, unit)); }
/** * Returns a function that maps latencies to a set of buckets. Example use-case would be * tracking the amount of time to process a request on a server. Values that are less than * 0 will be marked as "negative_latency". These typically occur due to minor variations in the * clocks, e.g., using {@link System#currentTimeMillis()} to measure the latency and having a * time adjustment between the start and end. In addition to a bucket at the max, it will create * buckets at max / 2, max / 4, and max / 8. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction latency(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.latency(max, unit)); }
/** * Returns a function that maps age values to a set of buckets. Example use-case would be * tracking the age of data flowing through a processing pipeline. Values that are less than * 0 will be marked as "future". These typically occur due to minor variations in the clocks * across nodes. In addition to a bucket at the max, it will create buckets at max - max / 8, * max - max / 4, and max - max / 2. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction ageBiasOld(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.ageBiasOld(max, unit)); }
/** * Returns a function that maps latencies to a set of buckets. Example use-case would be * tracking the amount of time to process a request on a server. Values that are less than * 0 will be marked as "negative_latency". These typically occur due to minor variations in the * clocks, e.g., using {@link System#currentTimeMillis()} to measure the latency and having a * time adjustment between the start and end. In addition to a bucket at the max, it will create * buckets at max / 2, max / 4, and max / 8. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction latency(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.latency(max, unit)); }
/** * Returns a function that maps age values to a set of buckets. Example use-case would be * tracking the age of data flowing through a processing pipeline. Values that are less than * 0 will be marked as "future". These typically occur due to minor variations in the clocks * across nodes. In addition to a bucket at the max, it will create buckets at max / 2, max / 4, * and max / 8. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction age(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.age(max, unit)); }
/** * Returns a function that maps latencies to a set of buckets. Example use-case would be * tracking the amount of time to process a request on a server. Values that are less than * 0 will be marked as "negative_latency". These typically occur due to minor variations in the * clocks, e.g., using {@link System#currentTimeMillis()} to measure the latency and having a * time adjustment between the start and end. In addition to a bucket at the max, it will create * buckets at max - max / 8, max - max / 4, and max - max / 2. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction latencyBiasSlow(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.latencyBiasSlow(max, unit)); } }
/** * Returns a function that maps latencies to a set of buckets. Example use-case would be * tracking the amount of time to process a request on a server. Values that are less than * 0 will be marked as "negative_latency". These typically occur due to minor variations in the * clocks, e.g., using {@link System#currentTimeMillis()} to measure the latency and having a * time adjustment between the start and end. In addition to a bucket at the max, it will create * buckets at max - max / 8, max - max / 4, and max - max / 2. * * @param max * Maximum expected age of data flowing through. Values greater than this max will be mapped * to an "old" bucket. * @param unit * Unit for the max value. * @return * Function mapping age values to string labels. The labels for buckets will sort * so they can be used with a simple group by. */ public static BucketFunction latencyBiasSlow(long max, TimeUnit unit) { return wrap(com.netflix.spectator.api.histogram.BucketFunctions.latencyBiasSlow(max, unit)); } }