Skip to content

Commit

Permalink
Revert "MeterTags wrapper to support multiple MeterTag-s on a single …
Browse files Browse the repository at this point in the history
…method parameter (#5055)"

This reverts commit dd9194a.
  • Loading branch information
shakuzen committed Jul 9, 2024
1 parent dd9194a commit 1f20895
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -38,15 +36,16 @@ private AnnotationUtils() {

static List<AnnotatedParameter> findAnnotatedParameters(Class<? extends Annotation> annotationClazz, Method method,
Object[] args) {
Parameter[] parameters = method.getParameters();
List<AnnotatedParameter> result = new LinkedList<>();
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
Annotation[] annotations = parameter.getAnnotationsByType(annotationClazz);
final int parameterIndex = i;
Arrays.stream(annotations)
.map(annotation -> new AnnotatedParameter(parameterIndex, annotation, args[parameterIndex]))
.forEach(result::add);
Annotation[][] parameters = method.getParameterAnnotations();
List<AnnotatedParameter> result = new ArrayList<>();
int i = 0;
for (Annotation[] parameter : parameters) {
for (Annotation parameter2 : parameter) {
if (annotationClazz.isAssignableFrom(parameter2.annotationType())) {
result.add(new AnnotatedParameter(i, parameter2, args[i]));
}
}
i++;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target(ElementType.PARAMETER)
@Repeatable(MeterTags.class)
public @interface MeterTag {

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -457,49 +457,6 @@ void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
assertThat(registry.get("method.timed").tag("test", "hello characters").timer().count()).isEqualTo(1);
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
void multipleMeterTagsWithExpression(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
timedAspect.setMeterTagAnnotationHandler(meterTagAnnotationHandler);

AspectJProxyFactory pf = new AspectJProxyFactory(annotatedClass.newInstance());
pf.addAspect(timedAspect);

MeterTagClassInterface service = pf.getProxy();

service.getMultipleAnnotationsForTagValueExpression(new DataHolder("zxe", "qwe"));

assertThat(registry.get("method.timed")
.tag("value1", "value1: zxe")
.tag("value2", "value2: qwe")
.timer()
.count()).isEqualTo(1);
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
void multipleMeterTagsWithinContainerWithExpression(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
timedAspect.setMeterTagAnnotationHandler(meterTagAnnotationHandler);

AspectJProxyFactory pf = new AspectJProxyFactory(annotatedClass.newInstance());
pf.addAspect(timedAspect);

MeterTagClassInterface service = pf.getProxy();

service.getMultipleAnnotationsWithContainerForTagValueExpression(new DataHolder("zxe", "qwe"));

assertThat(registry.get("method.timed")
.tag("value1", "value1: zxe")
.tag("value2", "value2: qwe")
.tag("value3", "value3: ZXEQWE")
.timer()
.count()).isEqualTo(1);
}

@Test
void meterTagOnPackagePrivateMethod() {
MeterRegistry registry = new SimpleMeterRegistry();
Expand Down Expand Up @@ -568,17 +525,6 @@ void getAnnotationForTagValueExpression(
@Timed
void getAnnotationForArgumentToString(@MeterTag("test") Long param);

@Timed
void getMultipleAnnotationsForTagValueExpression(
@MeterTag(key = "value1", expression = "'value1: ' + value1") @MeterTag(key = "value2",
expression = "'value2: ' + value2") DataHolder param);

@Timed
void getMultipleAnnotationsWithContainerForTagValueExpression(@MeterTags({
@MeterTag(key = "value1", expression = "'value1: ' + value1"),
@MeterTag(key = "value2", expression = "'value2: ' + value2"), @MeterTag(key = "value3",
expression = "'value3: ' + value1.toUpperCase + value2.toUpperCase") }) DataHolder param);

}

static class MeterTagClass implements MeterTagClassInterface {
Expand All @@ -604,22 +550,6 @@ public void getAnnotationForArgumentToString(@MeterTag("test") Long param) {
void getAnnotationForPackagePrivateMethod(@MeterTag("foo") String foo) {
}

@Timed
@Override
public void getMultipleAnnotationsForTagValueExpression(
@MeterTag(key = "value1", expression = "'value1: ' + value1") @MeterTag(key = "value2",
expression = "'value2: ' + value2") DataHolder param) {

}

@Timed
@Override
public void getMultipleAnnotationsWithContainerForTagValueExpression(@MeterTags({
@MeterTag(key = "value1", expression = "'value1: ' + value1"),
@MeterTag(key = "value2", expression = "'value2: ' + value2"), @MeterTag(key = "value3",
expression = "'value3: ' + value1.toUpperCase + value2.toUpperCase") }) DataHolder param) {
}

}

static class MeterTagClassChild implements MeterTagClassInterface {
Expand All @@ -639,18 +569,6 @@ public void getAnnotationForTagValueExpression(String test) {
public void getAnnotationForArgumentToString(Long param) {
}

@Timed
@Override
public void getMultipleAnnotationsForTagValueExpression(DataHolder param) {

}

@Timed
@Override
public void getMultipleAnnotationsWithContainerForTagValueExpression(DataHolder param) {

}

}

static class MeterTagSuper {
Expand Down Expand Up @@ -781,25 +699,4 @@ public void call() {

}

public static final class DataHolder {

private final String value1;

private final String value2;

private DataHolder(String value1, String value2) {
this.value1 = value1;
this.value2 = value2;
}

public String getValue1() {
return value1;
}

public String getValue2() {
return value2;
}

}

}

0 comments on commit 1f20895

Please sign in to comment.