Change a default annotation value for all usages
Clash Royale CLAN TAG#URR8PPP
Change a default annotation value for all usages
The @Timed
annotation in Spring Boot (part of Micrometer) has several fields. One of these is:
@Timed
double percentiles() default ;
I would like to set this value once across the entire codebase to a different array, say:
new double 0.0, 50.0 ;
This is achievable in one of two ways that I know of:
Setting the field on every instance:
@Timed(percentiles = new double 0.0, 50.0 )
Using @AliasFor
or meta-annotations to create a different annotation with the desired value.
@AliasFor
I have also come across the AnnotationUtils class, but cannot see how to achieve my goal.
What is the standard way of doing this in Spring Boot? If it cannot be done in Spring Boot, how does one do it with the JDK's own reflection capabilities?
@Stultuske A default is there to be changed. Having no percentiles in your statistics is completely useless. The value is designed to be overriden.
– Paul Benn
Aug 10 at 9:29
yes, but not for all possible instances, that's when it stops being a default. The point of a default is to be the fallback value unless another value is chosen by the implementation
– Stultuske
Aug 10 at 9:36
2 Answers
2
You can create your own meta-annotation with @Timed
. See for more details: https://github.com/micrometer-metrics/micrometer/issues/145
@Timed
That was my option 2 - I'll edit my question to make it clear I was referring to meta-annotations. I was looking for a way to do it without the use of a new annotation, but I'll definitely consider this if it's not possible. Thank you!
– Paul Benn
Aug 10 at 9:45
AFAIK this is a general approach to achieve the goal you mentioned.
– Johnny Lim
Aug 10 at 9:49
If you are looking to configure a set of percentiles for all histograms generated throughout your application you can use a MeterFilter
.
MeterFilter
Micrometer Docs: https://micrometer.io/docs/concepts#_configuring_distribution_statistics
In your spring boot project you would create the meter filter as a bean ie.
@Bean
public MeterFilter meterFilter()
return new MeterFilter()
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config)
return DistributionStatisticConfig.builder()
.percentiles(0.5, 0.75, 0.95, 0.98, 0.99)
.percentilesHistogram(true)
.build()
.merge(config);
;
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
the standard way of doing this is "NOT". that default value is by design, it's because they want that to be the default value
– Stultuske
Aug 10 at 9:26