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

Binary search histograms #3251

Closed
wants to merge 89 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
f53d8b6
Squashed commit of the following:
mic-max Sep 23, 2021
e51aca6
Merge remote-tracking branch 'upstream/main' into main
mic-max Sep 27, 2021
3d15631
Merge remote-tracking branch 'upstream/main' into main
mic-max Sep 30, 2021
472eabb
Merge remote-tracking branch 'upstream/main' into main
mic-max Oct 13, 2021
4295758
Merge remote-tracking branch 'upstream/main'
mic-max Oct 14, 2021
4de8d0f
Merge remote-tracking branch 'upstream/main'
mic-max Oct 18, 2021
ccd3b53
Guard Type summary comment fix
mic-max Oct 18, 2021
1cac13f
Update TracerProviderBuilder.cs
mic-max Oct 18, 2021
d971dae
TryFetch optional param to skip obj null check
mic-max Oct 20, 2021
8ba84c5
Make guard internal
mic-max Oct 20, 2021
45d4caf
GuardTest doesn't need to be a static class
mic-max Oct 20, 2021
0b4c80e
Update src/OpenTelemetry/DiagnosticSourceInstrumentation/PropertyFetc…
mic-max Oct 20, 2021
964e9a6
Update Guard.cs
mic-max Oct 20, 2021
eae26ac
Merge branch 'main' of https://github.com/mic-max/opentelemetry-dotnet
mic-max Oct 20, 2021
169547a
Add Compile Guard to required project files
mic-max Oct 20, 2021
a473889
Update OpenTelemetry.Instrumentation.Http.csproj
mic-max Oct 20, 2021
e256363
Merge branch 'main' into main
cijothomas Oct 26, 2021
307ca0a
Merge remote-tracking branch 'upstream/main'
mic-max Oct 27, 2021
a67164e
Merge remote-tracking branch 'upstream/main'
mic-max Nov 4, 2021
ebe09e7
Merge remote-tracking branch 'upstream/main'
mic-max Nov 5, 2021
46deabc
Merge remote-tracking branch 'upstream/main'
mic-max Nov 9, 2021
88867c6
Merge remote-tracking branch 'upstream/main'
mic-max Nov 9, 2021
583e946
Merge remote-tracking branch 'upstream/main'
mic-max Nov 16, 2021
28c0299
Merge remote-tracking branch 'upstream/main'
mic-max Dec 6, 2021
18fc9c9
Merge remote-tracking branch 'upstream/main'
mic-max Dec 7, 2021
7734ff6
Merge remote-tracking branch 'upstream/main'
mic-max Dec 13, 2021
34f9c83
Merge remote-tracking branch 'upstream/main'
mic-max Dec 17, 2021
6dc71f0
Merge remote-tracking branch 'upstream/main'
mic-max Jan 7, 2022
d0d778d
Merge remote-tracking branch 'upstream/main'
mic-max Jan 12, 2022
c2f2284
Merge remote-tracking branch 'upstream/main'
mic-max Jan 13, 2022
71baa29
Merge remote-tracking branch 'upstream/main'
mic-max Jan 13, 2022
7b177fa
Merge remote-tracking branch 'upstream/main'
mic-max Jan 14, 2022
7781ed4
Update CHANGELOG.md Files - --help
mic-max Jan 14, 2022
d76643f
Merge remote-tracking branch 'upstream/main'
mic-max Jan 25, 2022
1d5b23c
Merge remote-tracking branch 'upstream/main'
mic-max Feb 1, 2022
a406114
Merge remote-tracking branch 'upstream/main'
mic-max Feb 2, 2022
821aec8
Merge remote-tracking branch 'upstream/main'
mic-max Feb 3, 2022
be7743f
Merge remote-tracking branch 'upstream/main'
mic-max Feb 11, 2022
785cc23
Merge remote-tracking branch 'upstream/main'
mic-max Feb 18, 2022
bdccc53
Merge remote-tracking branch 'upstream/main'
mic-max Feb 22, 2022
d4b77e0
Merge remote-tracking branch 'upstream/main'
mic-max Feb 25, 2022
fd7ffd6
Merge remote-tracking branch 'upstream/main'
mic-max Mar 2, 2022
99a827f
Merge remote-tracking branch 'upstream/main'
mic-max Mar 8, 2022
84fc7c9
Merge remote-tracking branch 'upstream/main'
mic-max Mar 21, 2022
b440234
Merge remote-tracking branch 'upstream/main' into main
mic-max Mar 23, 2022
bd325b5
Merge remote-tracking branch 'upstream/main'
mic-max Apr 12, 2022
b3bdabf
Merge remote-tracking branch 'upstream/main' into main
mic-max Apr 14, 2022
b3000a1
Update Guard.cs
mic-max Apr 27, 2022
544d3fc
OTLP LogExporter to special case {OriginalFormat} to populate body (#…
cijothomas Apr 14, 2022
5e1bb7b
Public setter for MetricReaderOptions.PeriodicExportingMetricReaderOp…
alanwest Apr 15, 2022
47bf823
Prepare 1.2.0 stable release. (#3188)
cijothomas Apr 15, 2022
a8c0089
Update PreviousStableVersion to be 1.2.0 (#3189)
cijothomas Apr 15, 2022
6669cad
Remove net461 support from API and SDK (#3191)
cijothomas Apr 15, 2022
be8becd
Remove net461 from console inmemory exporters, asp.net (#3193)
cijothomas Apr 15, 2022
b0f25f4
Remove net461 from jaeger zipkin and otlp exporters (#3194)
cijothomas Apr 15, 2022
6767951
Remove net461 from Prometheus SQL SE HTTP Client (#3195)
cijothomas Apr 15, 2022
0e9c2d5
Add additional ThreadStatic storage to avoid allocation while sorting…
utpilla Apr 15, 2022
c3c3831
Bump minimum required version of Msft.Extensions.Logging to 3.1 (#3196)
cijothomas Apr 15, 2022
8f747f6
Docs minor tune (#3200)
reyang Apr 16, 2022
b73065d
update windows-ci-md (#3199)
TimothyMothra Apr 18, 2022
874f9fc
Remove 'release' badge (#3207)
reyang Apr 20, 2022
3541770
Update changelog for next release (#3197)
cijothomas Apr 20, 2022
06df7eb
ConsoleExporter Log minor cosmetic improvement. (#3211)
cijothomas Apr 20, 2022
6715b52
OTLP LogExporter to enable ParseStateValues by default (#3186)
cijothomas Apr 21, 2022
eccfa61
Fix changelog entry in wrong place (#3214)
cijothomas Apr 21, 2022
0080992
Remove NET5 from tests and CI (#3215)
cijothomas Apr 21, 2022
cb2b941
Console LogExporter to display Body (#3213)
cijothomas Apr 21, 2022
9880756
Bump codecov/codecov-action from 3.0.0 to 3.1.0 (#3216)
dependabot[bot] Apr 21, 2022
2f011be
OTLP LogExporter to support ILogger Scopes (#3218)
cijothomas Apr 21, 2022
2e06fe9
Remove net5.0 from JaegerExporter (#3220)
cijothomas Apr 22, 2022
adc8bdf
Exposed public setters for LogRecord.State, LogRecord.StateValues, …
Yun-Ting Apr 22, 2022
189bbac
Remove net5.0 from Zipkin and replace with net6.0 (#3222)
cijothomas Apr 22, 2022
b2a8dcb
Remove net461 from OpenTracing shim (#3224)
cijothomas Apr 22, 2022
45b5145
Remove net5.0 target from aspnet core instrumentation (#3223)
cijothomas Apr 22, 2022
721dd31
Add HTTP/Protobuf exporter for OTLP Logs (#3225)
cijothomas Apr 22, 2022
aefbda8
Remove NET5.0 target from OTLP Exporters (#3226)
cijothomas Apr 22, 2022
1c9fade
Cleanup .NET 5.0 (#3227)
cijothomas Apr 22, 2022
86e502e
Update main readme with project status (#3228)
cijothomas Apr 22, 2022
b2981ac
Bump github/codeql-action from 1 to 2 (#3230)
dependabot[bot] Apr 25, 2022
d6928a8
OTLP LogExporter to add LoggerCategory as attribute (#3221)
cijothomas Apr 26, 2022
e960f5a
reword
reyang Apr 27, 2022
4676bd3
Revert "reword" (#3233)
reyang Apr 27, 2022
beb3f36
Remove w3c check HttpClient (#3235)
vishweshbankwar Apr 28, 2022
6d52f87
Doc update to use 1.2.0 stable version. (#3242)
Yun-Ting May 2, 2022
9a847c2
Fix handling of OTLP ArrayValue attributes (#3238)
alanwest May 2, 2022
9572360
minor docs cleanup (#3246)
reyang May 2, 2022
60b8edc
histogram bucket linear/binary search depends on bonds count
mic-max May 4, 2022
e9d0428
Update CHANGELOG.md
mic-max May 4, 2022
ecc2e7b
Merge branch 'main' into binary-search-histograms
mic-max May 4, 2022
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
71 changes: 12 additions & 59 deletions build/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,24 @@

Only for Maintainers.

1. Decide the tag name (version name) to be released.
eg: 1.0.0-rc2, 1.0.0 etc.
1. Decide the tag name (version name) to be released.
eg: 1.0.0-rc2, 1.0.0 etc.

2. Run the following PowerShell from the root of the
repo to get combined changelog (to be used later).
1. Run the following PowerShell from the root of the
repo to get combined changelog (to be used later).

```powershell
$changelogs = Get-ChildItem -Path . -Recurse -Filter changelog.md
foreach ($changelog in $changelogs)
{
Add-Content -Path .\combinedchangelog.md -Value "**$($changelog.Directory.Name)**"
$lines = Get-Content -Path $changelog.FullName
$started = $false
$ended = $false
foreach ($line in $lines)
{
if($line -like "## Unreleased" -and $started -ne $true)
{
$started = $true
}
elseif($line -like "## *" -and $started -eq $true)
{
$ended = $true
break
}
else
{
if ($started -eq $true)
{
Add-Content -Path .\combinedchangelog.md $line
}
}
}
}
```
`./build/todo.ps1 1.0.0-rc2 | Set-Clipboard`

This generates combined changelog to be used in Github release.
Once contents of combined changelog is saved somewhere,
delete the file.

3. Run the following PowerShell script from the root of the repo.
This updates all the changelog to have release date for the
current version being released.
Replace the version with actual version.
The actual version would be the tag name from step1.

```powershell
$changelogs = Get-ChildItem -Path . -Recurse -Filter changelog.md
foreach ($changelog in $changelogs)
{
(Get-Content -Path $changelog.FullName) -replace "Unreleased", "Unreleased

## 1.0.0-rc2

Released $(Get-Date -UFormat '%Y-%b-%d')" | Set-Content -Path $changelog.FullName
}
```
Note: `git restore **/CHANGELOG.md` will undo changes to all CHANGELOG.md.

4. Normalize PublicApi files (Stable Release Only)
4. Normalize PublicApi files (Stable Release Only)
Run the PowerShell script `.\build\finalize-publicapi.ps1`.
This will merge the contents of Unshipped.txt into the Shipped.txt.

5. Submit PR with the above changes, and get it merged.
5. Submit PR with the above changes, and get it merged.

6. Tag Git with version to be released e.g.:
6. Tag Git with version to be released e.g.:

```sh
git tag -a 1.0.0-rc2 -m "1.0.0-rc2"
Expand All @@ -87,14 +40,14 @@ Only for Maintainers.

If releasing both, push both tags above.

7. Open [Pack and publish to MyGet
7. Open [Pack and publish to MyGet
workflow](https://github.com/open-telemetry/opentelemetry-dotnet/actions/workflows/publish-packages-1.0.yml)
and manually trigger a build. At the end of this, MyGet will have the
packages. The package name will be the tag name used in step 5.

8. Validate using MyGet packages. Basic sanity checks :)
8. Validate using MyGet packages. Basic sanity checks :)

9. From the above build, get the artifacts from the drop, which has all the
9. From the above build, get the artifacts from the drop, which has all the
NuGet packages.

10. Copy all the NuGet files and symbols into a local folder. If only
Expand Down
5 changes: 4 additions & 1 deletion src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

## Unreleased

* Use binary search for histograms with a large amount of buckets.
([#3251](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3251))

* Exposed public setters for `LogRecord.State`, `LogRecord.StateValues`,
and `LogRecord.FormattedMessage`.
([#3217](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3217))
([#3217](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3217))

## 1.3.0-beta.1

Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry/Metrics/Metric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public sealed class Metric
{
internal static readonly double[] DefaultHistogramBounds = new double[] { 0, 5, 10, 25, 50, 75, 100, 250, 500, 1000 };

internal static readonly int DefaultHistogramCountForBinarySearch = 140;

private readonly AggregatorStore aggStore;

internal Metric(
Expand Down
59 changes: 50 additions & 9 deletions src/OpenTelemetry/Metrics/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public struct MetricPoint

private readonly AggregationType aggType;

private readonly Func<double[], double, int> findHistogramBucketIndex;

private HistogramBuckets histogramBuckets;

// Represents temporality adjusted "value" for double/long metric types or "count" when histogram
Expand Down Expand Up @@ -61,6 +63,9 @@ internal MetricPoint(
if (this.aggType == AggregationType.Histogram)
{
this.histogramBuckets = new HistogramBuckets(histogramExplicitBounds);
this.findHistogramBucketIndex = histogramExplicitBounds.Length >= Metric.DefaultHistogramCountForBinarySearch
? FindHistogramBucketIndexBinary
: FindHistogramBucketIndexLinear;
}
else if (this.aggType == AggregationType.HistogramSumCount)
{
Expand Down Expand Up @@ -324,15 +329,9 @@ internal void Update(double number)

case AggregationType.Histogram:
{
int i;
for (i = 0; i < this.histogramBuckets.ExplicitBounds.Length; i++)
{
// Upper bound is inclusive
if (number <= this.histogramBuckets.ExplicitBounds[i])
{
break;
}
}
int i = double.IsNaN(number)
? this.histogramBuckets.ExplicitBounds.Length
: this.findHistogramBucketIndex(this.histogramBuckets.ExplicitBounds, number);

var sw = default(SpinWait);
while (true)
Expand Down Expand Up @@ -545,5 +544,47 @@ private readonly void ThrowNotSupportedMetricTypeException(string methodName)
{
throw new NotSupportedException($"{methodName} is not supported for this metric type.");
}

#pragma warning disable SA1204 // Static elements should appear before instance elements
private static int FindHistogramBucketIndexLinear(double[] bounds, double number)
#pragma warning restore SA1204 // Static elements should appear before instance elements
{
int i;

for (i = 0; i < bounds.Length; i++)
{
if (number <= bounds[i])
{
break;
}
}

return i;
}

private static int FindHistogramBucketIndexBinary(double[] bounds, double number)
{
var left = 0;
var right = bounds.Length - 1;

while (left <= right)
{
var mid = (int)Math.Floor((double)(left + right) / 2);
if (number == bounds[mid])
{
return mid;
}
else if (number > bounds[mid])
{
left = mid + 1;
}
else
{
right = mid - 1;
}
}

return right + 1;
}
}
}
4 changes: 2 additions & 2 deletions test/Benchmarks/Metrics/HistogramBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ namespace Benchmarks.Metrics
{
public class HistogramBenchmarks
{
private const int MaxValue = 1000;
private const int MaxValue = 10000;
private readonly Random random = new();
private readonly string[] dimensionValues = new string[] { "DimVal1", "DimVal2", "DimVal3", "DimVal4", "DimVal5", "DimVal6", "DimVal7", "DimVal8", "DimVal9", "DimVal10" };
private Histogram<long> histogram;
private MeterProvider provider;
private Meter meter;
private double[] bounds;

[Params(10, 20, 50, 100)]
[Params(10, 20, 50, 100, 200, 500, 1000)]
public int BoundCount { get; set; }

[GlobalSetup]
Expand Down