Skip to content

Commit bce0e58

Browse files
authored
Avoid classloading LatencyUtils when not configured (#3262)
The default configuration uses a NoPauseDetector, which need not use any LatencyUtils classes. This avoids classloading LatencyUtils classes, which makes it possible for end users to exclude the LatencyUtils dependency and not have any issues at runtime. The Prometheus sample should work without LatencyUtils or HdrHistogram since configuration that would use either is not present in the sample. This sample can be run to demonstrate it being possible to exclude these dependencies.
1 parent 651587b commit bce0e58

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

micrometer-core/src/main/java/io/micrometer/core/instrument/AbstractTimer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.micrometer.core.instrument.distribution.*;
1919
import io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector;
20+
import io.micrometer.core.instrument.distribution.pause.NoPauseDetector;
2021
import io.micrometer.core.instrument.distribution.pause.PauseDetector;
2122
import io.micrometer.core.lang.Nullable;
2223
import org.LatencyUtils.IntervalEstimator;
@@ -101,6 +102,9 @@ else if (distributionStatisticConfig.isPublishingHistogram()) {
101102
}
102103

103104
private void initPauseDetector(PauseDetector pauseDetectorType) {
105+
if (pauseDetectorType instanceof NoPauseDetector) {
106+
return;
107+
}
104108
pauseDetector = pauseDetectorCache.computeIfAbsent(pauseDetectorType, detector -> {
105109
if (detector instanceof ClockDriftPauseDetector) {
106110
ClockDriftPauseDetector clockDriftPauseDetector = (ClockDriftPauseDetector) detector;

samples/micrometer-samples-boot2/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ repositories {
1010
}
1111

1212
dependencies {
13-
implementation project(":micrometer-core")
13+
implementation(project(":micrometer-core")) {
14+
// see gh-1599; pause detection and percentiles are not configured so these dependencies can be excluded
15+
exclude module: 'LatencyUtils'
16+
exclude module: 'HdrHistogram'
17+
}
1418
['atlas', 'azure-monitor', 'prometheus', 'datadog', 'elastic', 'ganglia', 'graphite', 'health', 'jmx', 'influx', 'statsd', 'new-relic', 'cloudwatch', 'cloudwatch2', 'signalfx', 'wavefront', 'elastic', 'dynatrace', 'humio', 'appoptics', 'stackdriver'].each { sys ->
1519
implementation project(":micrometer-registry-$sys")
1620
}

0 commit comments

Comments
 (0)