Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions src/WebJobs.Script.Grpc/Channel/WorkerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private async Task ProcessInbound()
{
while (_inbound.TryRead(out var msg))
{
if (debug && msg.ContentCase != MsgType.RpcLog)
if (msg.ContentCase != MsgType.RpcLog)
{
Logger.ChannelReceivedMessage(_workerChannelLogger, _workerId, msg.ContentCase);
}
Expand Down Expand Up @@ -2018,28 +2018,16 @@ private void OnTimeout()
}

// EventId range is 800-899
private static class Logger
private static partial class Logger
{
private static readonly Action<ILogger, string, MsgType, Exception> _channelReceivedMessage = LoggerMessage.Define<string, MsgType>(
LogLevel.Debug,
new EventId(820, nameof(ChannelReceivedMessage)),
"[channel] received {workerId}: {msgType}");
[LoggerMessage(820, LogLevel.Trace, "[channel] received {workerId}: {msgType}")]
internal static partial void ChannelReceivedMessage(ILogger logger, string workerId, ContentOneofCase msgType);

private static readonly Action<ILogger, string, Exception> _invocationResponseReceived = LoggerMessage.Define<string>(
LogLevel.Debug,
new EventId(821, nameof(InvocationResponseReceived)),
"InvocationResponse received for invocation: '{invocationId}'");
[LoggerMessage(821, LogLevel.Trace, "InvocationResponse received for invocation: '{invocationId}'")]
internal static partial void InvocationResponseReceived(ILogger logger, string invocationId);

private static readonly Action<ILogger, string, Exception> _failedToRegisterAppCapabilities = LoggerMessage.Define<string>(
LogLevel.Warning,
new EventId(822, nameof(FailedToRegisterAppCapabilities)),
"Failed to register app capabilities from worker '{workerId}'");

internal static void ChannelReceivedMessage(ILogger logger, string workerId, ContentOneofCase msgType) => _channelReceivedMessage(logger, workerId, msgType, null);

internal static void InvocationResponseReceived(ILogger logger, string invocationId) => _invocationResponseReceived(logger, invocationId, null);

internal static void FailedToRegisterAppCapabilities(ILogger logger, Exception ex, string workerId) => _failedToRegisterAppCapabilities(logger, workerId, ex);
[LoggerMessage(822, LogLevel.Warning, "Failed to register app capabilities from worker '{workerId}'")]
internal static partial void FailedToRegisterAppCapabilities(ILogger logger, Exception ex, string workerId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1374,9 +1374,21 @@ public async Task ReceivesInboundEvent_InvocationResponse()

var expectedLog = "InvocationResponse received for invocation: 'TestInvocationId'";
await TestHelpers.Await(
() => _logger.GetLogMessages().Any(m => string.Equals(m.FormattedMessage, expectedLog)),
() => _logger.GetLogMessages().Any(m => string.Equals(m.FormattedMessage, expectedLog, StringComparison.Ordinal)),
timeout: 3000,
pollingInterval: 50);

var traces = _logger.GetLogMessages();
var invocationResponseLog = Assert.Single(traces, m => string.Equals(m.FormattedMessage, expectedLog, StringComparison.Ordinal));
Assert.Equal(LogLevel.Trace, invocationResponseLog.Level);
Assert.Equal(821, invocationResponseLog.EventId.Id);
Assert.Equal("InvocationResponseReceived", invocationResponseLog.EventId.Name);

var channelReceivedLog = Assert.Single(traces, m => string.Equals(
m.FormattedMessage, $"[channel] received {_workerId}: InvocationResponse", StringComparison.Ordinal));
Assert.Equal(LogLevel.Trace, channelReceivedLog.Level);
Assert.Equal(820, channelReceivedLog.EventId.Id);
Assert.Equal("ChannelReceivedMessage", channelReceivedLog.EventId.Name);
}

[Fact]
Expand All @@ -1398,6 +1410,9 @@ await TestHelpers.Await(
var traces = _logger.GetLogMessages();
ShowOutput(traces);

Assert.Contains(traces, m => m.Level == LogLevel.Trace && string.Equals(
m.FormattedMessage, $"[channel] received {_workerId}: FunctionLoadResponse", StringComparison.Ordinal));

Assert.True(traces.Any(m => string.Equals(m.FormattedMessage, "Setting up FunctionInvocationBuffer for function: 'js1' with functionId: 'TestFunctionId1'")), "FunctionInvocationBuffer TestFunctionId1");
Assert.True(traces.Any(m => string.Equals(m.FormattedMessage, "Setting up FunctionInvocationBuffer for function: 'js2' with functionId: 'TestFunctionId2'")), "FunctionInvocationBuffer TestFunctionId2");
Assert.True(traces.Any(m => string.Equals(m.FormattedMessage, expectedLog)), "FunctionLoadResponse TestFunctionId1");
Expand Down
Loading