diff --git a/README.md b/README.md index 5827688..8c9dce8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# SmallRye Metrics Extension: AsyncTimed +# SmallRye Metrics Extension: AsyncSimplyTimed This library provides annotation-based timing for methods returning promised values, namely `java.util.concurrent.CompletionStage` and `io.smallrye.mutiny.Uni`. @@ -40,4 +40,5 @@ Therefore, the minimum set of dependencies looks as follows: ## Usage -Annotate any bean method returning one of the aforementioned types with `com.traum.microprofile.metrics.annotation.AsyncTimed`. +Annotate any bean method returning one of the aforementioned types with `com.traum.microprofile.metrics.annotation.AsyncSimplyTimed`, +instead of MicroProfile's [`SimplyTimed`](https://download.eclipse.org/microprofile/microprofile-metrics-2.3/microprofile-metrics-spec-2.3.html#_simplytimed). diff --git a/src/main/java/com/traum/metrics/interceptors/AsyncTimedInterceptor.java b/src/main/java/com/traum/metrics/interceptors/AsyncSimplyTimedInterceptor.java similarity index 83% rename from src/main/java/com/traum/metrics/interceptors/AsyncTimedInterceptor.java rename to src/main/java/com/traum/metrics/interceptors/AsyncSimplyTimedInterceptor.java index f66597f..156bb5f 100644 --- a/src/main/java/com/traum/metrics/interceptors/AsyncTimedInterceptor.java +++ b/src/main/java/com/traum/metrics/interceptors/AsyncSimplyTimedInterceptor.java @@ -1,6 +1,6 @@ package com.traum.metrics.interceptors; -import com.traum.microprofile.metrics.annotation.AsyncTimed; +import com.traum.microprofile.metrics.annotation.AsyncSimplyTimed; import io.smallrye.metrics.TagsUtils; import io.smallrye.metrics.elementdesc.AnnotationInfo; import io.smallrye.metrics.elementdesc.MemberInfo; @@ -27,16 +27,16 @@ import org.eclipse.microprofile.metrics.Tag; @Dependent -@AsyncTimed @Interceptor -public class AsyncTimedInterceptor { +@AsyncSimplyTimed +public class AsyncSimplyTimedInterceptor { private final MetricRegistry registry; private final Map cache = new HashMap<>(); @Inject - AsyncTimedInterceptor(MetricRegistry registry) { + AsyncSimplyTimedInterceptor(MetricRegistry registry) { this.registry = registry; } @@ -81,7 +81,7 @@ private SimpleTimer registerTimer(E elemen return cache.computeIfAbsent( element.getName(), key -> { - Of resolvedAnnotation = AsyncTimedOf.of(element); + Of resolvedAnnotation = AsyncSimplyTimedOf.of(element); final Metadata metadata = Metadata.builder() @@ -98,7 +98,7 @@ private SimpleTimer registerTimer(E elemen } } -class AsyncTimedOf implements Of { +class AsyncSimplyTimedOf implements Of { private static final MemberInfoAdapter MEMBER_INFO_ADAPTER = new CDIMemberInfoAdapter(); @@ -106,24 +106,24 @@ class AsyncTimedOf implements Of { private final String metricName; private final Tag[] tags; - private AsyncTimedOf(AnnotationInfo annotationInfo, String metricName, Tag[] tags) { + private AsyncSimplyTimedOf(AnnotationInfo annotationInfo, String metricName, Tag[] tags) { this.annotationInfo = annotationInfo; this.metricName = metricName; this.tags = tags; } - static AsyncTimedOf of(E element) { - final AsyncTimed annotation = element.getAnnotation(AsyncTimed.class); + static AsyncSimplyTimedOf of(E element) { + final AsyncSimplyTimed annotation = element.getAnnotation(AsyncSimplyTimed.class); final MemberInfo memberInfo = MEMBER_INFO_ADAPTER.convert(element); final String name = annotation.name().isEmpty() ? memberInfo.getName() : annotation.name(); final String metricName = annotation.absolute() ? name : MetricRegistry.name(memberInfo.getDeclaringClassName(), name); - final AnnotationInfo annotationInfo = new AsyncTimedAnnotationInfo(annotation); + final AnnotationInfo annotationInfo = new AsyncSimplyTimedAnnotationInfo(annotation); final Tag[] tags = TagsUtils.parseTagsAsArray(annotation.tags()); - return new AsyncTimedOf(annotationInfo, metricName, tags); + return new AsyncSimplyTimedOf(annotationInfo, metricName, tags); } @Override @@ -147,11 +147,11 @@ public AnnotationInfo metricAnnotation() { } } -class AsyncTimedAnnotationInfo implements AnnotationInfo { +class AsyncSimplyTimedAnnotationInfo implements AnnotationInfo { - private final AsyncTimed instance; + private final AsyncSimplyTimed instance; - public AsyncTimedAnnotationInfo(AsyncTimed instance) { + public AsyncSimplyTimedAnnotationInfo(AsyncSimplyTimed instance) { this.instance = instance; } diff --git a/src/main/java/com/traum/microprofile/metrics/annotation/AsyncTimed.java b/src/main/java/com/traum/microprofile/metrics/annotation/AsyncSimplyTimed.java similarity index 98% rename from src/main/java/com/traum/microprofile/metrics/annotation/AsyncTimed.java rename to src/main/java/com/traum/microprofile/metrics/annotation/AsyncSimplyTimed.java index fb07624..54517ad 100644 --- a/src/main/java/com/traum/microprofile/metrics/annotation/AsyncTimed.java +++ b/src/main/java/com/traum/microprofile/metrics/annotation/AsyncSimplyTimed.java @@ -24,7 +24,7 @@ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) -public @interface AsyncTimed { +public @interface AsyncSimplyTimed { /** @return The name of the simple timer. */ @Nonbinding diff --git a/src/test/java/com/traum/metrics/interceptors/AsyncService.java b/src/test/java/com/traum/metrics/interceptors/AsyncService.java index c9a2785..4af5aff 100644 --- a/src/test/java/com/traum/metrics/interceptors/AsyncService.java +++ b/src/test/java/com/traum/metrics/interceptors/AsyncService.java @@ -1,6 +1,6 @@ package com.traum.metrics.interceptors; -import com.traum.microprofile.metrics.annotation.AsyncTimed; +import com.traum.microprofile.metrics.annotation.AsyncSimplyTimed; import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; @@ -14,27 +14,27 @@ public class AsyncService { ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); - @AsyncTimed + @AsyncSimplyTimed public CompletionStage returnCompletionStage(Duration delay) { return execute(delay); } - @AsyncTimed(name = "relative_name") + @AsyncSimplyTimed(name = "relative_name") public CompletionStage returnCompletionStageWithRelativeName(Duration delay) { return execute(delay); } - @AsyncTimed(name = "absolute_name", absolute = true) + @AsyncSimplyTimed(name = "absolute_name", absolute = true) public CompletionStage returnCompletionStageWithAbsoluteName(Duration delay) { return execute(delay); } - @AsyncTimed(name = "with_exception", absolute = true) + @AsyncSimplyTimed(name = "with_exception", absolute = true) public CompletionStage returnCompletionStageWithException(Duration delay) { throw new RuntimeException("Failed fast"); } - @AsyncTimed(name = "with_failure", absolute = true) + @AsyncSimplyTimed(name = "with_failure", absolute = true) public CompletionStage returnCompletionStageWithFailure(Duration delay) { return CompletableFuture.failedStage(new RuntimeException("Failed later")); } diff --git a/src/test/java/com/traum/metrics/interceptors/AsyncTimedInterceptorTest.java b/src/test/java/com/traum/metrics/interceptors/AsyncSimplyTimedInterceptorTest.java similarity index 96% rename from src/test/java/com/traum/metrics/interceptors/AsyncTimedInterceptorTest.java rename to src/test/java/com/traum/metrics/interceptors/AsyncSimplyTimedInterceptorTest.java index f257a05..9885572 100644 --- a/src/test/java/com/traum/metrics/interceptors/AsyncTimedInterceptorTest.java +++ b/src/test/java/com/traum/metrics/interceptors/AsyncSimplyTimedInterceptorTest.java @@ -19,15 +19,15 @@ import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(WeldJunit5Extension.class) -class AsyncTimedInterceptorTest { +class AsyncSimplyTimedInterceptorTest { @WeldSetup WeldInitiator initiator = WeldInitiator.of( WeldInitiator.createWeld() .beanClasses(AsyncService.class, MetricRegistryProducer.class) - .packages(AsyncTimedInterceptor.class) - .interceptors(AsyncTimedInterceptor.class)); + .packages(AsyncSimplyTimedInterceptor.class) + .interceptors(AsyncSimplyTimedInterceptor.class)); @Inject AsyncService service;