Skip to content

Base2 exponential histogram aggregation #3346

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

Merged
merged 63 commits into from
Apr 25, 2025

Conversation

ethandmd
Copy link
Contributor

@ethandmd ethandmd commented Apr 4, 2025

Fixes #1391

Changes

Add base2 exponential histogram aggregation.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

Copy link

linux-foundation-easycla bot commented Apr 4, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

netlify bot commented Apr 4, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit beb9227
🔍 Latest deploy log https://app.netlify.com/sites/opentelemetry-cpp-api-docs/deploys/680bc887d6b270000856253d

@ethandmd
Copy link
Contributor Author

ethandmd commented Apr 4, 2025

@lalitb @ThomsonTan @marcalff @dbarker

In order to satisfy CLA check had to remove some @{corporate}.com alias from the commit history by using a new branch. I am closing the previous WIP PR and @felipesantosk and I will be working here.

Looking forward to your review and comments :)

Copy link

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 92.04893% with 26 lines in your changes missing coverage. Please review.

Project coverage is 89.67%. Comparing base (3e761d0) to head (beb9227).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...egation/base2_exponential_histogram_aggregation.cc 90.64% 22 Missing ⚠️
...etry/sdk/metrics/aggregation/default_aggregation.h 50.00% 2 Missing ⚠️
exporters/ostream/src/metric_exporter.cc 95.46% 1 Missing ⚠️
...nclude/opentelemetry/sdk/metrics/data/point_data.h 95.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3346      +/-   ##
==========================================
+ Coverage   89.55%   89.67%   +0.12%     
==========================================
  Files         210      211       +1     
  Lines        6505     6832     +327     
==========================================
+ Hits         5825     6126     +301     
- Misses        680      706      +26     
Files with missing lines Coverage Δ
exporters/ostream/test/ostream_metric_test.cc 100.00% <100.00%> (ø)
...pentelemetry/sdk/metrics/aggregation/aggregation.h 100.00% <ø> (ø)
...metry/sdk/metrics/aggregation/aggregation_config.h 100.00% <ø> (ø)
...e/opentelemetry/sdk/metrics/data/circular_buffer.h 100.00% <ø> (ø)
sdk/src/metrics/data/circular_buffer.cc 100.00% <100.00%> (ø)
exporters/ostream/src/metric_exporter.cc 91.55% <95.46%> (+0.65%) ⬆️
...nclude/opentelemetry/sdk/metrics/data/point_data.h 96.16% <95.00%> (-3.84%) ⬇️
...etry/sdk/metrics/aggregation/default_aggregation.h 79.02% <50.00%> (-1.50%) ⬇️
...egation/base2_exponential_histogram_aggregation.cc 90.64% <90.64%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ethandmd ethandmd changed the title [WIP] Base2 exponential histogram aggregation Base2 exponential histogram aggregation Apr 4, 2025
@ethandmd ethandmd marked this pull request as ready for review April 4, 2025 20:33
@ethandmd ethandmd requested a review from a team as a code owner April 4, 2025 20:33
@lalitb lalitb self-assigned this Apr 4, 2025

histogram_aggregation_config->max_scale_ = 3;

// histogram_aggregation_config->boundaries_ = std::vector<double>{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the boundary configuration still needed? Remove it if no.

HistogramPointData,
Base2ExponentialHistogramPointData,
LastValuePointData,
DropPointData>;
Copy link
Member

@lalitb lalitb Apr 21, 2025

Choose a reason for hiding this comment

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

Did a quick test on the effect of adding a Base2ExponentialHistogramPointData as new variant alternative. As the size of a variant type is determined by the size of its largest alternative, there seems to increase in ~50 bytes per aggregated value. For the maximum cardinality limit of 2000, this would account for 100KB worst scenario peek increase per configured instrument.

Refer - https://godbolt.org/z/cG6b6Ks1d

output:
sizeof(PointTypeWithBase2): 176 bytes
sizeof(PointTypeWithoutBase2): 120 bytes

I believe this increase is reasonable, unless there are specific concerns about memory usage at scale - with large number of configured instruments. @ThomsonTan ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for trying this. This extra memory consumption could be an issue for the users who are not using exponential histogram, as we've seen some user have very large number of instruments configured. @ethandmd , is it possible to make the feature opt-in to avoid taking the extra memory for users who don't use this feature?

Copy link
Member

Choose a reason for hiding this comment

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

We can also modify the Base2ExponentialHistogramPointData to contain unique_ptr to AdaptingCircularBufferCounter, as that seems to be inflating the size. Something like:

class Base2ExponentialHistogramPointDataUniquePtr {
public:
  uint64_t count_{};
  double sum_{};
  int32_t scale_{};
  uint64_t zero_count_{};
  std::unique_ptr<AdaptingCircularBufferCounter> positive_buckets_;
  std::unique_ptr<AdaptingCircularBufferCounter> negative_buckets_;
  double min_{}, max_{}, zero_threshold_{};
  bool record_min_max_ = true;
  size_t max_buckets_{};

  Base2ExponentialHistogramPointDataUniquePtr()
      : positive_buckets_{std::make_unique<AdaptingCircularBufferCounter>(0)},
        negative_buckets_{std::make_unique<AdaptingCircularBufferCounter>(0)} {}
};

The size seems to be reduced to the earlier size with that: - https://godbolt.org/z/zvdbfYYbs

sizeof(PointTypeWithBase2): 176 bytes
sizeof(PointTypeWithoutBase2): 120 bytes
sizeof(PointTypeWithBase2UniquePtr): 120 bytes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the analysis! Let me take a look

Copy link
Contributor

Choose a reason for hiding this comment

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

One more suggestion is moving below 2 files together and put them at the end of the class, which will make the padding more compact.

  int32_t scale_{};
  bool record_min_max_ = true;

@lalitb lalitb enabled auto-merge (squash) April 25, 2025 17:38
@lalitb lalitb merged commit 7bf1149 into open-telemetry:main Apr 25, 2025
66 checks passed
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.

[Metrics SDK] Add support for Exponential Histogram Aggregation
7 participants