-
Notifications
You must be signed in to change notification settings - Fork 468
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
Metrics aggregate collector generic over temporality #2506
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2506 +/- ##
=====================================
Coverage 77.9% 77.9%
=====================================
Files 123 124 +1
Lines 22944 22974 +30
=====================================
+ Hits 17880 17915 +35
+ Misses 5064 5059 -5 ☔ View full report in Codecov by Sentry. |
f89f06b
to
09ebfdc
Compare
const TEMPORALITY: Temporality; | ||
type Aggr: Aggregator; | ||
|
||
fn measure(&self, value: <Self::Aggr as Aggregator>::PreComputedValue, attributes: &[KeyValue]); |
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.
It's getting a bit too confusing with these new coupled traits. Could we separate the concerns here? Could we update Collector
trait to only have collect related methods and AggregateMap
trait to only have update related methods? You could then keep an impl
of both the traits as fields of ExpoHistogram
struct.
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.
Not sure if it's possible to have this separation, basically this whole things is like an onion.
Starting from the center:
trait AggregateMap
- implement the core data structure optimized for updating AND collecting aggregates for specific temporality (e.g.DeltaValueMap
, andCumulativeValueMap
)trait AggregateCollector
- provides filtering attributes AND collecting impl specificDataPoints
intodyn Aggregation
(including time initialization for specific temporality). There's only one implementation, -Collector
. The reason we have this trait, is becauseCollector
itself is also generic (currently only overtrait AggregateMap
, but it might also be generic over "aggregate-filter"), which makes trait bounds for implementations to be very verbose). Important property of this implementation is that it has all common code for aggregations.- specific aggregation e.g. (Sum, LastValue, Histogram, etc..) - implements
Measure
andComputeAggregation
traits, which are used by SDK. Also implementsInitAggregationData
which is used byAggregateCollector
to make whole collection phase reusable.
The thing that I like about this is that 1) and 2) (e.g. impls for trait AggregateMap
and trait AggregateCollector
) is common code for absolutely all aggregates. The only aggregate specific logic is in three traits: Measure
, ComputeAggregation
, InitAggregationData
.
Regarding splitting...:
trait AggregateMap
cannot be split, because it's implementation has optimized internal structure that only it knows how to update and collect- since
trait AggregateCollector
depends ontrait AggregateMap
, it also cannot be split into few instances. - same fields within specific implementations can be used in measure and collect phases, as well. (e.g.
Histogram::bounds
field), so splitting concrete implementation not optimal as well. - so the
AggregateFns
implementation is probably most efficient way to do it. (e.g. Arc and clone, so one instance implements Measure,- anotherComputeAggregation
).
BTW, I agree that this gets a bit confusing, but I think better naming would solve the problem here... but that's the hardest part :)
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.
Mm... maybe I have one more idea.
Instead of having specific aggregation "the final thing" (which implements Measure
and ComputeAggregation
). I could make that Collector
is the final thing, and specific aggregations would have a trait which will be used to provide specific functionality...
I will probably create separate revision for that, (so we could compare both at the same time).
Ok?
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.
#2530 Same thing,- new design.
IMO it turned out very good, I like this new design much more.
If you have same opinion, then we can close this PR.
opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs
Outdated
Show resolved
Hide resolved
01cd8a0
to
ea151e4
Compare
Prerequisite for #2328
Changes
Provided several interfaces that allow to provide "ValueMap" implementation for specific temporality.
The key element is
Collector
(which implementsAggregateCollector
). It provides common functionality for all aggregations (Sum, LastValue, Histogram, etc...):This allow to have very clean concrete implementations. I have refactored
ExponentialHistogram
to use these new interfaces as an example.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes