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

Fix the Micrometer MP Metrics annotation transformation #33598

Merged
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 @@ -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