-
Notifications
You must be signed in to change notification settings - Fork 440
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 metrics sorted/deduped bug AND extract common functionality for better code usage/consistency. #2097
Conversation
This looks like same as #2093? |
@fraillt Good work here! Just wondering if you hit the issue in a real application OR just that the prom tests started failing due to this, that led you to dig deep into this? |
Indeed solves same issue as #2093, I don't use this version in production yet, but in production we have custom MetricReader that expects sorted attributes, so I would be caching it in prod as well :) |
Can you clarify if you expect sorted attributes or sorted+de-duped attributes? OTel spec ensures uniqueness (i.e no de-duplications), but not ordering. My main question was - how did the instrumentation end up with duplicate attributes in the first place? That feels like an instrumentation bug to me to be fixed. |
At the moment, our production setup is a bit custom... |
Got it. You need to do the sorting yourself, as that is not something guaranteed by OTel spec. It may work, but that is not a guarantee, so its best if your custom MetricReader does not rely on undocumented behavior. |
804f325
to
89d270d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2097 +/- ##
=====================================
Coverage 78.0% 78.0%
=====================================
Files 121 122 +1
Lines 20936 20873 -63
=====================================
- Hits 16332 16283 -49
+ Misses 4604 4590 -14 ☔ View full report in Codecov by Sentry. |
Updated revision, with few notable changes:
Overall performance has increased, at least in few places:
|
/// This must implement [Hash], [PartialEq], and [Eq] so it may be used as | ||
/// HashMap keys and other de-duplication methods. | ||
#[derive(Clone, Default, Debug, PartialEq, Eq)] | ||
pub(crate) struct AttributeSet(pub(crate) Vec<KeyValue>, u64); |
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.
its not clear what is the reason why this is being changed? can you update the PR desc. with the reasoning.
if the goal is to get predictable attribute set in readers, then #2093 looks sufficient to achieve that, without having to touch the hot path code.
89d270d
to
500c759
Compare
I'll close this PR for few reasons:
|
Fixes #
#2085 (comment)
Basically the issue was, that introduced in #1989.
It made success path super fast, by avoiding any copying/sorting/deduplicating of attributes, which is very cool,
BUT...
in order to achieve that in attribute set tracker it was inserted two records:
original_list
ANDsorted_deduped_list
.Later, during aggregation, there was introduced deduplication mechanism, so that only one attribute set would be selected for specific tracker.
However, since rust uses randomness in hashing, the order in which these two attribute sets (original and deduped) is returned is random.
So the end result is that everytime application is restarted,
MetricReader
will getoriginal_list
ORsorted_dedup_list
at random.Changes
Bug fix
sorted_deduped
attributes.This should also improve performance for collection stage as it only needs to go through this list of already
sorted_deduped
attributes.attributes_should_be_sorted_and_deduplicated
test, to make sure this wouldn't happen again.Other improvements
AttributeSet
rustc-hash
.sorted_deduped
list uses AttributeSet as key, for faster hashing/lookup.AttributeSet
to it's own file, in order to better protect internal implementation to guarantee sorting&deduping.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes