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

Directly implement Measure trait for metric aggregates #2371

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

Conversation

fraillt
Copy link
Contributor

@fraillt fraillt commented Dec 2, 2024

Changes

At the moment aggregation implementations (Sum, LastValue, Histogram, etc...) doesn't implement any traits. But there's a Measure<T> trait is used to implement SyncInstrument.
At the moment there's a filter function AggregateBuilder, that makes implements Measure<T> for aggregations. The way it works is like this:

  1. create Arc, which will be used to measure and collect on aggregation.
  2. create closure that implements Measure<T>, which captures Arc for measurement
  3. wraps it in another closure, that checks if attributes should be filtered (this check is for every single call to measure)
  4. Finally create Arc<dyn Measure<T>.

In this revision aggregations directly implement Measure<T>, so things get a bit simpler:

  • if there's no filtering then directly use same Arc<SpecificAggregation> (no need to wrap in closure, and then in another closure and then create Arc again)
  • if there's filtering enabled, construct Arc<FilteredMeasureInstrument> which wraps Arc<SpecificAggregation> to do attribute filtering.

Technically this should be more performant (because if there's no filtering, then there's no need to have two closures and 1 extra Arc), but compiler is smart enough, so I didn't observed any increase in performance.
Regardless, in theory there's less work to be done, and also less code to understand :)

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 December 2, 2024 07:43
} else {
f.call(n, attrs);
};
fn maybe_filtered_measurement(&self, instrument: Arc<impl Measure<T>>) -> Arc<dyn Measure<T>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any advice on naming?
both for maybe_filtered_measurement function, and for FilteredMeasureInstrument...

Copy link

codecov bot commented Dec 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.5%. Comparing base (e0159ad) to head (00bee01).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2371     +/-   ##
=======================================
- Coverage   79.5%   79.5%   -0.1%     
=======================================
  Files        123     123             
  Lines      21492   21485      -7     
=======================================
- Hits       17094   17085      -9     
- Misses      4398    4400      +2     

☔ 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