Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore handling for Timed.percentiles() in TimedAspect #5475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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