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

Exponential Bucket Histogram - part 7 #3499

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/OpenTelemetry/Metrics/ExponentialBucketHistogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ internal class ExponentialBucketHistogram
private int scale;
private double scalingFactor; // 2 ^ scale / log(2)

public ExponentialBucketHistogram(int scale, int maxBuckets = 160)
/// <summary>
/// Initializes a new instance of the <see cref="ExponentialBucketHistogram"/> class.
/// </summary>
/// <param name="maxBuckets">
/// The maximum number of buckets in each of the positive and negative ranges, not counting the special zero bucket. The default value is 160.
/// </param>
public ExponentialBucketHistogram(int maxBuckets = 160)
: this(maxBuckets, 20)
{
}

internal ExponentialBucketHistogram(int maxBuckets, int scale)
{
/*
The following table is calculated based on [ MapToIndex(double.Epsilon), MapToIndex(double.MaxValue) ]:
Expand Down Expand Up @@ -80,7 +91,12 @@ The following table is calculated based on [ MapToIndex(double.Epsilon), MapToIn
*/
Guard.ThrowIfOutOfRange(scale, min: -11, max: 20);

Guard.ThrowIfOutOfRange(maxBuckets, min: 1);
/*
Regardless of the scale, MapToIndex(1) will always be -1, so we need two buckets at minimum:
bucket[-1] = (1/base, 1]
bucket[0] = (1, base]
*/
Guard.ThrowIfOutOfRange(maxBuckets, min: 2);

this.Scale = scale;
this.PositiveBuckets = new CircularBufferBuckets(maxBuckets);
Expand Down
Loading