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
MeterTag #3727
MeterTag #3727
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly minor feedback left in comments. Looks great overall. This should be nice and offers good usability while being flexible.
The main feedback I have is a bikeshed argument about naming. In Micrometer core, I would go with @MeterTag
instead of @MetricTag
. We use Meter
elsewhere there consistently, as far as I know. On the classes in commons, it feels a little odd they have "Tag" in the name even though commons has no tag references and instead has KeyValue. I wonder if we need the "Tag" part in the name in commons. It might be too generic, but what about ValueResolver
and ValueExpressionResolver
? They are resolving the Value part of KeyValue and we do say tag value also. Maybe it isn't a big deal either way, but it stuck out to me in reviewing.
micrometer-commons/src/main/java/io/micrometer/common/annotation/TagAnnotationHandler.java
Show resolved
Hide resolved
String expression() default ""; | ||
|
||
/** | ||
* Use this bean to resolve the tag value. Has the highest precedence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"bean" feels a little odd here. The class type given here will be used to resolve the TagValueResolver
instance from the function given to the MetricsTagAnnotationHandler
.
micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java
Show resolved
Hide resolved
* <p> | ||
* try with the {@link TagValueResolver} bean if the value of the bean wasn't set, try to | ||
* evaluate a SPEL expression if there’s no SPEL expression just return a | ||
* {@code toString()} value of the parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaDoc needs to be updated for metrics (it mentions span and SPEL and beans). It would also be good to make a warning that this should not be used with parameters that are going to result in high cardinality values (e.g. user-provided input) and there is no protection provided out-of-the-box for if it is used in such a way.
e59a23e
to
87c07a3
Compare
.tags(EXCEPTION_TAG, exceptionClass) | ||
.tags(tagsBasedOnJoinPoint.apply(pjp)) | ||
.publishPercentileHistogram(timed.histogram()) | ||
.publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NullTernary: This conditional expression may evaluate to null, which will result in an NPE when the result is unboxed.
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Help us improve LIFT! (Sonatype LiftBot external survey)
Was this a good recommendation for you? Answering this survey will not impact your Lift settings.
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
int i = 0; | ||
for (Annotation[] parameter : parameters) { | ||
for (Annotation parameter2 : parameter) { | ||
if (tagClazz.isAssignableFrom(parameter2.getClass())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetClassOnAnnotation: Calling getClass() on an annotation may return a proxy class
if (tagClazz.isAssignableFrom(parameter2.getClass())) { | |
if (tagClazz.isAssignableFrom(parameter2.annotationType())) { |
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Help us improve LIFT! (Sonatype LiftBot external survey)
Was this a good recommendation for you? Answering this survey will not impact your Lift settings.
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
🛠 Lift Auto-fixSome of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.1 # Download the patch
curl https://lift.sonatype.com/api/patch/github.com/micrometer-metrics/micrometer/3727.diff -o lift-autofixes.diff
# Apply the patch with git
git apply lift-autofixes.diff
# Review the changes
git diff Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command: curl https://lift.sonatype.com/api/patch/github.com/micrometer-metrics/micrometer/3727.diff | git apply Once you're satisfied, commit and push your changes in your project. Footnotes |
87c07a3
to
bfd076d
Compare
I messed up the rebasing and I missed this important commit when merging this PR bc59c47 😬 |
* Polish MeterTag changes See gh-3727 * Update micrometer-commons/src/main/java/io/micrometer/common/annotation/AnnotationUtils.java Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com> --------- Co-authored-by: Marcin Grzejszczak <marcin@grzejszczak.pl> Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com>
TimedAspect
(too many constructors already)Timer.Builder
not for theLongTaskTimer.Builder
(code can be modified to allow that)fixes #1732