Skip to content

Commit

Permalink
[AzureMonitorDistro] Fix livemetrics reporting incorrect values (#46429)
Browse files Browse the repository at this point in the history
* removing buffer capacity

* remove counter

* remove DocumentBuffer class

* changelog
  • Loading branch information
TimothyMothra authored Oct 11, 2024
1 parent 5ae1c69 commit 7ba92a4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* Fixed a bug in LiveMetrics that counted all manually created Dependencies as failures.
([#45103](https://github.com/Azure/azure-sdk-for-net/pull/45103))

* Fixed a bug in LiveMetrics that caused incorrect counts for telemetry.
([#46429](https://github.com/Azure/azure-sdk-for-net/pull/46429))

### Other Changes

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Concurrent;
using Azure.Monitor.OpenTelemetry.AspNetCore.Models;

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

public void WriteDocument(DocumentIngress document)
{
_currentBuffer.Add(document);
_currentBuffer.Enqueue(document);
}

public DocumentBuffer FlipDocumentBuffers()
public ConcurrentQueue<DocumentIngress> FlipDocumentBuffers()
{
// Atomically exchange the current buffer with a new empty buffer and return the old buffer
return Interlocked.Exchange(ref _currentBuffer, new DocumentBuffer());
return Interlocked.Exchange(ref _currentBuffer, new ConcurrentQueue<DocumentIngress>());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Concurrent;
using Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics;
using Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics.DataCollection;
using Azure.Monitor.OpenTelemetry.AspNetCore.LiveMetrics.Filtering;
Expand Down Expand Up @@ -45,9 +46,10 @@ public MonitoringDataPoint GetDataPoint()
string projectionError = string.Empty;
Dictionary<string, AccumulatedValues> metricAccumulators = CreateMetricAccumulators(_collectionConfiguration);
LiveMetricsBuffer liveMetricsBuffer = new();
DocumentBuffer filledBuffer = _documentBuffer.FlipDocumentBuffers();
IEnumerable<DocumentStream> documentStreams = _collectionConfiguration.DocumentStreams;
foreach (var item in filledBuffer.ReadAllAndClear())

ConcurrentQueue<DocumentIngress> filledBuffer = _documentBuffer.FlipDocumentBuffers();
while (filledBuffer.TryDequeue(out DocumentIngress? item))
{
bool matchesDocumentStreamFilter = false;

Expand Down

0 comments on commit 7ba92a4

Please sign in to comment.