Skip to content

Commit

Permalink
Merge pull request #33598 from Ladicek/fix-micrometer-mpmetrics-annot…
Browse files Browse the repository at this point in the history
…ation-transformation

Fix the Micrometer MP Metrics annotation transformation
  • Loading branch information
ebullient authored May 25, 2023
2 parents 5b3d82c + 5ef3b08 commit a9c3ebf
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ static AnnotationsTransformerBuildItem transformAnnotations(final IndexView inde
}

static AnnotationsTransformerBuildItem transformAnnotations(final IndexView index,
DotName sourceAnnotation, DotName targetAnnotation) {
DotName sourceAnnotationName, DotName targetAnnotationName) {
return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
@Override
public void transform(TransformationContext ctx) {
final Collection<AnnotationInstance> annotations = ctx.getAnnotations();
AnnotationInstance annotation = Annotations.find(annotations, sourceAnnotation);
AnnotationInstance annotation = Annotations.find(annotations, sourceAnnotationName);
if (annotation == null) {
return;
}
Expand All @@ -59,8 +59,8 @@ public void transform(TransformationContext ctx) {

// Remove the @Counted annotation when both @Counted & @Timed/SimplyTimed
// Ignore @Metric with @Produces
if (removeCountedWhenTimed(sourceAnnotation, target, classInfo, methodInfo) ||
removeMetricWhenProduces(sourceAnnotation, target, methodInfo, fieldInfo)) {
if (removeCountedWhenTimed(sourceAnnotationName, target, classInfo, methodInfo) ||
removeMetricWhenProduces(sourceAnnotationName, target, methodInfo, fieldInfo)) {
ctx.transform()
.remove(x -> x == annotation)
.done();
Expand All @@ -71,10 +71,14 @@ public void transform(TransformationContext ctx) {
MetricAnnotationInfo annotationInfo = new MetricAnnotationInfo(annotation, index,
classInfo, methodInfo, fieldInfo);

// preserve the original annotation target, `ctx.getTarget()` is different in case of method parameters
AnnotationInstance newAnnotation = AnnotationInstance.create(targetAnnotationName, annotation.target(),
annotationInfo.getAnnotationValues());

// Remove the existing annotation, and add a new one with all the fields
ctx.transform()
.remove(x -> x == annotation)
.add(targetAnnotation, annotationInfo.getAnnotationValues())
.add(newAnnotation)
.done();
}
});
Expand Down

0 comments on commit a9c3ebf

Please sign in to comment.