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

Fix incorrect tags comparison when trying to match metric IDs #5544

Merged
merged 1 commit into from
Nov 29, 2022

Conversation

tjquinno
Copy link
Member

@tjquinno tjquinno commented Nov 28, 2022

Resolves #5541

The original code used an array comparison to compare the tags of a previously-registered metric with the tags of a candidate new metric.

Inside the MicroProfile Metrics implementation of MetricID the tags are stored in a TreeMap. So iterators deliver in key-order (that is, in order of ascending tag name). But the comparison in MetricStore did not order the candidate metric's tag array by tag name prior to comparing. Tag sets that should match might not, depending on the order in which the tags were specified in the array.

The PR just creates a temporary TreeMap to hold the candidate tags so it can compare that and the MetricID's TreeMap directly. Metric registration is typically a relatively infrequent event, so creating the TreeMap for this purpose should not hurt performance noticeably.

(BTW, this is not an issue in 2.x because the implementation is different and that code created a candidate MetricID for each candidate new metric and our code compared the two MetricIDs which did the right thing with the tags.)

@tjquinno tjquinno self-assigned this Nov 28, 2022
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 28, 2022
@@ -556,6 +556,14 @@ private <S> S access(Lock lock, Callable<S> action) {
}
}

private static boolean tagsMatch(Tag[] tags, Map<String, String> tagMap) {
Map<String, String> newTags = new TreeMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if this should optimize for the case of a single tag (to avoid creating the Map), but now I see you mention in the description that this is an infrequent operation. So LGTM!

@tjquinno tjquinno merged commit aab9770 into helidon-io:helidon-3.x Nov 29, 2022
@tjquinno tjquinno deleted the metrics-tags-fix-3.x branch November 29, 2022 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MetricRegistry::counter inconsistent result with multiple tags
2 participants