Synopsis
As part of this PR, Micrometer now supports a new annotation based and more declarative API to define Counters. That'd be great if we could add a new auto-configuration in Spring Boot to enable this feature by default.
Motivation
As I've elaborated in the corresponding Micrometer issue, using @Counted annotation would enable us to record method call failure rates in a more declarative way.
Basically, it provides a familiar enterprise-y approach to keep track of:
- A number of successful attempts.
- A Number of failed attempts.
For any given task. For example, when we manage to finish a task successfully, an annotated method with, say, @Counted("notifications.requested"), would increment the notifications.requested counter metric along with a success tag. Otherwise, it tags the same metric with failure status along with the exception.
This API hides the underlying mechanism for creating, incrementing, tagging and registering counter metrics!
How to Integrate
We just have to register the CountedAspect as a Spring Bean!
Release Plan
This feature would be part of Micrometer 1.2.0 (non-LTS).
Comment From: philwebb
It would be nice if we could support both @Counted and @Timed in a consistent way, however, the use of AspectJ concerns me. Users will need to both register the CountedAspect bean and also include spring-boot-starter-aop as a dependency. We might be able to offer Spring integration in a similar way to @Cacheable so that it can work without AspectJ.
Comment From: alimate
@philwebb I will take a look at Cachable integration.
Comment From: bruto1
I actually wrote an integration not unlike the one discussed here a while ago for work Is anyone interested in this contribution to Spring or has it already been done (quick google search says no)?
It enables declarative meter creation like this:
Counter counterTag(@Tag String tag);
@GaugeMetric
void gauge2(@Tag String prefix, DoubleSupplier f, @Tag String suffix);
@SummaryMetric(baseUnit = "foo")
DistributionSummary summaryWithBaseUnit();
@SummaryMetric(scale = 100)
DistributionSummary summary();
@Description("das taimer")
Timer timerTagWithSummaryMetric(@Tag String tag1, @Tag int tag2);
WDYT, @philwebb ?
Comment From: bruto1
tagging @alimate and whoever else might be interested
Comment From: philwebb
We're cleaning out the issue tracker and closing issues that we've not seen much demand to fix. Feel free to comment with additional justifications if you feel that this one should not have been closed.
Comment From: bruto1
@philwebb Just thinking that annotation-based metrics would be a little bit easier on the eyes than the verbose Micrometer builders There isn't much overhead in the impl as of now It's already written, just asking if it would be a worthy addition to the framework
Comment From: juzerali
It's a shame that Spring framework does not have this feature yet. This reduces boilerplate in code so much.