Skip to content

Commit

Permalink
log send time in verbose heartbeat messages #6496. (#6548)
Browse files Browse the repository at this point in the history
  • Loading branch information
F0b0s authored Mar 23, 2023
1 parent 0f701e9 commit b07771a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
23 changes: 22 additions & 1 deletion src/core/Akka.Cluster.Tests/ClusterHeartbeatReceiverSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public ClusterHeartbeatReceiverLegacySpec(ITestOutputHelper output) : base(outpu
public abstract class ClusterHeartbeatReceiverBase : AkkaSpec
{
private static Config Config(bool useLegacyHeartbeat) => $@"
akka.loglevel=DEBUG
akka.cluster.debug.verbose-heartbeat-logging = on
akka.actor.provider = cluster
akka.cluster.use-legacy-heartbeat-message = {(useLegacyHeartbeat ? "true" : "false")}
";

protected ClusterHeartbeatReceiverBase(ITestOutputHelper output, bool useLegacyHeartbeat)
: base(Config(useLegacyHeartbeat), output)
{
Expand All @@ -49,5 +51,24 @@ public async Task ClusterHeartbeatReceiver_should_respond_to_heartbeats_with_sam
heartbeater.Tell(new Heartbeat(Cluster.Get(Sys).SelfAddress, 1, 2));
await ExpectMsgAsync<HeartbeatRsp>(new HeartbeatRsp(Cluster.Get(Sys).SelfUniqueAddress, 1, 2));
}

[Fact]
public async Task ClusterHeartbeatReceiver_should_write_correct_debug_messages_on_heartbeat()
{
var heartbeater = Sys.ActorOf(ClusterHeartbeatReceiver.Props(Cluster.Get(Sys)));

EventFilter.Debug(contains: "- Sequence number [2]")
.ExpectOne(() => heartbeater.Tell(new Heartbeat(Cluster.Get(Sys).SelfAddress, 2, 3)));
}

[Fact]
public async Task ClusterHeartbeatSender_should_write_correct_debug_messages_on_heartbeat_rsp()
{
var heartbeater = Sys.ActorOf(Props.Create(() => new ClusterHeartbeatSender(Cluster.Get(Sys))));
heartbeater.Tell(new ClusterEvent.CurrentClusterState());

EventFilter.Debug(contains: "- Sequence number [2] - Creation time [3]")
.ExpectOne(() => heartbeater.Tell(new HeartbeatRsp(Cluster.Get(Sys).SelfUniqueAddress, 2, 3)));
}
}
}
15 changes: 7 additions & 8 deletions src/core/Akka.Cluster/ClusterHeartbeat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using Akka.Actor;
using Akka.Event;
Expand Down Expand Up @@ -43,8 +44,7 @@ protected override void OnReceive(object message)
switch (message)
{
case ClusterHeartbeatSender.Heartbeat hb:
// TODO log the sequence nr once serializer is enabled
if(VerboseHeartbeat) _cluster.CurrentInfoLogger.LogDebug("Heartbeat from [{0}]", hb.From);
if (VerboseHeartbeat) _cluster.CurrentInfoLogger.LogDebug($"Heartbeat from [{hb.From}] - Sequence number [{hb.SequenceNr.ToString(CultureInfo.InvariantCulture)}]");
Sender.Tell(new ClusterHeartbeatSender.HeartbeatRsp(_cluster.SelfUniqueAddress,
hb.SequenceNr, hb.CreationTimeNanos));
break;
Expand All @@ -58,7 +58,6 @@ public static Props Props(Cluster getCluster)
{
return Akka.Actor.Props.Create(() => new ClusterHeartbeatReceiver(getCluster));
}

}

/// <summary>
Expand Down Expand Up @@ -248,7 +247,8 @@ private void CheckTickInterval()
"Previous heartbeat was sent [{1}] ms ago, expected interval is [{2}] ms. This may cause failure detection " +
"to mark members as unreachable. The reason can be thread starvation, e.g. by running blocking tasks on the " +
"default dispatcher, CPU overload, or GC.",
_cluster.SelfAddress, (now - _tickTimestamp).TotalMilliseconds, _cluster.Settings.HeartbeatInterval.TotalMilliseconds);
_cluster.SelfAddress, (now - _tickTimestamp).TotalMilliseconds.ToString(CultureInfo.InvariantCulture),
_cluster.Settings.HeartbeatInterval.TotalMilliseconds.ToString(CultureInfo.InvariantCulture));
}

_tickTimestamp = DateTime.UtcNow;
Expand All @@ -258,8 +258,8 @@ private void DoHeartbeatRsp(HeartbeatRsp rsp)
{
if (_cluster.Settings.VerboseHeartbeatLogging)
{
// TODO: log response time and validate sequence nrs once serialisation of sendTime is released
_log.Debug("Cluster Node [{0}] - Heartbeat response from [{1}]", _cluster.SelfAddress, rsp.From.Address);
_log.Debug("Cluster Node [{0}] - Heartbeat response from [{1}] - Sequence number [{2}] - Creation time [{3}]", _cluster.SelfAddress, rsp.From.Address,
rsp.SequenceNr.ToString(CultureInfo.InvariantCulture), rsp.CreationTimeNanos.ToString(CultureInfo.InvariantCulture));
}
_state = _state.HeartbeatRsp(rsp.From);
}
Expand Down Expand Up @@ -768,5 +768,4 @@ public int Compare(UniqueAddress x, UniqueAddress y)
}
#endregion
}
}

}

0 comments on commit b07771a

Please sign in to comment.