Skip to content

Add an empty constructor to TimedAspect - #1419

Merged
shakuzen merged 1 commit into
micrometer-metrics:masterfrom
luisrosilva:patch-1
Jun 11, 2019
Merged

shakuzen merged 1 commit into
micrometer-metrics:masterfrom
luisrosilva:patch-1

Conversation

@luisrosilva

Copy link
Copy Markdown
Contributor

Having an empty constructor available on TimedAspect would make it easier to use load time weaving via aspectj.
As referenced in the documentation (https://micrometer.io/docs/concepts, on section 3.2), Micrometer provides a static global registry (Metrics.globalRegistry) that can be used to achieve this.

Having an empty constructor available on TimedAspect would make it easier to use load time weaving via aspectj.
As referenced in the documentation (https://micrometer.io/docs/concepts, on section 3.2), Micrometer provides a static global registry (Metrics.globalRegistry) that can be used to achieve this.
@shakuzen

Copy link
Copy Markdown
Member

Sorry for my ignorance on load time weaving, but you could explain more how this constructor makes that easier, perhaps by showing the configuration required before and after this change?

@luisrosilva

Copy link
Copy Markdown
Contributor Author

No problem, I'm no expert on that either and documentation is rather scarce, so I can be wrong on this. However, here is what I know:

To use load time weaving, we have to provide these additional properties on jvm launch:

-javaagent:/Users/luissilva/.m2/repository/org/springframework/spring-instrument/5.1.5.RELEASE/spring-instrument-5.1.5.RELEASE.jar
-javaagent:/Users/luissilva/.m2/repository/org/aspectj/aspectjweaver/1.9.2/aspectjweaver-1.9.2.jar

The issue is that aspect instantiation happens in a different place, not controlled by spring. Aspectj weaver doesn't know about spring and as such it can't do injection. Also the spring context doesn't know about the aspect, so it can't help there. According to documentation (https://www.eclipse.org/aspectj/doc/next/progguide/semantics-aspects.html), aspects are instanciated upon need by the weaver, and thus the default empty constructor is used. I've tested these changes locally after finding about Metrics.globalRegistry and it worked ok.

The advantage of using this method is that aspect usage is independent of spring proxies and so, private methods or bean recursive calls can be intercepted with those as well.

@shakuzen shakuzen added the enhancement A general enhancement label Jun 11, 2019
@shakuzen shakuzen added this to the 1.2.0 (non-LTS) milestone Jun 11, 2019
@shakuzen
shakuzen merged commit 4e5f395 into micrometer-metrics:master Jun 11, 2019
@shakuzen

Copy link
Copy Markdown
Member

@luisrosilva Thank you for the contribution. This is merged now and will be included in the upcoming 1.2.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants