diff --git a/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationHandler.java b/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationHandler.java index 28ffb8da87..5c88618bf1 100644 --- a/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationHandler.java +++ b/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationHandler.java @@ -103,45 +103,43 @@ public void addAnnotatedParameters(T objectToModify, ProceedingJoinPoint pjp) { private void getAnnotationsFromInterfaces(ProceedingJoinPoint pjp, Method mostSpecificMethod, List annotatedParameters) { Class[] implementedInterfaces = pjp.getThis().getClass().getInterfaces(); - if (implementedInterfaces.length > 0) { - for (Class implementedInterface : implementedInterfaces) { - for (Method methodFromInterface : implementedInterface.getMethods()) { - if (methodsAreTheSame(mostSpecificMethod, methodFromInterface)) { - List annotatedParametersForActualMethod = AnnotationUtils - .findAnnotatedParameters(annotationClass, methodFromInterface, pjp.getArgs()); - mergeAnnotatedParameters(annotatedParameters, annotatedParametersForActualMethod); - } + for (Class implementedInterface : implementedInterfaces) { + for (Method methodFromInterface : implementedInterface.getMethods()) { + if (methodsAreTheSame(mostSpecificMethod, methodFromInterface)) { + List annotatedParametersForActualMethod = AnnotationUtils + .findAnnotatedParameters(annotationClass, methodFromInterface, pjp.getArgs()); + mergeAnnotatedParameters(annotatedParameters, annotatedParametersForActualMethod); } } } } - private boolean methodsAreTheSame(Method mostSpecificMethod, Method method1) { - return method1.getName().equals(mostSpecificMethod.getName()) - && Arrays.equals(method1.getParameterTypes(), mostSpecificMethod.getParameterTypes()); + private boolean methodsAreTheSame(Method mostSpecificMethod, Method method) { + return method.getName().equals(mostSpecificMethod.getName()) + && Arrays.equals(method.getParameterTypes(), mostSpecificMethod.getParameterTypes()); } - private void mergeAnnotatedParameters(List annotatedParametersIndices, - List annotatedParametersIndicesForActualMethod) { - for (AnnotatedParameter container : annotatedParametersIndicesForActualMethod) { + private void mergeAnnotatedParameters(List annotatedParameters, + List annotatedParametersForActualMethod) { + for (AnnotatedParameter container : annotatedParametersForActualMethod) { final int index = container.parameterIndex; boolean parameterContained = false; - for (AnnotatedParameter parameterContainer : annotatedParametersIndices) { + for (AnnotatedParameter parameterContainer : annotatedParameters) { if (parameterContainer.parameterIndex == index) { parameterContained = true; break; } } if (!parameterContained) { - annotatedParametersIndices.add(container); + annotatedParameters.add(container); } } } - private void addAnnotatedArguments(T objectToTag, List toBeAdded) { + private void addAnnotatedArguments(T objectToModify, List toBeAdded) { for (AnnotatedParameter container : toBeAdded) { KeyValue keyValue = toKeyValue.apply(container.annotation, container.argument); - keyValueConsumer.accept(keyValue, objectToTag); + keyValueConsumer.accept(keyValue, objectToModify); } } diff --git a/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationUtils.java b/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationUtils.java index bc11bf4a5f..55f76ed906 100644 --- a/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationUtils.java +++ b/micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationUtils.java @@ -34,14 +34,14 @@ private AnnotationUtils() { } - static List findAnnotatedParameters(Class tagClazz, Method method, + static List findAnnotatedParameters(Class annotationClazz, Method method, Object[] args) { Annotation[][] parameters = method.getParameterAnnotations(); List result = new ArrayList<>(); int i = 0; for (Annotation[] parameter : parameters) { for (Annotation parameter2 : parameter) { - if (tagClazz.isAssignableFrom(parameter2.getClass())) { + if (annotationClazz.isAssignableFrom(parameter2.annotationType())) { result.add(new AnnotatedParameter(i, parameter2, args[i])); } } diff --git a/micrometer-commons/src/main/java/io/micrometer/common/annotation/NoOpValueResolver.java b/micrometer-commons/src/main/java/io/micrometer/common/annotation/NoOpValueResolver.java index 0ef42103c2..bc216c8be8 100644 --- a/micrometer-commons/src/main/java/io/micrometer/common/annotation/NoOpValueResolver.java +++ b/micrometer-commons/src/main/java/io/micrometer/common/annotation/NoOpValueResolver.java @@ -1,5 +1,5 @@ /** - * Copyright 2022 the original author or authors. + * Copyright 2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueExpressionResolver.java b/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueExpressionResolver.java index cb88e124ed..6bb642bc8e 100644 --- a/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueExpressionResolver.java +++ b/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueExpressionResolver.java @@ -1,5 +1,5 @@ /** - * Copyright 2022 the original author or authors. + * Copyright 2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueResolver.java b/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueResolver.java index f32b65990c..effe0a9449 100644 --- a/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueResolver.java +++ b/micrometer-commons/src/main/java/io/micrometer/common/annotation/ValueResolver.java @@ -1,5 +1,5 @@ /** - * Copyright 2022 the original author or authors. + * Copyright 2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/micrometer-commons/src/main/java/io/micrometer/common/annotation/package-info.java b/micrometer-commons/src/main/java/io/micrometer/common/annotation/package-info.java index 531ed4daf1..ba75210351 100644 --- a/micrometer-commons/src/main/java/io/micrometer/common/annotation/package-info.java +++ b/micrometer-commons/src/main/java/io/micrometer/common/annotation/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 VMware, Inc. + * Copyright 2023 VMware, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/micrometer-core/src/main/java/io/micrometer/core/aop/MeterTag.java b/micrometer-core/src/main/java/io/micrometer/core/aop/MeterTag.java index 59c2bc1bfa..012bae84d1 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/aop/MeterTag.java +++ b/micrometer-core/src/main/java/io/micrometer/core/aop/MeterTag.java @@ -1,5 +1,5 @@ /** - * Copyright 2022 the original author or authors. + * Copyright 2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ * expression just return a {@code toString()} value of the parameter. * * IMPORTANT: Provided tag values MUST BE of LOW-CARDINALITY. If you fail to provide - * low-cardinality values, that can lead to performance issues of your metrics back end. - * Values should not come from the end-user since those most likely be high-cardinality. + * low-cardinality values, that can lead to performance issues of your metrics backend. + * Values should not come from the end-user since those could be high-cardinality. * * @author Christian Schwerdtfeger * @author Marcin Grzejszczak @@ -42,22 +42,22 @@ /** * The name of the key of the tag which should be created. This is an alias for - * {@link MeterTag#key()}. - * @return the tag key + * {@link #key()}. + * @return the tag key name */ String value() default ""; /** * The name of the key of the tag which should be created. - * @return the tag value + * @return the tag key name */ String key() default ""; /** - * Execute this expression to calculate the tag value. Will be analyzed if no value of - * the {@link MeterTag#resolver()} was set. You need to have a - * {@link ValueExpressionResolver} registered on the {@link MeterAnnotationHandler} to - * provide the expression resolution engine. + * Execute this expression to calculate the tag value. Will be evaluated if no value + * of the {@link #resolver()} was set. You need to have a + * {@link ValueExpressionResolver} registered on the {@link MeterTagAnnotationHandler} + * to provide the expression resolution engine. * @return an expression */ String expression() default ""; diff --git a/micrometer-core/src/main/java/io/micrometer/core/aop/MeterAnnotationHandler.java b/micrometer-core/src/main/java/io/micrometer/core/aop/MeterTagAnnotationHandler.java similarity index 89% rename from micrometer-core/src/main/java/io/micrometer/core/aop/MeterAnnotationHandler.java rename to micrometer-core/src/main/java/io/micrometer/core/aop/MeterTagAnnotationHandler.java index c239fb0d96..1ba5bf997f 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/aop/MeterAnnotationHandler.java +++ b/micrometer-core/src/main/java/io/micrometer/core/aop/MeterTagAnnotationHandler.java @@ -28,19 +28,19 @@ /** * Annotation handler for {@link MeterTag}. To add support for {@link MeterTag} on * {@link TimedAspect} check the - * {@link TimedAspect#setMetricsTagAnnotationHandler(MeterAnnotationHandler)} method. + * {@link TimedAspect#setMeterTagAnnotationHandler(MeterTagAnnotationHandler)} method. * * @since 1.11.0 */ -public class MeterAnnotationHandler extends AnnotationHandler { +public class MeterTagAnnotationHandler extends AnnotationHandler { /** - * Creates a new instance of {@link MeterAnnotationHandler}. + * Creates a new instance of {@link MeterTagAnnotationHandler}. * @param resolverProvider function to retrieve a {@link ValueResolver} * @param expressionResolverProvider function to retrieve a * {@link ValueExpressionResolver} */ - public MeterAnnotationHandler(Function, ? extends ValueResolver> resolverProvider, + public MeterTagAnnotationHandler(Function, ? extends ValueResolver> resolverProvider, Function, ? extends ValueExpressionResolver> expressionResolverProvider) { super((keyValue, builder) -> builder.tag(keyValue.getKey(), keyValue.getValue()), resolverProvider, expressionResolverProvider, MeterTag.class, (annotation, o) -> { 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 a0a7010ce4..295a823d15 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 @@ -67,8 +67,9 @@ * } * * - * To add support for {@link MeterTag} annotations set the {@link MeterAnnotationHandler} - * via {@link TimedAspect#setMetricsTagAnnotationHandler(MeterAnnotationHandler)}. + * To add support for {@link MeterTag} annotations set the + * {@link MeterTagAnnotationHandler} via + * {@link TimedAspect#setMeterTagAnnotationHandler(MeterTagAnnotationHandler)}. * * @author David J. M. Karlsen * @author Jon Schneider @@ -101,7 +102,7 @@ public class TimedAspect { private final Predicate shouldSkip; - private MeterAnnotationHandler meterTagAnnotationHandler; + private MeterTagAnnotationHandler meterTagAnnotationHandler; /** * Creates a {@code TimedAspect} instance with {@link Metrics#globalRegistry}. @@ -324,9 +325,9 @@ private Optional buildLongTaskTimer(ProceedingJoinPoint pjp, Time /** * Setting this enables support for {@link MeterTag}. - * @param meterTagAnnotationHandler metrics tag annotation handler + * @param meterTagAnnotationHandler meter tag annotation handler */ - public void setMetricsTagAnnotationHandler(MeterAnnotationHandler meterTagAnnotationHandler) { + public void setMeterTagAnnotationHandler(MeterTagAnnotationHandler meterTagAnnotationHandler) { this.meterTagAnnotationHandler = meterTagAnnotationHandler; } diff --git a/micrometer-core/src/test/java/io/micrometer/core/aop/MeterAnnotationHandlerTests.java b/micrometer-core/src/test/java/io/micrometer/core/aop/MeterTagAnnotationHandlerTests.java similarity index 59% rename from micrometer-core/src/test/java/io/micrometer/core/aop/MeterAnnotationHandlerTests.java rename to micrometer-core/src/test/java/io/micrometer/core/aop/MeterTagAnnotationHandlerTests.java index da5349a878..6f229a076d 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/aop/MeterAnnotationHandlerTests.java +++ b/micrometer-core/src/test/java/io/micrometer/core/aop/MeterTagAnnotationHandlerTests.java @@ -18,72 +18,50 @@ import io.micrometer.common.annotation.ValueExpressionResolver; import io.micrometer.common.annotation.ValueResolver; import io.micrometer.core.annotation.Timed; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -class MeterAnnotationHandlerTests { +class MeterTagAnnotationHandlerTests { ValueResolver valueResolver = parameter -> "Value from myCustomTagValueResolver"; ValueExpressionResolver valueExpressionResolver = new SpelValueExpressionResolver(); - MeterAnnotationHandler handler; - - @BeforeEach - void setup() { - this.handler = new MeterAnnotationHandler(aClass -> valueResolver, aClass -> valueExpressionResolver); - } - @Test void shouldUseCustomTagValueResolver() throws NoSuchMethodException, SecurityException { Method method = AnnotationMockClass.class.getMethod("getAnnotationForTagValueResolver", String.class); Annotation annotation = method.getParameterAnnotations()[0][0]; - if (annotation instanceof MeterTag) { - String resolvedValue = this.handler.resolveTagValue((MeterTag) annotation, "test", aClass -> valueResolver, - aClass -> valueExpressionResolver); - assertThat(resolvedValue).isEqualTo("Value from myCustomTagValueResolver"); - } - else { - fail("Annotation was not MetricTag"); - } + assertThat(annotation).isInstanceOf(MeterTag.class); + String resolvedValue = MeterTagAnnotationHandler.resolveTagValue((MeterTag) annotation, "test", + aClass -> valueResolver, aClass -> valueExpressionResolver); + assertThat(resolvedValue).isEqualTo("Value from myCustomTagValueResolver"); } @Test void shouldUseTagValueExpression() throws NoSuchMethodException, SecurityException { Method method = AnnotationMockClass.class.getMethod("getAnnotationForTagValueExpression", String.class); Annotation annotation = method.getParameterAnnotations()[0][0]; - if (annotation instanceof MeterTag) { - String resolvedValue = this.handler.resolveTagValue((MeterTag) annotation, "test", aClass -> valueResolver, - aClass -> valueExpressionResolver); - - assertThat(resolvedValue).isEqualTo("hello characters"); - } - else { - fail("Annotation was not MetricTag"); - } + assertThat(annotation).isInstanceOf(MeterTag.class); + String resolvedValue = MeterTagAnnotationHandler.resolveTagValue((MeterTag) annotation, "test value", + aClass -> valueResolver, aClass -> valueExpressionResolver); + assertThat(resolvedValue).isEqualTo("hello test value characters"); } @Test void shouldReturnArgumentToString() throws NoSuchMethodException, SecurityException { Method method = AnnotationMockClass.class.getMethod("getAnnotationForArgumentToString", Long.class); Annotation annotation = method.getParameterAnnotations()[0][0]; - if (annotation instanceof MeterTag) { - String resolvedValue = this.handler.resolveTagValue((MeterTag) annotation, 15, aClass -> valueResolver, - aClass -> valueExpressionResolver); - assertThat(resolvedValue).isEqualTo("15"); - } - else { - fail("Annotation was not MetricTag"); - } + assertThat(annotation).isInstanceOf(MeterTag.class); + String resolvedValue = MeterTagAnnotationHandler.resolveTagValue((MeterTag) annotation, 15, + aClass -> valueResolver, aClass -> valueExpressionResolver); + assertThat(resolvedValue).isEqualTo("15"); } - protected class AnnotationMockClass { + static class AnnotationMockClass { @Timed public void getAnnotationForTagValueResolver( @@ -92,7 +70,7 @@ public void getAnnotationForTagValueResolver( @Timed public void getAnnotationForTagValueExpression( - @MeterTag(key = "test", expression = "'hello' + ' characters'") String test) { + @MeterTag(key = "test", expression = "'hello ' + #this + ' characters'") String test) { } @Timed diff --git a/micrometer-core/src/test/java/io/micrometer/core/aop/NullMetricTagAnnotationHandlerTests.java b/micrometer-core/src/test/java/io/micrometer/core/aop/NullMetricTagAnnotationHandlerTests.java index 4434f1f139..f8052be75c 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/aop/NullMetricTagAnnotationHandlerTests.java +++ b/micrometer-core/src/test/java/io/micrometer/core/aop/NullMetricTagAnnotationHandlerTests.java @@ -24,61 +24,44 @@ import java.lang.reflect.Method; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -class NullMeterAnnotationHandlerTests { +class NullMeterTagAnnotationHandlerTests { ValueResolver valueResolver = parameter -> null; - ValueExpressionResolver valueExpressionResolver = (expression, parameter) -> ""; - - MeterAnnotationHandler handler = new MeterAnnotationHandler(aClass -> valueResolver, - aClass -> valueExpressionResolver); + ValueExpressionResolver valueExpressionResolver = (expression, parameter) -> null; @Test - void shouldUseEmptyStringWheCustomTagValueResolverReturnsNull() throws NoSuchMethodException, SecurityException { + void shouldUseEmptyStringWhenCustomTagValueResolverReturnsNull() throws NoSuchMethodException, SecurityException { Method method = AnnotationMockClass.class.getMethod("getAnnotationForTagValueResolver", String.class); Annotation annotation = method.getParameterAnnotations()[0][0]; - if (annotation instanceof MeterTag) { - String resolvedValue = this.handler.resolveTagValue((MeterTag) annotation, "test", aClass -> valueResolver, - aClass -> valueExpressionResolver); - assertThat(resolvedValue).isEqualTo(""); - } - else { - fail("Annotation was not MetricTag"); - } + assertThat(annotation).isInstanceOf(MeterTag.class); + String resolvedValue = MeterTagAnnotationHandler.resolveTagValue((MeterTag) annotation, "test", + aClass -> valueResolver, aClass -> valueExpressionResolver); + assertThat(resolvedValue).isEmpty(); } @Test void shouldUseEmptyStringWhenTagValueExpressionReturnNull() throws NoSuchMethodException, SecurityException { Method method = AnnotationMockClass.class.getMethod("getAnnotationForTagValueExpression", String.class); Annotation annotation = method.getParameterAnnotations()[0][0]; - if (annotation instanceof MeterTag) { - String resolvedValue = this.handler.resolveTagValue((MeterTag) annotation, "test", aClass -> valueResolver, - aClass -> valueExpressionResolver); - - assertThat(resolvedValue).isEqualTo(""); - } - else { - fail("Annotation was not MetricTag"); - } + assertThat(annotation).isInstanceOf(MeterTag.class); + String resolvedValue = MeterTagAnnotationHandler.resolveTagValue((MeterTag) annotation, "test", + aClass -> valueResolver, aClass -> valueExpressionResolver); + assertThat(resolvedValue).isEmpty(); } @Test void shouldUseEmptyStringWhenArgumentIsNull() throws NoSuchMethodException, SecurityException { Method method = AnnotationMockClass.class.getMethod("getAnnotationForArgumentToString", Long.class); Annotation annotation = method.getParameterAnnotations()[0][0]; - if (annotation instanceof MeterTag) { - String resolvedValue = this.handler.resolveTagValue((MeterTag) annotation, null, aClass -> valueResolver, - aClass -> valueExpressionResolver); - assertThat(resolvedValue).isEqualTo(""); - } - else { - fail("Annotation was not SpanTag"); - } + assertThat(annotation).isInstanceOf(MeterTag.class); + String resolvedValue = MeterTagAnnotationHandler.resolveTagValue((MeterTag) annotation, null, + aClass -> valueResolver, aClass -> valueExpressionResolver); + assertThat(resolvedValue).isEmpty(); } - protected class AnnotationMockClass { + static class AnnotationMockClass { @Timed public void getAnnotationForTagValueResolver( diff --git a/micrometer-core/src/test/java/io/micrometer/core/aop/SpelValueExpressionResolver.java b/micrometer-core/src/test/java/io/micrometer/core/aop/SpelValueExpressionResolver.java index 0f92a8f702..2e6c4b8847 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/aop/SpelValueExpressionResolver.java +++ b/micrometer-core/src/test/java/io/micrometer/core/aop/SpelValueExpressionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 VMware, Inc. + * Copyright 2023 VMware, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ public String resolve(String expression, Object parameter) { return expressionToEvaluate.getValue(context, parameter, String.class); } catch (Exception ex) { - log.error("Exception occurred while tying to evaluate the SPEL expression [" + expression + "]", ex); + log.error("Exception occurred while trying to evaluate the SpEL expression [" + expression + "]", ex); } return parameter.toString(); } 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 c6f63fbfe7..4f0b6c34d9 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 @@ -380,18 +380,20 @@ static class MeterTagsTests { ValueExpressionResolver valueExpressionResolver = new SpelValueExpressionResolver(); + MeterTagAnnotationHandler meterTagAnnotationHandler = new MeterTagAnnotationHandler(aClass -> valueResolver, + aClass -> valueExpressionResolver); + @ParameterizedTest @EnumSource(AnnotatedTestClass.class) - void metricTagsWithText(AnnotatedTestClass annotatedClass) { + void meterTagsWithText(AnnotatedTestClass annotatedClass) { MeterRegistry registry = new SimpleMeterRegistry(); TimedAspect timedAspect = new TimedAspect(registry); - timedAspect.setMetricsTagAnnotationHandler( - new MeterAnnotationHandler(aClass -> valueResolver, aClass -> valueExpressionResolver)); + timedAspect.setMeterTagAnnotationHandler(meterTagAnnotationHandler); AspectJProxyFactory pf = new AspectJProxyFactory(annotatedClass.newInstance()); pf.addAspect(timedAspect); - MetricTagClassInterface service = pf.getProxy(); + MeterTagClassInterface service = pf.getProxy(); service.getAnnotationForArgumentToString(15L); @@ -400,16 +402,15 @@ void metricTagsWithText(AnnotatedTestClass annotatedClass) { @ParameterizedTest @EnumSource(AnnotatedTestClass.class) - void metricTagsWithResolver(AnnotatedTestClass annotatedClass) { + void meterTagsWithResolver(AnnotatedTestClass annotatedClass) { MeterRegistry registry = new SimpleMeterRegistry(); TimedAspect timedAspect = new TimedAspect(registry); - timedAspect.setMetricsTagAnnotationHandler( - new MeterAnnotationHandler(aClass -> valueResolver, aClass -> valueExpressionResolver)); + timedAspect.setMeterTagAnnotationHandler(meterTagAnnotationHandler); AspectJProxyFactory pf = new AspectJProxyFactory(annotatedClass.newInstance()); pf.addAspect(timedAspect); - MetricTagClassInterface service = pf.getProxy(); + MeterTagClassInterface service = pf.getProxy(); service.getAnnotationForTagValueResolver("foo"); @@ -421,16 +422,15 @@ void metricTagsWithResolver(AnnotatedTestClass annotatedClass) { @ParameterizedTest @EnumSource(AnnotatedTestClass.class) - void metricTagsWithExpression(AnnotatedTestClass annotatedClass) { + void meterTagsWithExpression(AnnotatedTestClass annotatedClass) { MeterRegistry registry = new SimpleMeterRegistry(); TimedAspect timedAspect = new TimedAspect(registry); - timedAspect.setMetricsTagAnnotationHandler( - new MeterAnnotationHandler(aClass -> valueResolver, aClass -> valueExpressionResolver)); + timedAspect.setMeterTagAnnotationHandler(meterTagAnnotationHandler); AspectJProxyFactory pf = new AspectJProxyFactory(annotatedClass.newInstance()); pf.addAspect(timedAspect); - MetricTagClassInterface service = pf.getProxy(); + MeterTagClassInterface service = pf.getProxy(); service.getAnnotationForTagValueExpression("15L"); @@ -439,16 +439,16 @@ void metricTagsWithExpression(AnnotatedTestClass annotatedClass) { enum AnnotatedTestClass { - CLASS_WITHOUT_INTERFACE(MetricTagClass.class), CLASS_WITH_INTERFACE(MetricTagClassChild.class); + CLASS_WITHOUT_INTERFACE(MeterTagClass.class), CLASS_WITH_INTERFACE(MeterTagClassChild.class); - private final Class clazz; + private final Class clazz; - AnnotatedTestClass(Class clazz) { + AnnotatedTestClass(Class clazz) { this.clazz = clazz; } @SuppressWarnings("unchecked") - T newInstance() { + T newInstance() { try { return (T) clazz.getDeclaredConstructor().newInstance(); } @@ -459,7 +459,7 @@ T newInstance() { } - protected interface MetricTagClassInterface { + interface MeterTagClassInterface { @Timed void getAnnotationForTagValueResolver(@MeterTag(key = "test", resolver = ValueResolver.class) String test); @@ -473,7 +473,7 @@ void getAnnotationForTagValueExpression( } - protected static class MetricTagClass implements MetricTagClassInterface { + static class MeterTagClass implements MeterTagClassInterface { @Timed @Override @@ -494,17 +494,20 @@ public void getAnnotationForArgumentToString(@MeterTag("test") Long param) { } - protected static class MetricTagClassChild implements MetricTagClassInterface { + static class MeterTagClassChild implements MeterTagClassInterface { @Timed + @Override public void getAnnotationForTagValueResolver(String test) { } @Timed + @Override public void getAnnotationForTagValueExpression(String test) { } @Timed + @Override public void getAnnotationForArgumentToString(Long param) { }