Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bf8b6dd
WIP to update exmplar code.
CodeBlanch Feb 13, 2024
daf57cd
First compiling version.
CodeBlanch Feb 14, 2024
c23e7bf
Tweak.
CodeBlanch Feb 14, 2024
feb1c7e
Improvements.
CodeBlanch Feb 14, 2024
4e97f10
API updates.
CodeBlanch Feb 14, 2024
05e058a
Tweak.
CodeBlanch Feb 14, 2024
4542e83
Tweaks.
CodeBlanch Feb 14, 2024
82e6fa6
Better concurrency. Bug fixes.
CodeBlanch Feb 14, 2024
6b20ac3
Tweaks.
CodeBlanch Feb 14, 2024
4c849be
Tweaks.
CodeBlanch Feb 14, 2024
de1856a
Tweaks.
CodeBlanch Feb 14, 2024
ea58f75
Tweak.
CodeBlanch Feb 15, 2024
369738b
Tweak.
CodeBlanch Feb 15, 2024
645bb75
Merge from main.
CodeBlanch Feb 15, 2024
17cbe69
Cleanup.
CodeBlanch Feb 15, 2024
39230c9
Cleanup.
CodeBlanch Feb 15, 2024
7a8669c
Tweaks.
CodeBlanch Feb 15, 2024
65e87eb
CHANGELOG patch.
CodeBlanch Feb 15, 2024
aa0b3b5
Faster init for FixedSizeExemplarReservoir buffers.
CodeBlanch Feb 16, 2024
b21ba8d
Merge from main.
CodeBlanch Feb 16, 2024
ea2f149
Tweaks.
CodeBlanch Feb 16, 2024
ee7a978
Tweak.
CodeBlanch Feb 18, 2024
6ccfd4d
Tweaks.
CodeBlanch Feb 18, 2024
b2b327a
Tweak.
CodeBlanch Feb 18, 2024
04d56ca
Merge from main.
CodeBlanch Feb 20, 2024
a6011de
WIP
CodeBlanch Feb 20, 2024
015670a
Tweaks.
CodeBlanch Feb 21, 2024
fb521aa
Test improvements and tweaks.
CodeBlanch Feb 21, 2024
8bde052
Code review.
CodeBlanch Feb 21, 2024
c2c7f0a
Code review.
CodeBlanch Feb 21, 2024
0ffba7d
Code review.
CodeBlanch Feb 21, 2024
fb9b07a
Code review.
CodeBlanch Feb 21, 2024
4512b49
Merge remote-tracking branch 'upstream/main' into sdk-exemplar-spec-i…
CodeBlanch Feb 22, 2024
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
Prev Previous commit
Next Next commit
Tweaks.
  • Loading branch information
CodeBlanch committed Feb 14, 2024
commit 6b20ac378d1a59e118b9ec1a947dbeab091e2899
58 changes: 11 additions & 47 deletions src/OpenTelemetry/Metrics/AggregatorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal sealed class AggregatorStore
internal readonly int CardinalityLimit;
internal readonly bool EmitOverflowAttribute;
internal readonly ConcurrentDictionary<Tags, LookupData>? TagsToMetricPointIndexDictionaryDelta;
internal readonly ExemplarFilter ExemplarFilter;
internal long DroppedMeasurements = 0;

private static readonly string MetricPointCapHitFixMessage = "Consider opting in for the experimental SDK feature to emit all the throttled metrics under the overflow attribute by setting env variable OTEL_DOTNET_EXPERIMENTAL_METRICS_EMIT_OVERFLOW_ATTRIBUTE = true. You could also modify instrumentation to reduce the number of unique key/value pair combinations. Or use Views to drop unwanted tags. Or use MeterProviderBuilder.SetMaxMetricPointsPerMetricStream to set higher limit.";
Expand All @@ -43,7 +44,6 @@ internal sealed class AggregatorStore
private readonly int exponentialHistogramMaxScale;
private readonly UpdateLongDelegate updateLongCallback;
private readonly UpdateDoubleDelegate updateDoubleCallback;
private readonly ExemplarFilter exemplarFilter;
private readonly Func<KeyValuePair<string, object?>[], int, int> lookupAggregatorStore;

private int metricPointIndex = 0;
Expand Down Expand Up @@ -73,7 +73,7 @@ internal AggregatorStore(
this.exponentialHistogramMaxSize = metricStreamIdentity.ExponentialHistogramMaxSize;
this.exponentialHistogramMaxScale = metricStreamIdentity.ExponentialHistogramMaxScale;
this.StartTimeExclusive = DateTimeOffset.UtcNow;
this.exemplarFilter = exemplarFilter ?? DefaultExemplarFilter;
this.ExemplarFilter = exemplarFilter ?? DefaultExemplarFilter;
if (metricStreamIdentity.TagKeys == null)
{
this.updateLongCallback = this.UpdateLong;
Expand Down Expand Up @@ -141,7 +141,7 @@ internal bool IsExemplarEnabled()
{
// Using this filter to indicate On/Off
// instead of another separate flag.
return this.exemplarFilter is not AlwaysOffExemplarFilter;
return this.ExemplarFilter is not AlwaysOffExemplarFilter;
}

internal void Update(long value, ReadOnlySpan<KeyValuePair<string, object?>> tags)
Expand Down Expand Up @@ -931,7 +931,7 @@ private void UpdateLong(long value, ReadOnlySpan<KeyValuePair<string, object?>>
if (this.EmitOverflowAttribute)
{
this.InitializeOverflowTagPointIfNotInitialized();
this.metricPoints[1].Update(value);
this.metricPoints[1].Update(value, tags: default);
return;
}
else
Expand All @@ -945,16 +945,7 @@ private void UpdateLong(long value, ReadOnlySpan<KeyValuePair<string, object?>>
}
}

// TODO: can special case built-in filters to be bit faster.
if (this.IsExemplarEnabled()
&& this.exemplarFilter.ShouldSample(value, tags))
{
this.metricPoints[index].UpdateAndOfferExemplar(value, tags: default);
}
else
{
this.metricPoints[index].Update(value);
}
this.metricPoints[index].Update(value, tags: default);
}
catch (Exception)
{
Expand All @@ -975,7 +966,7 @@ private void UpdateLongCustomTags(long value, ReadOnlySpan<KeyValuePair<string,
if (this.EmitOverflowAttribute)
{
this.InitializeOverflowTagPointIfNotInitialized();
this.metricPoints[1].Update(value);
this.metricPoints[1].Update(value, tags);
return;
}
else
Expand All @@ -989,16 +980,7 @@ private void UpdateLongCustomTags(long value, ReadOnlySpan<KeyValuePair<string,
}
}

// TODO: can special case built-in filters to be bit faster.
if (this.IsExemplarEnabled()
&& this.exemplarFilter.ShouldSample(value, tags))
{
this.metricPoints[index].UpdateAndOfferExemplar(value, tags);
}
else
{
this.metricPoints[index].Update(value);
}
this.metricPoints[index].Update(value, tags);
}
catch (Exception)
{
Expand All @@ -1019,7 +1001,7 @@ private void UpdateDouble(double value, ReadOnlySpan<KeyValuePair<string, object
if (this.EmitOverflowAttribute)
{
this.InitializeOverflowTagPointIfNotInitialized();
this.metricPoints[1].Update(value);
this.metricPoints[1].Update(value, tags: default);
return;
}
else
Expand All @@ -1033,16 +1015,7 @@ private void UpdateDouble(double value, ReadOnlySpan<KeyValuePair<string, object
}
}

// TODO: can special case built-in filters to be bit faster.
if (this.IsExemplarEnabled()
&& this.exemplarFilter.ShouldSample(value, tags))
{
this.metricPoints[index].UpdateAndOfferExemplar(value, tags: default);
}
else
{
this.metricPoints[index].Update(value);
}
this.metricPoints[index].Update(value, tags: default);
}
catch (Exception)
{
Expand All @@ -1063,7 +1036,7 @@ private void UpdateDoubleCustomTags(double value, ReadOnlySpan<KeyValuePair<stri
if (this.EmitOverflowAttribute)
{
this.InitializeOverflowTagPointIfNotInitialized();
this.metricPoints[1].Update(value);
this.metricPoints[1].Update(value, tags);
return;
}
else
Expand All @@ -1077,16 +1050,7 @@ private void UpdateDoubleCustomTags(double value, ReadOnlySpan<KeyValuePair<stri
}
}

// TODO: can special case built-in filters to be bit faster.
if (this.IsExemplarEnabled()
&& this.exemplarFilter.ShouldSample(value, tags))
{
this.metricPoints[index].UpdateAndOfferExemplar(value, tags);
}
else
{
this.metricPoints[index].Update(value);
}
this.metricPoints[index].Update(value, tags);
}
catch (Exception)
{
Expand Down
34 changes: 13 additions & 21 deletions src/OpenTelemetry/Metrics/Exemplar/Exemplar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,13 @@ internal void Reset()

internal readonly bool IsUpdated()
{
if (this.Timestamp == default)
{
return false;
}

if (this.isCriticalSectionOccupied != 0)
{
this.WaitIfUpdatingRare();
this.WaitForUpdateToCompleteRare();
return true;
}

return true;
}

internal readonly void WaitIfUpdatingRare()
{
var spinWait = default(SpinWait);
while (true)
{
spinWait.SpinOnce();

if (this.isCriticalSectionOccupied == 0)
{
return;
}
}
return this.Timestamp != default;
}

internal readonly void Copy(ref Exemplar destination)
Expand Down Expand Up @@ -181,4 +163,14 @@ private void StoreRawTags(ReadOnlySpan<KeyValuePair<string, object?>> tags)

tags.CopyTo(this.tagStorage);
}

private readonly void WaitForUpdateToCompleteRare()
{
var spinWait = default(SpinWait);
do
{
spinWait.SpinOnce();
}
while (this.isCriticalSectionOccupied != 0);
}
}
Loading