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

Fix exponential histogram bucket snapshot #4313

Merged
merged 4 commits into from
Mar 21, 2023

Conversation

alanwest
Copy link
Member

As @utpilla points out (#4303 (comment)), I have lost all ability to reason over CircularBufferBuckets. With some enhancements to my 🧠, I believe this PR makes the world right again.

@alanwest alanwest requested a review from a team March 17, 2023 23:20
@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

Merging #4313 (e96326b) into main (811d0eb) will increase coverage by 0.07%.
The diff coverage is 100.00%.

❗ Current head e96326b differs from pull request most recent head 2d76301. Consider uploading reports for the commit 2d76301 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4313      +/-   ##
==========================================
+ Coverage   84.50%   84.57%   +0.07%     
==========================================
  Files         298      298              
  Lines       11888    11899      +11     
==========================================
+ Hits        10046    10064      +18     
+ Misses       1842     1835       -7     
Impacted Files Coverage Δ
src/OpenTelemetry/Metrics/CircularBufferBuckets.cs 100.00% <100.00%> (ø)
...enTelemetry/Metrics/ExponentialHistogramBuckets.cs 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

@@ -81,7 +86,7 @@ internal Enumerator(long[] buckets)
/// collection.</returns>
public bool MoveNext()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the unit tests should also cover a scale-down scenario when the CircularBufferBuckets offset is updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not very obvious, but the existing tests actually do cover this scenario.

Even this simple test that only records two values requires a scale down. When the first value is recorded (10) the initial scale of 20 is fine, but when the second value is recorded (5) a scale down is necessary to fit this range of values within the default 160 buckets.

// SECOND EXPORT
expectedHistogram.Record(5);
histogram.Record(5);
meterProvider.ForceFlush();

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to merge this PR, but I will be coming back to the tests. Clearly there's improvements to make as the bug this PR fixes is not really covered by any tests yet.

@alanwest alanwest merged commit a46039a into open-telemetry:main Mar 21, 2023
@alanwest alanwest deleted the alanwest/fix-exp-histogram branch March 21, 2023 16:42
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.

2 participants