Skip to content

Commit

Permalink
Merge branch 'main' into prometheus-thread-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Nov 15, 2021
2 parents 33b341e + 770a367 commit f94bc5f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/OpenTelemetry/BatchExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ protected override bool OnForceFlush(int timeoutMilliseconds)

var triggers = new WaitHandle[] { this.dataExportedNotification, this.shutdownTrigger };

var sw = Stopwatch.StartNew();
var sw = timeoutMilliseconds == Timeout.Infinite
? null
: Stopwatch.StartNew();

// There is a chance that the export thread finished processing all the data from the queue,
// and signaled before we enter wait here, use polling to prevent being blocked indefinitely.
const int pollingMilliseconds = 1000;

while (true)
{
if (timeoutMilliseconds == Timeout.Infinite)
if (sw == null)
{
try
{
Expand Down
12 changes: 8 additions & 4 deletions src/OpenTelemetry/CompositeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ public override void OnStart(T data)
protected override bool OnForceFlush(int timeoutMilliseconds)
{
var result = true;
var sw = Stopwatch.StartNew();
var sw = timeoutMilliseconds == Timeout.Infinite
? null
: Stopwatch.StartNew();

for (var cur = this.head; cur != null; cur = cur.Next)
{
if (timeoutMilliseconds == Timeout.Infinite)
if (sw == null)
{
result = cur.Value.ForceFlush(Timeout.Infinite) && result;
}
Expand All @@ -107,11 +109,13 @@ protected override bool OnForceFlush(int timeoutMilliseconds)
protected override bool OnShutdown(int timeoutMilliseconds)
{
var result = true;
var sw = Stopwatch.StartNew();
var sw = timeoutMilliseconds == Timeout.Infinite
? null
: Stopwatch.StartNew();

for (var cur = this.head; cur != null; cur = cur.Next)
{
if (timeoutMilliseconds == Timeout.Infinite)
if (sw == null)
{
result = cur.Value.Shutdown(Timeout.Infinite) && result;
}
Expand Down
12 changes: 8 additions & 4 deletions src/OpenTelemetry/Metrics/CompositeMetricReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ protected override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMill
protected override bool OnCollect(int timeoutMilliseconds = Timeout.Infinite)
{
var result = true;
var sw = Stopwatch.StartNew();
var sw = timeoutMilliseconds == Timeout.Infinite
? null
: Stopwatch.StartNew();

for (var cur = this.head; cur != null; cur = cur.Next)
{
if (timeoutMilliseconds == Timeout.Infinite)
if (sw == null)
{
result = cur.Value.Collect(Timeout.Infinite) && result;
}
Expand All @@ -99,11 +101,13 @@ protected override bool OnCollect(int timeoutMilliseconds = Timeout.Infinite)
protected override bool OnShutdown(int timeoutMilliseconds)
{
var result = true;
var sw = Stopwatch.StartNew();
var sw = timeoutMilliseconds == Timeout.Infinite
? null
: Stopwatch.StartNew();

for (var cur = this.head; cur != null; cur = cur.Next)
{
if (timeoutMilliseconds == Timeout.Infinite)
if (sw == null)
{
result = cur.Value.Shutdown(Timeout.Infinite) && result;
}
Expand Down
6 changes: 4 additions & 2 deletions src/OpenTelemetry/Metrics/MetricReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ internal virtual void SetParentProvider(BaseProvider parentProvider)
/// </remarks>
protected virtual bool OnCollect(int timeoutMilliseconds)
{
var sw = Stopwatch.StartNew();
var sw = timeoutMilliseconds == Timeout.Infinite
? null
: Stopwatch.StartNew();

var collectMetric = this.ParentProvider.GetMetricCollect();
var metrics = collectMetric();

if (timeoutMilliseconds == Timeout.Infinite)
if (sw == null)
{
return this.ProcessMetrics(metrics, Timeout.Infinite);
}
Expand Down

0 comments on commit f94bc5f

Please sign in to comment.