Search in sources :

Example 1 with MockClock

use of io.micrometer.core.instrument.MockClock in project micrometer by micrometer-metrics.

the class TimeWindowPercentileHistogramTest method percentilesChangeWithMoreRecentSamples.

@Test
void percentilesChangeWithMoreRecentSamples() {
    DistributionStatisticConfig config = DistributionStatisticConfig.builder().percentiles(0.5).build().merge(DistributionStatisticConfig.DEFAULT);
    TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(), config, false);
    for (int i = 1; i <= 10; i++) {
        histogram.recordLong((long) millisToUnit(i, TimeUnit.NANOSECONDS));
    }
    // baseline median
    assertThat(histogram.takeSnapshot(0, 0, 0).percentileValues()).anyMatch(p -> percentileValueIsApproximately(p, 0.5, 5e6));
    for (int i = 11; i <= 20; i++) {
        histogram.recordLong((long) millisToUnit(i, TimeUnit.NANOSECONDS));
    }
    // median should have moved after seeing 10 more samples
    assertThat(histogram.takeSnapshot(0, 0, 0).percentileValues()).anyMatch(p -> percentileValueIsApproximately(p, 0.5, 10e6));
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 2 with MockClock

use of io.micrometer.core.instrument.MockClock in project micrometer by micrometer-metrics.

the class TimeWindowPercentileHistogramTest method recordValuesThatExceedTheDynamicRange.

@Test
void recordValuesThatExceedTheDynamicRange() {
    TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(), DistributionStatisticConfig.builder().sla(Long.MAX_VALUE).build().merge(DistributionStatisticConfig.DEFAULT), false);
    // Regardless of the imputed dynamic bound for the underlying histogram, Double.MAX_VALUE is always too large.
    histogram.recordDouble(Double.MAX_VALUE);
    assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).containsExactly(new CountAtBucket(Long.MAX_VALUE, 0));
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 3 with MockClock

use of io.micrometer.core.instrument.MockClock in project micrometer by micrometer-metrics.

the class TimeWindowPercentileHistogramTest method sampleValueAboveMaximumExpectedValue.

@Test
void sampleValueAboveMaximumExpectedValue() {
    TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(), DistributionStatisticConfig.builder().sla(3).maximumExpectedValue(2L).build().merge(DistributionStatisticConfig.DEFAULT), false);
    histogram.recordDouble(3);
    assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).containsExactly(new CountAtBucket(3, 1));
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 4 with MockClock

use of io.micrometer.core.instrument.MockClock in project micrometer by micrometer-metrics.

the class TimeWindowPercentileHistogramTest method histogramsAreCumulative.

@Test
void histogramsAreCumulative() {
    TimeWindowPercentileHistogram histogram = new TimeWindowPercentileHistogram(new MockClock(), DistributionStatisticConfig.builder().sla(3, 6, 7).build().merge(DistributionStatisticConfig.DEFAULT), false);
    histogram.recordDouble(3);
    assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).contains(new CountAtBucket(3, 1));
    histogram.recordDouble(6);
    // Proves that the accumulated histogram is truly cumulative, and not just a representation
    // of the last snapshot
    assertThat(histogram.takeSnapshot(0, 0, 0).histogramCounts()).containsExactly(new CountAtBucket(3, 1), new CountAtBucket(6, 2), new CountAtBucket(7, 2));
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Example 5 with MockClock

use of io.micrometer.core.instrument.MockClock in project micrometer by micrometer-metrics.

the class TimeWindowPercentileHistogramTest method timeBasedSlidingWindow.

@Test
void timeBasedSlidingWindow() {
    final DistributionStatisticConfig config = DistributionStatisticConfig.builder().percentiles(0.0, 0.5, 0.75, 0.9, 0.99, 0.999, 1.0).expiry(Duration.ofSeconds(4)).bufferLength(4).build().merge(DistributionStatisticConfig.DEFAULT);
    MockClock clock = new MockClock();
    // Start from 0 for more comprehensive timing calculation.
    clock.add(-1, TimeUnit.NANOSECONDS);
    assertThat(clock.wallTime()).isZero();
    Histogram histogram = new TimeWindowPercentileHistogram(clock, config, false);
    histogram.recordLong(10);
    histogram.recordLong(20);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(9.0, 11.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(19.0, 21.0);
    // 900
    clock.add(900, TimeUnit.MILLISECONDS);
    histogram.recordLong(30);
    histogram.recordLong(40);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(9.0, 11.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(38.0, 42.0);
    // 999
    clock.add(99, TimeUnit.MILLISECONDS);
    histogram.recordLong(9);
    histogram.recordLong(60);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(8.0, 10.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(58.0, 62.0);
    // 1000
    clock.add(1, TimeUnit.MILLISECONDS);
    histogram.recordLong(12);
    histogram.recordLong(70);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(8.0, 10.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(68.0, 72.0);
    // 2001
    clock.add(1001, TimeUnit.MILLISECONDS);
    histogram.recordLong(13);
    histogram.recordLong(80);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(8.0, 10.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(75.0, 85.0);
    // 3001
    clock.add(1000, TimeUnit.MILLISECONDS);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(8.0, 10.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(75.0, 85.0);
    // 4000
    clock.add(999, TimeUnit.MILLISECONDS);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(11.0, 13.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(75.0, 85.0);
    histogram.recordLong(1);
    histogram.recordLong(200);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(0.0, 2.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(190.0, 210.0);
    // 14000
    clock.add(10000, TimeUnit.MILLISECONDS);
    assertThat(percentileValue(histogram, 0.0)).isZero();
    assertThat(percentileValue(histogram, 1.0)).isZero();
    histogram.recordLong(3);
    // 17999
    clock.add(3999, TimeUnit.MILLISECONDS);
    assertThat(percentileValue(histogram, 0.0)).isStrictlyBetween(2.0, 4.0);
    assertThat(percentileValue(histogram, 1.0)).isStrictlyBetween(2.0, 4.0);
    // 18000
    clock.add(1, TimeUnit.MILLISECONDS);
    assertThat(percentileValue(histogram, 0.0)).isZero();
    assertThat(percentileValue(histogram, 1.0)).isZero();
}
Also used : MockClock(io.micrometer.core.instrument.MockClock) Test(org.junit.jupiter.api.Test)

Aggregations

MockClock (io.micrometer.core.instrument.MockClock)19 Test (org.junit.jupiter.api.Test)18 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)5 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)3 TimeUnit (java.util.concurrent.TimeUnit)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Duration (java.time.Duration)2 AtlasConfig (com.netflix.spectator.atlas.AtlasConfig)1 Issue (io.micrometer.core.Issue)1 LongTaskTimer (io.micrometer.core.instrument.LongTaskTimer)1 Meter (io.micrometer.core.instrument.Meter)1 MockClock.clock (io.micrometer.core.instrument.MockClock.clock)1 Timer (io.micrometer.core.instrument.Timer)1 TimeUtils.millisToUnit (io.micrometer.core.instrument.util.TimeUtils.millisToUnit)1 TimeUtils.secondsToUnit (io.micrometer.core.instrument.util.TimeUtils.secondsToUnit)1 Nullable (io.micrometer.core.lang.Nullable)1 ChannelOption (io.netty.channel.ChannelOption)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 InetSocketAddress (java.net.InetSocketAddress)1 Locale (java.util.Locale)1