Skip to content

Commit

Permalink
Restore handling for Timed.percentiles() in TimedAspect (#5475)
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Sep 11, 2024
1 parent 40ca508 commit 9991df4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -736,6 +756,10 @@ void longCall() {
void sloCall() {
}

@Timed(value = "percentilesCall", percentiles = { 0.1, 0.5 })
void percentilesCall() {
}

}

static class AsyncTimedService {
Expand Down

0 comments on commit 9991df4

Please sign in to comment.