Skip to content
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

Merged
merged 3 commits into from Apr 7, 2023
Merged

MeterTag #3727

merged 3 commits into from Apr 7, 2023

Conversation

marcingrzejszczak
Copy link
Contributor

  • Moves the common code from Micrometer Tracing
  • Adds a setter to TimedAspect (too many constructors already)
  • This only works for the Timer.Builder not for the LongTaskTimer.Builder (code can be modified to allow that)

fixes #1732

Copy link
Member

@shakuzen shakuzen left a 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.

String expression() default "";

/**
* Use this bean to resolve the tag value. Has the highest precedence.
Copy link
Member

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.

* <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
Copy link
Member

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.

.tags(EXCEPTION_TAG, exceptionClass)
.tags(tagsBasedOnJoinPoint.apply(pjp))
.publishPercentileHistogram(timed.histogram())
.publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles());
Copy link
Contributor

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())) {
Copy link
Contributor

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


Suggested change
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 ]

@sonatype-lift
Copy link
Contributor

sonatype-lift bot commented Apr 6, 2023

🛠 Lift Auto-fix

Some 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

  1. You can preview the patch by opening the patch URL in the browser.

@marcingrzejszczak marcingrzejszczak merged commit b78c24c into main Apr 7, 2023
8 checks passed
@marcingrzejszczak marcingrzejszczak deleted the issues_#1732 branch April 7, 2023 09:56
marcingrzejszczak added a commit that referenced this pull request Apr 7, 2023
@marcingrzejszczak
Copy link
Contributor Author

I messed up the rebasing and I missed this important commit when merging this PR bc59c47 😬

marcingrzejszczak added a commit to micrometer-metrics/tracing that referenced this pull request Apr 7, 2023
@shakuzen shakuzen changed the title MetricTag MeterTag Apr 7, 2023
izeye added a commit to izeye/micrometer that referenced this pull request Apr 16, 2023
@izeye izeye mentioned this pull request Apr 16, 2023
marcingrzejszczak added a commit that referenced this pull request Apr 18, 2023
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@Timed annotation with dynamic tags derived from input arguments and/or output
3 participants