Skip to content

Commit

Permalink
Remove interfaces used for creating mock gRPC clients (#2831)
Browse files Browse the repository at this point in the history
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
  • Loading branch information
alanwest and cijothomas authored Feb 2, 2022
1 parent 1b8599b commit 840b24e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClie
/// <summary>Class for sending OTLP metrics export request over gRPC.</summary>
internal sealed class OtlpGrpcLogExportClient : BaseOtlpGrpcExportClient<OtlpCollector.ExportLogsServiceRequest>
{
private readonly OtlpCollector.LogsService.ILogsServiceClient logsClient;
private readonly OtlpCollector.LogsService.LogsServiceClient logsClient;

public OtlpGrpcLogExportClient(OtlpExporterOptions options, OtlpCollector.LogsService.ILogsServiceClient logsServiceClient = null)
public OtlpGrpcLogExportClient(OtlpExporterOptions options, OtlpCollector.LogsService.LogsServiceClient logsServiceClient = null)
: base(options)
{
if (logsServiceClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClie
/// <summary>Class for sending OTLP metrics export request over gRPC.</summary>
internal sealed class OtlpGrpcMetricsExportClient : BaseOtlpGrpcExportClient<OtlpCollector.ExportMetricsServiceRequest>
{
private readonly OtlpCollector.MetricsService.IMetricsServiceClient metricsClient;
private readonly OtlpCollector.MetricsService.MetricsServiceClient metricsClient;

public OtlpGrpcMetricsExportClient(OtlpExporterOptions options, OtlpCollector.MetricsService.IMetricsServiceClient metricsServiceClient = null)
public OtlpGrpcMetricsExportClient(OtlpExporterOptions options, OtlpCollector.MetricsService.MetricsServiceClient metricsServiceClient = null)
: base(options)
{
if (metricsServiceClient != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClie
/// <summary>Class for sending OTLP trace export request over gRPC.</summary>
internal sealed class OtlpGrpcTraceExportClient : BaseOtlpGrpcExportClient<OtlpCollector.ExportTraceServiceRequest>
{
private readonly OtlpCollector.TraceService.ITraceServiceClient traceClient;
private readonly OtlpCollector.TraceService.TraceServiceClient traceClient;

public OtlpGrpcTraceExportClient(OtlpExporterOptions options, OtlpCollector.TraceService.ITraceServiceClient traceServiceClient = null)
public OtlpGrpcTraceExportClient(OtlpExporterOptions options, OtlpCollector.TraceService.TraceServiceClient traceServiceClient = null)
: base(options)
{
if (traceServiceClient != null)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions test/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPkgVer)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingPkgVer)" />
<PackageReference Include="Moq" Version="$(MoqPkgVer)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
Expand Down
20 changes: 11 additions & 9 deletions test/Benchmarks/Exporter/OtlpGrpcExporterBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using BenchmarkDotNet.Attributes;
using Benchmarks.Helper;
using Grpc.Core;
using Moq;
using OpenTelemetry;
using OpenTelemetry.Internal;
using OpenTelemetryProtocol::OpenTelemetry.Exporter;
Expand All @@ -46,10 +47,19 @@ public class OtlpGrpcExporterBenchmarks
[GlobalSetup]
public void GlobalSetup()
{
var mockClient = new Mock<OtlpCollector.TraceService.TraceServiceClient>();
mockClient
.Setup(m => m.Export(
It.IsAny<OtlpCollector.ExportTraceServiceRequest>(),
It.IsAny<Metadata>(),
It.IsAny<DateTime?>(),
It.IsAny<CancellationToken>()))
.Returns(new OtlpCollector.ExportTraceServiceResponse());

var options = new OtlpExporterOptions();
this.exporter = new OtlpTraceExporter(
options,
new OtlpGrpcTraceExportClient(options, new NoopTraceServiceClient()));
new OtlpGrpcTraceExportClient(options, mockClient.Object));

this.activity = ActivityHelper.CreateTestActivity();
this.activityBatch = new CircularBuffer<Activity>(this.NumberOfSpans);
Expand All @@ -75,13 +85,5 @@ public void OtlpExporter_Batching()
this.exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans));
}
}

private class NoopTraceServiceClient : OtlpCollector.TraceService.ITraceServiceClient
{
public OtlpCollector.ExportTraceServiceResponse Export(OtlpCollector.ExportTraceServiceRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default)
{
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
Expand All @@ -27,7 +26,6 @@
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
using Xunit;
using GrpcCore = Grpc.Core;
using OtlpCollector = Opentelemetry.Proto.Collector.Trace.V1;
using OtlpCommon = Opentelemetry.Proto.Common.V1;
using OtlpTrace = Opentelemetry.Proto.Trace.V1;
Expand Down Expand Up @@ -423,13 +421,5 @@ public void Shutdown_ClientShutdownIsCalled()

exportClientMock.Verify(m => m.Shutdown(It.IsAny<int>()), Times.Once());
}

private class NoopTraceServiceClient : OtlpCollector.TraceService.ITraceServiceClient
{
public OtlpCollector.ExportTraceServiceResponse Export(OtlpCollector.ExportTraceServiceRequest request, GrpcCore.Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default)
{
return null;
}
}
}
}

0 comments on commit 840b24e

Please sign in to comment.