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

Metrics aggregate map is generic over temporality #2530

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fraillt
Copy link
Contributor

@fraillt fraillt commented Jan 22, 2025

Changes

Same functionality as in #2506, but in my opinion a bit simpler and even cleaner.
The thing that I especially like, is how elegant is concrete implementation for an aggregation.

pub(crate) struct SumNew {
    pub(crate) monotonic: bool,
}

impl<T> AggregationImpl<T> for SumNew
where
    T: Number,
{
    type Aggr = Increment<T>;
    type AggrData = data::Sum<T>;

    fn precompute(&self, value: T) -> T {
        value
    }

    fn new_aggregation_data(&self, temporality: Temporality, time: AggregateTime) -> data::Sum<T> {
        data::Sum {
            data_points: vec![],
            start_time: time.start,
            time: time.current,
            temporality,
            is_monotonic: self.monotonic,
        }
    }

    fn reset_aggregation_data(
        &self,
        existing: &mut data::Sum<T>,
        temporality: Temporality,
        time: AggregateTime,
    ) {
        existing.data_points.clear();
        existing.start_time = time.start;
        existing.time = time.current;
        existing.temporality = temporality;
        existing.is_monotonic = self.monotonic;
    }

    fn build_create_points_fn(
        &self,
    ) -> impl FnMut(Vec<KeyValue>, &Increment<T>) -> SumDataPoint<T> {
        |attributes, aggr| SumDataPoint {
            attributes,
            value: aggr.value.get_value(),
            exemplars: vec![],
        }
    }
}

Yep, that's full implementation for Sum :) all the other common stuff is in aggregate_impl.rs file.
I deliberately didn't remove existing code, so it would be easier to evaluate this new design, and once we're happy with it, we can apply it.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@fraillt fraillt requested a review from a team as a code owner January 22, 2025 12:25
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 97.05882% with 4 lines in your changes missing coverage. Please review.

Project coverage is 77.5%. Comparing base (90b0dd4) to head (bdc6ecd).

Files with missing lines Patch % Lines
opentelemetry-sdk/src/metrics/data/mod.rs 50.0% 3 Missing ⚠️
...pentelemetry-sdk/src/metrics/internal/aggregate.rs 92.8% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2530     +/-   ##
=======================================
- Coverage   77.8%   77.5%   -0.3%     
=======================================
  Files        123     124      +1     
  Lines      23059   23194    +135     
=======================================
+ Hits       17940   17981     +41     
- Misses      5119    5213     +94     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant