Skip to content

Commit

Permalink
Merge branch 'main' into reyang/prometheus-options
Browse files Browse the repository at this point in the history
  • Loading branch information
reyang authored Aug 2, 2022
2 parents 56d94c2 + a1cdb28 commit 454e0bf
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using System.Diagnostics.Tracing;
Expand Down Expand Up @@ -79,7 +80,8 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
},
};

DelegatingTestExporter<Activity> delegatingExporter = null;
DelegatingExporter<Activity> delegatingExporter = null;
var exportResults = new List<ExportResult>();

var activitySourceName = "otlp.collector.test";

Expand All @@ -93,7 +95,16 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
serviceProvider: null,
configureExporterInstance: otlpExporter =>
{
delegatingExporter = new DelegatingTestExporter<Activity>(otlpExporter, onExportAction: () => handle.Set());
delegatingExporter = new DelegatingExporter<Activity>
{
OnExportFunc = (batch) =>
{
var result = otlpExporter.Export(batch);
exportResults.Add(result);
handle.Set();
return result;
},
};
return delegatingExporter;
});

Expand All @@ -108,21 +119,21 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
if (forceFlush)
{
Assert.True(tracerProvider.ForceFlush());
Assert.Single(delegatingExporter.ExportResults);
Assert.Equal(ExportResult.Success, delegatingExporter.ExportResults[0]);
Assert.Single(exportResults);
Assert.Equal(ExportResult.Success, exportResults[0]);
}
else if (exporterOptions.ExportProcessorType == ExportProcessorType.Batch)
{
Assert.True(handle.WaitOne(ExportIntervalMilliseconds * 2));
Assert.Single(delegatingExporter.ExportResults);
Assert.Equal(ExportResult.Success, delegatingExporter.ExportResults[0]);
Assert.Single(exportResults);
Assert.Equal(ExportResult.Success, exportResults[0]);
}
}

if (!forceFlush && exportProcessorType == ExportProcessorType.Simple)
{
Assert.Single(delegatingExporter.ExportResults);
Assert.Equal(ExportResult.Success, delegatingExporter.ExportResults[0]);
Assert.Single(exportResults);
Assert.Equal(ExportResult.Success, exportResults[0]);
}
}

Expand Down Expand Up @@ -155,7 +166,8 @@ public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endp
Protocol = protocol,
};

DelegatingTestExporter<Metric> delegatingExporter = null;
DelegatingExporter<Metric> delegatingExporter = null;
var exportResults = new List<ExportResult>();

var meterName = "otlp.collector.test";

Expand All @@ -174,7 +186,16 @@ public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endp
serviceProvider: null,
configureExporterInstance: otlpExporter =>
{
delegatingExporter = new DelegatingTestExporter<Metric>(otlpExporter, onExportAction: () => handle.Set());
delegatingExporter = new DelegatingExporter<Metric>
{
OnExportFunc = (batch) =>
{
var result = otlpExporter.Export(batch);
exportResults.Add(result);
handle.Set();
return result;
},
};
return delegatingExporter;
});

Expand All @@ -191,21 +212,21 @@ public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endp
if (forceFlush)
{
Assert.True(meterProvider.ForceFlush());
Assert.Single(delegatingExporter.ExportResults);
Assert.Equal(ExportResult.Success, delegatingExporter.ExportResults[0]);
Assert.Single(exportResults);
Assert.Equal(ExportResult.Success, exportResults[0]);
}
else if (!useManualExport)
{
Assert.True(handle.WaitOne(ExportIntervalMilliseconds * 2));
Assert.Single(delegatingExporter.ExportResults);
Assert.Equal(ExportResult.Success, delegatingExporter.ExportResults[0]);
Assert.Single(exportResults);
Assert.Equal(ExportResult.Success, exportResults[0]);
}
}

if (!forceFlush && useManualExport)
{
Assert.Single(delegatingExporter.ExportResults);
Assert.Equal(ExportResult.Success, delegatingExporter.ExportResults[0]);
Assert.Single(exportResults);
Assert.Equal(ExportResult.Success, exportResults[0]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\DelegatingTestExporter.cs" Link="Includes\DelegatingTestExporter.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\DelegatingExporter.cs" Link="Includes\DelegatingExporter.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\EventSourceTestHelper.cs" Link="Includes\EventSourceTestHelper.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\SkipUnlessEnvVarFoundTheoryAttribute.cs" Link="Includes\SkipUnlessEnvVarFoundTheoryAttribute.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\SkipUnlessEnvVarFoundFactAttribute.cs" Link="Includes\SkipUnlessEnvVarFoundFactAttribute.cs" />
Expand Down
27 changes: 27 additions & 0 deletions test/OpenTelemetry.Tests/Shared/DelegatingExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// <copyright file="DelegatingExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;

namespace OpenTelemetry.Tests;

internal sealed class DelegatingExporter<T> : BaseExporter<T>
where T : class
{
public Func<Batch<T>, ExportResult> OnExportFunc { get; set; } = (batch) => default;

public override ExportResult Export(in Batch<T> batch) => this.OnExportFunc(batch);
}
46 changes: 0 additions & 46 deletions test/OpenTelemetry.Tests/Shared/DelegatingTestExporter.cs

This file was deleted.

0 comments on commit 454e0bf

Please sign in to comment.