-
Notifications
You must be signed in to change notification settings - Fork 893
[OpenTelemetry] Move BucketLookup tree to AggregatorStore #6715
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
Changes from all commits
a0ddbc6
9c9c5d5
85c972e
7934ab0
358a59d
697d90b
43ba5d4
7b27dcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,128 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Copyright The OpenTelemetry Authors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Diagnostics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Runtime.CompilerServices; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace OpenTelemetry.Metrics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal sealed class HistogramExplicitBounds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal const int DefaultBoundaryCountForBinarySearch = 50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly BucketLookupNode? bucketLookupTreeRoot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly Func<double, int> findHistogramBucketIndex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public HistogramExplicitBounds(double[] bounds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.Bounds = CleanUpInfinitiesFromExplicitBounds(bounds); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.findHistogramBucketIndex = this.FindBucketIndexLinear; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.Bounds.Length >= DefaultBoundaryCountForBinarySearch) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.bucketLookupTreeRoot = ConstructBalancedBST(this.Bounds, 0, this.Bounds.Length); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.findHistogramBucketIndex = this.FindBucketIndexBinary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static BucketLookupNode? ConstructBalancedBST(double[] values, int min, int max) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (min == max) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int median = min + ((max - min) / 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new BucketLookupNode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Index = median, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UpperBoundInclusive = values[median], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LowerBoundExclusive = median > 0 ? values[median - 1] : double.NegativeInfinity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Left = ConstructBalancedBST(values, min, median), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Right = ConstructBalancedBST(values, median + 1, max), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public double[] Bounds { get; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public int FindBucketIndex(double value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.findHistogramBucketIndex(value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static double[] CleanUpInfinitiesFromExplicitBounds(double[] bounds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (var i = 0; i < bounds.Length; i++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (double.IsNegativeInfinity(bounds[i]) || double.IsPositiveInfinity(bounds[i])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return bounds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .Where(b => !double.IsNegativeInfinity(b) && !double.IsPositiveInfinity(b)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .ToArray(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+65
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (var i = 0; i < bounds.Length; i++) | |
| { | |
| if (double.IsNegativeInfinity(bounds[i]) || double.IsPositiveInfinity(bounds[i])) | |
| { | |
| return bounds | |
| .Where(b => !double.IsNegativeInfinity(b) && !double.IsPositiveInfinity(b)) | |
| .ToArray(); | |
| } | |
| } | |
| List<double>? filtered = null; | |
| for (var i = 0; i < bounds.Length; i++) | |
| { | |
| var b = bounds[i]; | |
| if (double.IsNegativeInfinity(b) || double.IsPositiveInfinity(b)) | |
| { | |
| if (filtered == null) | |
| { | |
| filtered = new List<double>(bounds.Length - 1); | |
| for (var j = 0; j < i; j++) | |
| { | |
| filtered.Add(bounds[j]); | |
| } | |
| } | |
| // skip this value | |
| } | |
| else | |
| { | |
| if (filtered != null) | |
| { | |
| filtered.Add(b); | |
| } | |
| } | |
| } | |
| if (filtered != null) | |
| { | |
| return filtered.ToArray(); | |
| } |
Uh oh!
There was an error while loading. Please reload this page.