Skip to content

Commit

Permalink
Avoid classloading LatencyUtils when not configured (#3262)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shakuzen authored Jul 5, 2022
1 parent 651587b commit bce0e58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.micrometer.core.instrument.distribution.*;
import io.micrometer.core.instrument.distribution.pause.ClockDriftPauseDetector;
import io.micrometer.core.instrument.distribution.pause.NoPauseDetector;
import io.micrometer.core.instrument.distribution.pause.PauseDetector;
import io.micrometer.core.lang.Nullable;
import org.LatencyUtils.IntervalEstimator;
Expand Down Expand Up @@ -101,6 +102,9 @@ else if (distributionStatisticConfig.isPublishingHistogram()) {
}

private void initPauseDetector(PauseDetector pauseDetectorType) {
if (pauseDetectorType instanceof NoPauseDetector) {
return;
}
pauseDetector = pauseDetectorCache.computeIfAbsent(pauseDetectorType, detector -> {
if (detector instanceof ClockDriftPauseDetector) {
ClockDriftPauseDetector clockDriftPauseDetector = (ClockDriftPauseDetector) detector;
Expand Down
6 changes: 5 additions & 1 deletion samples/micrometer-samples-boot2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ repositories {
}

dependencies {
implementation project(":micrometer-core")
implementation(project(":micrometer-core")) {
// see gh-1599; pause detection and percentiles are not configured so these dependencies can be excluded
exclude module: 'LatencyUtils'
exclude module: 'HdrHistogram'
}
['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 ->
implementation project(":micrometer-registry-$sys")
}
Expand Down

0 comments on commit bce0e58

Please sign in to comment.