diff --git a/micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java b/micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java index cc3dd33d56..ca6e6cd7e9 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java +++ b/micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java @@ -258,6 +258,7 @@ private Timer.Builder recordBuilder(ProceedingJoinPoint pjp, Timed timed, String .tags(EXCEPTION_TAG, exceptionClass) .tags(tagsBasedOnJoinPoint.apply(pjp)) .publishPercentileHistogram(timed.histogram()) + .publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles()) .serviceLevelObjectives( timed.serviceLevelObjectives().length > 0 ? Arrays.stream(timed.serviceLevelObjectives()) .mapToObj(s -> Duration.ofNanos((long) TimeUtils.secondsToUnit(s, TimeUnit.NANOSECONDS))) diff --git a/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java b/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java index b12f5d4d78..ba6ec0ca45 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java +++ b/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java @@ -25,6 +25,7 @@ import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.distribution.CountAtBucket; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import io.micrometer.core.instrument.distribution.ValueAtPercentile; import io.micrometer.core.instrument.distribution.pause.PauseDetector; import io.micrometer.core.instrument.search.MeterNotFoundException; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -120,6 +121,25 @@ void timeMethodWithSloTimer() { .toArray()).isEqualTo(new double[] { Math.pow(10, 9) * 0.1, Math.pow(10, 9) * 0.5 }); } + @Test + void timeMethodWithPercentilesTimer() { + MeterRegistry registry = new SimpleMeterRegistry(); + + AspectJProxyFactory pf = new AspectJProxyFactory(new TimedService()); + pf.addAspect(new TimedAspect(registry)); + + TimedService service = pf.getProxy(); + + service.percentilesCall(); + + assertThat(registry.get("percentilesCall") + .tag("class", getClass().getName() + "$TimedService") + .tag("method", "percentilesCall") + .timer() + .takeSnapshot() + .percentileValues()).extracting(ValueAtPercentile::percentile).containsExactly(0.1, 0.5); + } + @Test void timeMethodFailure() { MeterRegistry failingRegistry = new FailingMeterRegistry(); @@ -736,6 +756,10 @@ void longCall() { void sloCall() { } + @Timed(value = "percentilesCall", percentiles = { 0.1, 0.5 }) + void percentilesCall() { + } + } static class AsyncTimedService {