Remove interfaces used for creating mock gRPC clients (#2831)

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
Alan West 2022-02-02 12:11:49 -08:00 committed by GitHub
parent 1b8599b115
commit 840b24e85f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 175 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -1,50 +0,0 @@
// <copyright file="LogsService.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;
using System.Threading;
using Grpc.Core;
namespace Opentelemetry.Proto.Collector.Logs.V1
{
/// <summary>
/// LogService extensions.
/// </summary>
internal static partial class LogsService
{
/// <summary>Interface for LogService.</summary>
public interface ILogsServiceClient
{
/// <summary>
/// For performance reasons, it is recommended to keep this RPC
/// alive for the entire life of the application.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
/// <param name="cancellationToken">An optional token for canceling the call.</param>
/// <returns>The response received from the server.</returns>
ExportLogsServiceResponse Export(ExportLogsServiceRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default);
}
/// <summary>
/// LogsServiceClient extensions.
/// </summary>
public partial class LogsServiceClient : ILogsServiceClient
{
}
}
}

View File

@ -1,50 +0,0 @@
// <copyright file="MetricsService.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;
using System.Threading;
using Grpc.Core;
namespace Opentelemetry.Proto.Collector.Metrics.V1
{
/// <summary>
/// MetricsService extensions.
/// </summary>
internal static partial class MetricsService
{
/// <summary>Interface for MetricService.</summary>
public interface IMetricsServiceClient
{
/// <summary>
/// For performance reasons, it is recommended to keep this RPC
/// alive for the entire life of the application.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
/// <param name="cancellationToken">An optional token for canceling the call.</param>
/// <returns>The response received from the server.</returns>
ExportMetricsServiceResponse Export(ExportMetricsServiceRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default);
}
/// <summary>
/// MetricServiceClient extensions.
/// </summary>
public partial class MetricsServiceClient : IMetricsServiceClient
{
}
}
}

View File

@ -1,50 +0,0 @@
// <copyright file="TraceService.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;
using System.Threading;
using Grpc.Core;
namespace Opentelemetry.Proto.Collector.Trace.V1
{
/// <summary>
/// TraceService extensions.
/// </summary>
internal static partial class TraceService
{
/// <summary>Interface for TraceService.</summary>
public interface ITraceServiceClient
{
/// <summary>
/// For performance reasons, it is recommended to keep this RPC
/// alive for the entire life of the application.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
/// <param name="cancellationToken">An optional token for canceling the call.</param>
/// <returns>The response received from the server.</returns>
ExportTraceServiceResponse Export(ExportTraceServiceRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default);
}
/// <summary>
/// TraceServiceClient extensions.
/// </summary>
public partial class TraceServiceClient : ITraceServiceClient
{
}
}
}

View File

@ -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'">

View File

@ -22,6 +22,7 @@ using System.Threading;
using BenchmarkDotNet.Attributes;
using Benchmarks.Helper;
using Grpc.Core;
using Moq;
using OpenTelemetry;
using OpenTelemetry.Internal;
using OpenTelemetryProtocol::OpenTelemetry.Exporter;
@ -46,10 +47,19 @@ namespace Benchmarks.Exporter
[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);
@ -75,13 +85,5 @@ namespace Benchmarks.Exporter
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;
}
}
}
}

View File

@ -18,7 +18,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
@ -27,7 +26,6 @@ using OpenTelemetry.Resources;
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;
@ -423,13 +421,5 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
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;
}
}
}
}