Reputation: 5154
I have a Spring Boot application, full of endpoints (i.e. @Controller
's) and @Service
's with @Repository
's behind them. I'd like to make all of them to export the timed metrics to Micrometer. At some point I'd like to disable them all too. At some point I would need to meter, for instance, all methods of @Service
labelled classes or meter the timing of @Repository
's. So I don't like all the classes that already keep @Service
annotation to have @Timed
inserted and the removed, and I have to idea how to do it with the Spring Data interfaces for repositories.
What kind of beans I should set up to make MeterRegistry
consider that all the @RestController
labeled code already have @Timed
annotation, to make this configuration an easy to switch on and switch off property? I know, that for the incoming http request management.metrics.web.server.request.autotime.enabled=true
will make this trick for getting the time of incoming http request, that will work for me.
However, the same probably I'd like to apply to service and repository layer, if possible. But there is no way to identify what is actually service, rather than @Service
annotation. So as I don't like to add @Timed
there explicitly, what kind of set up can be done to make MeterRegistry
consider any method in @Service
labelled class and in any Spring Data repository at the application?
Upvotes: 3
Views: 2162
Reputation: 6391
There is no out-of-the-box solution for it, but you can implement it by yourself, eg., with Spring AOP.
You can look at the TimedAspect source code, especially at @Around
aspect for @Timed
annotation, and recreate it for @Service
or @Repository
.
Upvotes: 3