Skip to content

Commit

Permalink
Server call handler logger name shouldn't be service type name (#497) (
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored and jtattermusch committed Sep 9, 2019
1 parent 9cc68a7 commit 5458bc0
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ internal abstract class ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
{
private const string LoggerName = "Grpc.AspNetCore.Server.ServerCallHandler";

protected Method<TRequest, TResponse> Method { get; }
protected GrpcServiceOptions ServiceOptions { get; }
protected IGrpcServiceActivator<TService> ServiceActivator { get; }
Expand All @@ -49,7 +51,7 @@ protected ServerCallHandlerBase(
ServiceOptions = serviceOptions;
ServiceActivator = serviceActivator;
ServiceProvider = serviceProvider;
Logger = loggerFactory.CreateLogger(typeof(TService));
Logger = loggerFactory.CreateLogger(LoggerName);
}

public Task HandleCallAsync(HttpContext httpContext)
Expand Down
2 changes: 1 addition & 1 deletion test/FunctionalTests/Client/CancellationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private async Task CancelInParallel(int tasks, bool waitForHeaders, int interati
{
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER FunctionalTestsWebsite.Services.StreamService")
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName)
{
// Kestrel cancellation error message
if (writeContext.Exception is IOException &&
Expand Down
3 changes: 2 additions & 1 deletion test/FunctionalTests/Client/StreamingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Threading;
using System.Threading.Tasks;
using Google.Protobuf;
using Grpc.AspNetCore.FunctionalTests.Infrastructure;
using Grpc.Core;
using Grpc.Net.Client;
using Grpc.Tests.Shared;
Expand Down Expand Up @@ -368,7 +369,7 @@ writeContext.Exception is InvalidOperationException &&
return true;
}
if (writeContext.LoggerName == "SERVER FunctionalTestsWebsite.Services.StreamService")
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName)
{
return true;
}
Expand Down
25 changes: 25 additions & 0 deletions test/FunctionalTests/Infrastructure/TestConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#region Copyright notice and license

// Copyright 2019 The gRPC 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.

#endregion

namespace Grpc.AspNetCore.FunctionalTests.Infrastructure
{
internal static class TestConstants
{
public const string ServerCallHandlerTestName = "SERVER Grpc.AspNetCore.Server.ServerCallHandler";
}
}
8 changes: 4 additions & 4 deletions test/FunctionalTests/Server/ClientStreamingMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public async Task CompleteThenIncompleteMessage_ErrorResponse()
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER " + typeof(CounterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Internal' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "Incomplete message.")
{
return true;
}
if (writeContext.LoggerName == "SERVER " + typeof(CounterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorReadingMessage" &&
writeContext.State.ToString() == "Error reading message." &&
GetRpcExceptionDetail(writeContext.Exception) == "Incomplete message.")
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task ServerMethodReturnsNull_FailureResponse()

SetExpectedErrorsFilter(writeContext =>
{
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Cancelled' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "No message returned from method.";
Expand Down Expand Up @@ -246,7 +246,7 @@ async Task<CounterReply> AccumulateCount(IAsyncStreamReader<CounterRequest> requ
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName;
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName;
});

var method = Fixture.DynamicGrpc.AddClientStreamingMethod<CounterRequest, CounterReply>(AccumulateCount);
Expand Down
12 changes: 6 additions & 6 deletions test/FunctionalTests/Server/CompressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ public async Task SendCompressedMessageWithIdentity_ReturnInternalError()
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Internal' raised.")
{
return true;
}
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorReadingMessage" &&
writeContext.State.ToString() == "Error reading message.")
{
Expand Down Expand Up @@ -291,15 +291,15 @@ public async Task SendCompressedMessageWithUnsupportedEncoding_ReturnUnimplement
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Unimplemented' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "Unsupported grpc-encoding value 'DOES_NOT_EXIST'. Supported encodings: identity, gzip")
{
return true;
}
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorReadingMessage" &&
writeContext.State.ToString() == "Error reading message." &&
GetRpcExceptionDetail(writeContext.Exception) == "Unsupported grpc-encoding value 'DOES_NOT_EXIST'. Supported encodings: identity, gzip")
Expand Down Expand Up @@ -360,15 +360,15 @@ public async Task SendCompressedMessageWithoutEncodingHeader_ServerErrorResponse
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Internal' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "Request did not include grpc-encoding value with compressed message.")
{
return true;
}
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorReadingMessage" &&
writeContext.State.ToString() == "Error reading message." &&
GetRpcExceptionDetail(writeContext.Exception) == "Request did not include grpc-encoding value with compressed message.")
Expand Down
2 changes: 1 addition & 1 deletion test/FunctionalTests/Server/DeadlineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static async Task WriteUntilError(HelloRequest request, IServerStreamWriter<Hell
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorExecutingServiceMethod" &&
writeContext.State.ToString() == "Error when executing service method 'WriteUntilError'." &&
writeContext.Exception!.Message == "Cannot write message after request is complete.";
Expand Down
8 changes: 4 additions & 4 deletions test/FunctionalTests/Server/MaxMessageSizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public async Task ReceivedMessageExceedsSize_ThrowError()
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'ResourceExhausted' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "Received message exceeds the maximum configured message size.")
{
return true;
}
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorReadingMessage" &&
writeContext.State.ToString() == "Error reading message." &&
GetRpcExceptionDetail(writeContext.Exception) == "Received message exceeds the maximum configured message size.")
Expand Down Expand Up @@ -78,15 +78,15 @@ public async Task SentMessageExceedsSize_ThrowError()
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'ResourceExhausted' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "Sending message exceeds the maximum configured message size.")
{
return true;
}
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorSendingMessage" &&
writeContext.State.ToString() == "Error sending message." &&
GetRpcExceptionDetail(writeContext.Exception) == "Sending message exceeds the maximum configured message size.")
Expand Down
12 changes: 6 additions & 6 deletions test/FunctionalTests/Server/UnaryMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public async Task AdditionalDataAfterStreamedMessage_ErrorResponse()
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Internal' raised.")
{
return true;
}
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorReadingMessage" &&
writeContext.State.ToString() == "Error reading message.")
{
Expand Down Expand Up @@ -164,7 +164,7 @@ static async Task<HelloReply> ReturnHeadersTwice(HelloRequest request, ServerCal
// Arrange
SetExpectedErrorsFilter(writeContext =>
{
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorExecutingServiceMethod" &&
writeContext.State.ToString() == "Error when executing service method 'ReturnHeadersTwice'." &&
writeContext.Exception!.Message == "Response headers can only be sent once per call.";
Expand Down Expand Up @@ -200,7 +200,7 @@ public async Task ServerMethodReturnsNull_FailureResponse()

SetExpectedErrorsFilter(writeContext =>
{
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Cancelled' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "No message returned from method.";
Expand Down Expand Up @@ -239,7 +239,7 @@ public async Task ServerMethodThrowsExceptionWithTrailers_FailureResponse()

SetExpectedErrorsFilter(writeContext =>
{
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "RpcConnectionError" &&
writeContext.State.ToString() == "Error status code 'Unknown' raised." &&
GetRpcExceptionDetail(writeContext.Exception) == "User error";
Expand Down Expand Up @@ -316,7 +316,7 @@ static Task<Empty> ReturnContextInfoInTrailers(Empty request, ServerCallContext

SetExpectedErrorsFilter(writeContext =>
{
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
writeContext.EventId.Name == "ErrorExecutingServiceMethod";
});

Expand Down

0 comments on commit 5458bc0

Please sign in to comment.