-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Metric endpoint is summing up same metric #14497
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
Metric endpoint is summing up same metric #14497
Conversation
} | ||
else { | ||
meters.addAll(registry.find(name).tags(tags).meters()); | ||
Collection<Meter> meterFound = registry.find(name).tags(tags).meters(); | ||
if (meterFound != null && meterFound.size() > 0) { |
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.
Micrometer guarantees that meterFound
is non-null. Could use isEmpty()
on second condition.
@@ -112,15 +112,20 @@ private Tag parseTag(String tag) { | |||
return Tag.of(parts[0], parts[1]); | |||
} | |||
|
|||
private void collectMeters(List<Meter> meters, MeterRegistry registry, String name, | |||
Iterable<Tag> tags) { | |||
private boolean findFirstMatchingMeters(List<Meter> meters, MeterRegistry registry, |
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.
Rather than modifying a parameter, this method could simply return a Collection
.
@jkschneider , please review. |
meters.addAll(registry.find(name).tags(tags).meters()); | ||
Collection<Meter> metersFound = registry.find(name).tags(tags).meters(); | ||
if (!metersFound.isEmpty()) { | ||
return new ArrayList<>(metersFound); |
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.
No need to wrap this. The list returned is already an immutable copy.
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.
Thanks @jkschneider , the reason I am wrapping it into List
is to avoid returning Collection
from this method.
Collection<Meter> metersFound = registry.find(name).tags(tags).meters();
If we return Collection
, the MetricEndpoint
methods should be refactored so that Collection
could be pass around instead of List
interface OR the return type should be downcasted to List
(which is dangerous as we dont have control on MeterRegistry#find
)
Changing MetricEndpoint
methods to pass Collection
is minor refactoring, with following highlight.
Line 93 in 13fef7d
Meter.Id meterId = meters.get(0).getId(); |
will be change to
meters.iterator().next().getId();
Please confirm should I go ahead and do this minor change?
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.
The minor refactoring seems preferable to me to generating extra garbage in this case, as minor as that will be.
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.
Thanks @jkschneider, pls review.
@philwebb , @jkschneider , the issue is closed but PR is still open. Is there anything l can do to help you merge it? |
The issue has been closed because this PR supersedes it. All is good, we just need some time to review it. |
* pr/14497: Polish "Stop MetricsEndpoint from summing up same metrics" Stop MetricsEndpoint from summing up same metrics
@pulkitmehra Thanks for the fix. This is now in 2.0.x and master. |
This PR fixed issue #14066