Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow logging deadletter response #1565

Merged
merged 4 commits into from
May 10, 2022
Merged
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
3 changes: 3 additions & 0 deletions src/Proto.Actor/Configuration/ActorSystemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public record ActorSystemConfig
/// The default timeout for RequestAsync calls
/// </summary>
public TimeSpan ActorRequestTimeout { get; init; } = TimeSpan.FromSeconds(5);
public bool DeadLetterResponseLogging { get; init; } = false;

/// <summary>
/// Creates a new default ActorSystemConfig
Expand Down Expand Up @@ -112,6 +113,8 @@ public ActorSystemConfig WithThreadPoolStatsTimeout(TimeSpan threadPoolStatsTime
public ActorSystemConfig WithDeveloperThreadPoolStatsLogging(bool enabled) => this with {DeveloperThreadPoolStatsLogging = enabled};

public ActorSystemConfig WithActorRequestTimeout(TimeSpan timeout) => this with {ActorRequestTimeout = timeout};

public ActorSystemConfig WithDeadLetterResponseLogging(bool enabled) => this with {DeadLetterResponseLogging = enabled};
}

//Not part of the contract, but still shipped out of the box
Expand Down
4 changes: 4 additions & 0 deletions src/Proto.Actor/Context/BatchContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public async Task<T> RequestAsync<T>(PID target, object message, CancellationTok
switch (result)
{
case DeadLetterResponse:
if (_context.System.Config.DeadLetterResponseLogging)
{
Logger.LogError("BatchContext {Self} got DeadLetterResponse for PID {Pid}", _context.Self , target);
}
throw new DeadLetterException(target);
case null:
case T:
Expand Down
6 changes: 6 additions & 0 deletions src/Proto.Actor/Context/ISenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Proto.Context;
using Proto.Future;

Expand Down Expand Up @@ -58,6 +59,7 @@ public interface ISenderContext : IInfoContext

public static class SenderContextExtensions
{
private static readonly ILogger Logger = Log.CreateLogger(nameof(SenderContextExtensions));
/// <summary>
/// Creates a batch context for sending a set of requests from the same thread context.
/// This is useful if you have several messages which shares a cancellation scope (same cancellationToken).
Expand Down Expand Up @@ -173,6 +175,10 @@ internal static async Task<T> RequestAsync<T>(this ISenderContext self, PID targ
switch (messageResult)
{
case DeadLetterResponse:
if (self.System.Config.DeadLetterResponseLogging)
{
Logger.LogError("Context {Self} got DeadLetterResponse for PID {Pid}", self.Self , target);
}
throw new DeadLetterException(target);
case null:
case T:
Expand Down
4 changes: 2 additions & 2 deletions src/Proto.Cluster/Gossip/GossipActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private Task OnGossipRequest(IContext context, GossipRequest gossipRequest)

context.RequestReenter<GossipResponseAck>(context.Sender!, new GossipResponse
{
State = memberState.State
State = memberState.State.Clone(), //ensure we have a copy and not state that might mutate
}, task => ReenterAfterResponseAck(context, task, memberState), context.CancellationToken
);

Expand Down Expand Up @@ -159,7 +159,7 @@ private void SendGossipForMember(IContext context, Member member, InstanceLogger
context.RequestReenter<object>(pid, new GossipRequest
{
MemberId = context.System.Id,
State = memberStateDelta.State
State = memberStateDelta.State.Clone(), //ensure we have a copy and not send state that might mutate
},
task => GossipReenterAfterSend(context, task, memberStateDelta),
CancellationTokens.WithTimeout(_gossipRequestTimeout)
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.Remote/Endpoints/ServerConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ await call.RequestStream.WriteAsync(new RemoteMessage
var sw = Stopwatch.StartNew();
await call.RequestStream.WriteAsync(message).ConfigureAwait(false);
sw.Stop();
RemoteMetrics.RemoteWriteDuration.Record(sw.ElapsedMilliseconds, _metricTags);
RemoteMetrics.RemoteWriteDuration.Record(sw.Elapsed.TotalSeconds, _metricTags);
}
else
{
Expand Down