Search in sources :

Example 1 with ClockDriftPauseDetector

use of io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector in project micrometer by micrometer-metrics.

the class CompositeMeterRegistryTest method compositePauseDetectorConfigOverridesChild.

@Test
void compositePauseDetectorConfigOverridesChild() {
    composite.add(simple);
    CountDownLatch count = new CountDownLatch(1);
    composite.config().pauseDetector(new ClockDriftPauseDetector(Duration.ofSeconds(1), Duration.ofSeconds(1)) {

        @Override
        public Duration getPauseThreshold() {
            count.countDown();
            return super.getPauseThreshold();
        }
    });
    composite.timer("my.timer");
    assertThat(count.getCount()).isEqualTo(0);
}
Also used : ClockDriftPauseDetector(io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector) Duration(java.time.Duration) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 2 with ClockDriftPauseDetector

use of io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector in project micrometer by micrometer-metrics.

the class AbstractTimer method initPauseDetector.

private void initPauseDetector(PauseDetector pauseDetectorType) {
    org.LatencyUtils.PauseDetector pauseDetector = requireNonNull(pauseDetectorCache.computeIfAbsent(pauseDetectorType, detector -> {
        if (detector instanceof ClockDriftPauseDetector) {
            ClockDriftPauseDetector clockDriftPauseDetector = (ClockDriftPauseDetector) detector;
            return new SimplePauseDetector(clockDriftPauseDetector.getSleepInterval().toNanos(), clockDriftPauseDetector.getPauseThreshold().toNanos(), 1, false);
        } else if (detector instanceof NoPauseDetector) {
            return new NoopPauseDetector();
        }
        return new NoopPauseDetector();
    }));
    this.intervalEstimator = new TimeCappedMovingAverageIntervalEstimator(128, 10000000000L, pauseDetector);
    pauseDetector.addListener((pauseLength, pauseEndTime) -> {
        // System.out.println("Pause of length " + (pauseLength / 1e6) + "ms, end time " + pauseEndTime);
        if (intervalEstimator != null) {
            long estimatedInterval = intervalEstimator.getEstimatedInterval(pauseEndTime);
            long observedLatencyMinbar = pauseLength - estimatedInterval;
            if (observedLatencyMinbar >= estimatedInterval) {
                recordValueWithExpectedInterval(observedLatencyMinbar, estimatedInterval);
            }
        }
    });
}
Also used : Nullable(io.micrometer.core.lang.Nullable) PauseDetector(io.micrometer.core.instrument.distribution.pause.PauseDetector) io.micrometer.core.instrument.distribution(io.micrometer.core.instrument.distribution) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimeCappedMovingAverageIntervalEstimator(org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator) IntervalEstimator(org.LatencyUtils.IntervalEstimator) Callable(java.util.concurrent.Callable) ClockDriftPauseDetector(io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector) Supplier(java.util.function.Supplier) SimplePauseDetector(org.LatencyUtils.SimplePauseDetector) TimeUnit(java.util.concurrent.TimeUnit) MeterEquivalence(io.micrometer.core.instrument.util.MeterEquivalence) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) NoPauseDetector(io.micrometer.core.instrument.distribution.pause.NoPauseDetector) TimeCappedMovingAverageIntervalEstimator(org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator) NoPauseDetector(io.micrometer.core.instrument.distribution.pause.NoPauseDetector) ClockDriftPauseDetector(io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector) SimplePauseDetector(org.LatencyUtils.SimplePauseDetector)

Aggregations

ClockDriftPauseDetector (io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector)2 io.micrometer.core.instrument.distribution (io.micrometer.core.instrument.distribution)1 NoPauseDetector (io.micrometer.core.instrument.distribution.pause.NoPauseDetector)1 PauseDetector (io.micrometer.core.instrument.distribution.pause.PauseDetector)1 MeterEquivalence (io.micrometer.core.instrument.util.MeterEquivalence)1 Nullable (io.micrometer.core.lang.Nullable)1 Duration (java.time.Duration)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 Supplier (java.util.function.Supplier)1 IntervalEstimator (org.LatencyUtils.IntervalEstimator)1 SimplePauseDetector (org.LatencyUtils.SimplePauseDetector)1 TimeCappedMovingAverageIntervalEstimator (org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator)1 Test (org.junit.jupiter.api.Test)1