Fix incorrect tags comparison when trying to match metric IDs #5544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aTreeMap
. So iterators deliver in key-order (that is, in order of ascending tag name). But the comparison inMetricStore
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 theMetricID
'sTreeMap
directly. Metric registration is typically a relatively infrequent event, so creating theTreeMap
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 twoMetricID
s which did the right thing with the tags.)