Skip to content

Commit 7ba92a4

Browse files
author
Timothy Mothra
authored
[AzureMonitorDistro] Fix livemetrics reporting incorrect values (Azure#46429)
* removing buffer capacity * remove counter * remove DocumentBuffer class * changelog
1 parent 5ae1c69 commit 7ba92a4

File tree

4 files changed

+12
-50
lines changed

4 files changed

+12
-50
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
* Fixed a bug in LiveMetrics that counted all manually created Dependencies as failures.
2222
([#45103](https://github.com/Azure/azure-sdk-for-net/pull/45103))
2323

24+
* Fixed a bug in LiveMetrics that caused incorrect counts for telemetry.
25+
([#46429](https://github.com/Azure/azure-sdk-for-net/pull/46429))
26+
2427
### Other Changes
2528

2629
* Updated the code of vendored resource detector library `OpenTelemetry.Resources.Azure` from the OpenTelemetry .NET contrib repository.

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/LiveMetrics/DataCollection/DocumentBuffer.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/LiveMetrics/DataCollection/DoubleBuffer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Concurrent;
45
using Azure.Monitor.OpenTelemetry.AspNetCore.Models;
56

67
namespace Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics.DataCollection
@@ -14,17 +15,17 @@ namespace Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics.DataCollection
1415
/// </summary>
1516
internal class DoubleBuffer
1617
{
17-
private DocumentBuffer _currentBuffer = new();
18+
private ConcurrentQueue<DocumentIngress> _currentBuffer = new();
1819

1920
public void WriteDocument(DocumentIngress document)
2021
{
21-
_currentBuffer.Add(document);
22+
_currentBuffer.Enqueue(document);
2223
}
2324

24-
public DocumentBuffer FlipDocumentBuffers()
25+
public ConcurrentQueue<DocumentIngress> FlipDocumentBuffers()
2526
{
2627
// Atomically exchange the current buffer with a new empty buffer and return the old buffer
27-
return Interlocked.Exchange(ref _currentBuffer, new DocumentBuffer());
28+
return Interlocked.Exchange(ref _currentBuffer, new ConcurrentQueue<DocumentIngress>());
2829
}
2930
}
3031
}

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/LiveMetrics/Manager.Metrics.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Concurrent;
45
using Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics;
56
using Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics.DataCollection;
67
using Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics.Filtering;
@@ -45,9 +46,10 @@ public MonitoringDataPoint GetDataPoint()
4546
string projectionError = string.Empty;
4647
Dictionary<string, AccumulatedValues> metricAccumulators = CreateMetricAccumulators(_collectionConfiguration);
4748
LiveMetricsBuffer liveMetricsBuffer = new();
48-
DocumentBuffer filledBuffer = _documentBuffer.FlipDocumentBuffers();
4949
IEnumerable<DocumentStream> documentStreams = _collectionConfiguration.DocumentStreams;
50-
foreach (var item in filledBuffer.ReadAllAndClear())
50+
51+
ConcurrentQueue<DocumentIngress> filledBuffer = _documentBuffer.FlipDocumentBuffers();
52+
while (filledBuffer.TryDequeue(out DocumentIngress? item))
5153
{
5254
bool matchesDocumentStreamFilter = false;
5355

0 commit comments

Comments
 (0)