Skip to content

Commit

Permalink
Change default logging setting to non-verbose (#209)
Browse files Browse the repository at this point in the history
* Change default logging setting to non-verbose

* Downgrade log levels

* Update unit tests

* Fix logging infratructure and downgrade log levels
  • Loading branch information
Arkatufus authored Mar 16, 2023
1 parent b5189a9 commit c42639f
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void ReadinessStatusCluster_Should_Tell_Subscribers_When_It_Becomes_Avail

// step2 - create probe

var probe = Sys.ActorOf(Props.Create(() => new ClusterReadinessProbe()));
var probe = Sys.ActorOf(Props.Create(() => new ClusterReadinessProbe(true)));
probe.Tell(new SubscribeToReadiness(TestActor));

// step3 - wait for ready status
Expand All @@ -58,7 +58,7 @@ public void ReadinessStatusCluster_Should_Tell_Subscribers_When_It_Leaves_Cluste

// step2 - create probe

var probe = Sys.ActorOf(Props.Create(() => new ClusterReadinessProbe()));
var probe = Sys.ActorOf(Props.Create(() => new ClusterReadinessProbe(true)));
probe.Tell(new SubscribeToReadiness(TestActor));

// step3 - wait for ready status
Expand Down
6 changes: 4 additions & 2 deletions src/Akka.HealthCheck.Cluster/ClusterLivenessProbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ public sealed class ClusterLivenessProbe : ReceiveActor
private readonly Akka.Cluster.Cluster _cluster = Akka.Cluster.Cluster.Get(Context.System);
private readonly ILoggingAdapter _log = Context.GetLogger();
private readonly HashSet<IActorRef> _subscribers = new HashSet<IActorRef>();
private readonly bool _logInfo;

private LivenessStatus _livenessStatus;

public ClusterLivenessProbe() : this(DefaultClusterLivenessStatus)
public ClusterLivenessProbe(bool logInfo) : this(logInfo, DefaultClusterLivenessStatus)
{
}

public ClusterLivenessProbe(LivenessStatus livenessStatus)
public ClusterLivenessProbe(bool logInfo, LivenessStatus livenessStatus)
{
_logInfo = logInfo;
_livenessStatus = livenessStatus;

Receive<LivenessStatus>(s =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public ClusterLivenessProbeProvider(ActorSystem system) : base(system)
{
}

public override Props ProbeProps => Props.Create(() => new ClusterLivenessProbe());
public override Props ProbeProps => Props.Create(() => new ClusterLivenessProbe(Settings.LogInfoEvents));
}
}
8 changes: 5 additions & 3 deletions src/Akka.HealthCheck.Cluster/ClusterReadinessProbeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ClusterReadinessProbeProvider(ActorSystem system) : base(system)
{
}

public override Props ProbeProps => Props.Create(() => new ClusterReadinessProbe());
public override Props ProbeProps => Props.Create(() => new ClusterReadinessProbe(Settings.LogInfoEvents));
}

/// <summary>
Expand All @@ -39,15 +39,17 @@ public sealed class ClusterReadinessProbe : ReceiveActor
private readonly Akka.Cluster.Cluster _cluster = Akka.Cluster.Cluster.Get(Context.System);
private readonly ILoggingAdapter _log = Context.GetLogger();
private readonly HashSet<IActorRef> _subscribers = new HashSet<IActorRef>();
private readonly bool _logInfo;
private ICancelable? _notReadyTask;
private ReadinessStatus _readinessStatus;

public ClusterReadinessProbe() : this(DefaultClusterReadinessStatus)
public ClusterReadinessProbe(bool logInfo) : this(logInfo, DefaultClusterReadinessStatus)
{
}

public ClusterReadinessProbe(ReadinessStatus readinessStatus)
public ClusterReadinessProbe(bool logInfo, ReadinessStatus readinessStatus)
{
_logInfo = logInfo;
_readinessStatus = readinessStatus;

Receive<ReadinessStatus>(s =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AkkaPersistenceLivenessProbeNotAvailableDueToSnapshotStoreSpecs(ITestOutp
public void AkkaPersistenceLivenessProbeProvidert_Should_Report_Akka_Persistance_Is_Unavailable_With_Bad_Snapshot_Store_Setup()
{

var ProbActor = Sys.ActorOf(Props.Create(() => new AkkaPersistenceLivenessProbe(TimeSpan.FromMilliseconds(250))));
var ProbActor = Sys.ActorOf(Props.Create(() => new AkkaPersistenceLivenessProbe(true, TimeSpan.FromMilliseconds(250))));
ProbActor.Tell(new SubscribeToLiveness(TestActor));
ExpectMsg<LivenessStatus>().IsLive.Should().BeFalse("System should not be live");
ExpectMsg<LivenessStatus>(TimeSpan.FromMinutes(1)).IsLive.Should().BeFalse("System should not be live");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AkkaPersistenceLivenessProbeNotAvailableDueToJournalSpecs(ITestOutputHelp
public void AkkaPersistenceLivenessProbeProvidert_Should_Report_Akka_Persistance_Is_Unavailable_With_Bad_Journal_Setup()
{

var ProbActor = Sys.ActorOf(Props.Create(() => new AkkaPersistenceLivenessProbe(TimeSpan.FromMilliseconds(250))));
var ProbActor = Sys.ActorOf(Props.Create(() => new AkkaPersistenceLivenessProbe(true, TimeSpan.FromMilliseconds(250))));
ProbActor.Tell(new SubscribeToLiveness(TestActor));
ExpectMsg<LivenessStatus>().IsLive.Should().BeFalse("System should not be live");
ExpectMsg<LivenessStatus>(TimeSpan.FromMinutes(1)).IsLive.Should().BeFalse("System should not be live");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AkkaPersistenceLivenessProbeSubscriptionTest(ITestOutputHelper helper)
[Fact(DisplayName = "AkkaPersistenceLivenessProbe should correctly handle subscription requests")]
public void AkkaPersistenceLivenessProbe_Should_Handle_Subscriptions_In_Any_State()
{
var ProbActor = Sys.ActorOf(Props.Create(() => new AkkaPersistenceLivenessProbe(TimeSpan.FromMilliseconds(250))));
var ProbActor = Sys.ActorOf(Props.Create(() => new AkkaPersistenceLivenessProbe(true, TimeSpan.FromMilliseconds(250))));
ProbActor.Tell(new SubscribeToLiveness(TestActor));
ExpectMsg<LivenessStatus>().IsLive.Should().BeFalse();
AwaitAssert(() => ExpectMsg<LivenessStatus>().IsLive.Should().BeTrue(),TimeSpan.FromSeconds(10));
Expand Down
19 changes: 12 additions & 7 deletions src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,23 @@ public class AkkaPersistenceLivenessProbe : ActorBase
private readonly TimeSpan _delay;
private readonly string _id;
private readonly Cancelable _shutdownCancellable;
private readonly bool _logInfo;

public AkkaPersistenceLivenessProbe(TimeSpan delay)
public AkkaPersistenceLivenessProbe(bool logInfo, TimeSpan delay)
{
_delay = delay;
_id = Guid.NewGuid().ToString("N");
_shutdownCancellable = new Cancelable(Context.System.Scheduler);
_logInfo = logInfo;
}
public AkkaPersistenceLivenessProbe() : this(TimeSpan.FromSeconds(10))
public AkkaPersistenceLivenessProbe(bool logInfo) : this(logInfo, TimeSpan.FromSeconds(10))
{
}

public static Props PersistentHealthCheckProps()
public static Props PersistentHealthCheckProps(bool logInfo)
{
// need to use the stopping strategy in case things blow up right away
return Props.Create(() => new AkkaPersistenceLivenessProbe())
return Props.Create(() => new AkkaPersistenceLivenessProbe(logInfo))
.WithSupervisorStrategy(Actor.SupervisorStrategy.StoppingStrategy);
}

Expand Down Expand Up @@ -134,7 +136,8 @@ private bool Started(object message)
{
case Terminated t when t.ActorRef.Equals(_probe):
Context.Unwatch(_probe);
_log.Info("Persistence probe terminated. Recreating...");
if(_logInfo)
_log.Debug("Persistence probe terminated. Recreating...");
CreateProbe();
Become(obj => Recreating(obj) || HandleSubscriptions(obj));
return true;
Expand All @@ -148,7 +151,8 @@ private bool Started(object message)

private void HandleRecoveryStatus(PersistenceLivenessStatus livenessStatus)
{
_log.Info("Received recovery status {0} from probe.", livenessStatus);
if(_logInfo)
_log.Debug("Received recovery status {0} from probe.", livenessStatus);
_currentLivenessStatus = livenessStatus;
PublishStatusUpdates();
}
Expand All @@ -159,7 +163,8 @@ private bool Recreating(object message)
{
case Terminated t when t.ActorRef.Equals(_probe):
Context.Unwatch(_probe);
_log.Debug("Persistence probe terminated. Recreating...");
if(_logInfo)
_log.Debug("Persistence probe terminated. Recreating...");
CreateProbe();
return true;
case PersistenceLivenessStatus status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public AkkaPersistenceLivenessProbeProvider(ActorSystem system) : base(system)
{
}

public override Props ProbeProps => AkkaPersistenceLivenessProbe.PersistentHealthCheckProps();
public override Props ProbeProps => AkkaPersistenceLivenessProbe.PersistentHealthCheckProps(Settings.LogInfoEvents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ public void Should_load_default_HealthCheck_Settings()
settings.ReadinessTransport.Should().Be(ProbeTransport.Custom);
settings.LivenessTransportSettings.Should().BeOfType<CustomTransportSettings>();
settings.ReadinessTransportSettings.Should().BeOfType<CustomTransportSettings>();
settings.LogConfigOnStart.Should().BeTrue();
settings.LogInfoEvents.Should().BeTrue();
settings.LogConfigOnStart.Should().BeFalse();
settings.LogInfoEvents.Should().BeFalse();
}

[Fact(DisplayName = "Should be able load non-default log options")]
public void Should_load_non_default_Log_Settings()
{
var hocon = ConfigurationFactory.ParseString(@"
akka.healthcheck{
log-config-on-start = off
log-info = off
log-config-on-start = on
log-info = on
}");

var settings = new HealthCheckSettings(hocon.WithFallback(HealthCheckSettings.DefaultConfig())
.GetConfig("akka.healthcheck"));
settings.LogConfigOnStart.Should().BeFalse();
settings.LogInfoEvents.Should().BeFalse();
settings.LogConfigOnStart.Should().BeTrue();
settings.LogInfoEvents.Should().BeTrue();
}

[Fact(DisplayName = "HealthCheckSettings should load non-default transport values")]
Expand Down
4 changes: 2 additions & 2 deletions src/Akka.HealthCheck/Configuration/akka.healthcheck.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
akka.healthcheck{
# Log the complete configuration at INFO level when the actor system is started.
# This is useful when you are uncertain of what configuration is used.
log-config-on-start = on
log-config-on-start = off

# Log Liveness and Readiness probe event messages
# Such as Liveness/Readiness subscriptions, and status request
log-info = on
log-info = off

liveness {
# List of liveness probe providers.
Expand Down
4 changes: 4 additions & 0 deletions src/Akka.HealthCheck/ProbeProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// -----------------------------------------------------------------------

using Akka.Actor;
using Akka.HealthCheck.Configuration;

namespace Akka.HealthCheck
{
Expand All @@ -16,6 +17,8 @@ namespace Akka.HealthCheck
/// </summary>
public abstract class ProbeProviderBase : IProbeProvider
{
protected HealthCheckSettings Settings { get; }

/// <summary>
/// Constructor takes the <see cref="ActorSystem" /> on which this
/// healthcheck will run as a current argument. Designed to allow
Expand All @@ -25,6 +28,7 @@ public abstract class ProbeProviderBase : IProbeProvider
/// <param name="system">The current actor system.</param>
protected ProbeProviderBase(ActorSystem system)
{
Settings = new HealthCheckSettings(system);
}

/// <inheritdoc cref="IProbeProvider.ProbeProps" />
Expand Down
6 changes: 3 additions & 3 deletions src/Akka.HealthCheck/Transports/LivenessTransportActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public LivenessTransportActor(IStatusTransport statusTransport, ImmutableDiction
try
{
if (_logInfo)
_log.Info("Received liveness status from probe [{0}]. Live: {1}, Message: {2}", probeName,
_log.Debug("Received liveness status from probe [{0}]. Live: {1}, Message: {2}", probeName,
status.IsLive, status.StatusMessage);
_statuses[probeName] = status;
Expand Down Expand Up @@ -88,12 +88,12 @@ public LivenessTransportActor(IStatusTransport statusTransport, ImmutableDiction
{
var probeName = probeReverseLookup[t.ActorRef];
if (_logInfo)
_log.Info("Liveness probe {0} terminated", probeName);
_log.Debug("Liveness probe {0} terminated", probeName);
_livenessProbes.Remove(t.ActorRef);
if (_livenessProbes.Count == 0)
{
_log.Warning("All liveness probe actors terminated! Shutting down.");
_log.Info("All liveness probe actors terminated! Shutting down.");
Context.Stop(Self);
}
else
Expand Down
19 changes: 9 additions & 10 deletions src/Akka.HealthCheck/Transports/ReadinessTransportActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public sealed class ReadinessTransportActor : ReceiveActor
private readonly List<IActorRef> _readinessProbes;
private readonly Dictionary<string, ReadinessStatus> _statuses = new ();
private readonly IStatusTransport _statusTransport;
private readonly bool _logInfo;

public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictionary<string, IActorRef> readinessProbe, bool log)
public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictionary<string, IActorRef> readinessProbe, bool logInfo)
{
_statusTransport = statusTransport;
var probeReverseLookup = readinessProbe.ToImmutableDictionary(kvp => kvp.Value, kvp => kvp.Key);
Expand All @@ -38,7 +37,6 @@ public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictio
_statuses[kvp.Key] = new ReadinessStatus(false, $"Probe {kvp.Key} starting up.");
}
_readinessProbes = readinessProbe.Values.ToList();
_logInfo = log;

ReceiveAsync<ReadinessStatus>(async status =>
{
Expand All @@ -47,8 +45,8 @@ public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictio
TransportWriteStatus writeStatus;
try
{
if (_logInfo)
_log.Info("Received readiness status from probe [{0}]. Ready: {1}, Message: {2}", probeName,
if (logInfo)
_log.Debug("Received readiness status from probe [{0}]. Ready: {1}, Message: {2}", probeName,
status.IsReady, status.StatusMessage);
_statuses[probeName] = status;
Expand All @@ -63,7 +61,7 @@ public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictio
}
catch (Exception e)
{
if (_logInfo)
if (logInfo)
_log.Error(e, $"While processing status from probe [{probeName}]. Failed to write to transport.");
throw new ProbeUpdateException(ProbeKind.Readiness,
Expand All @@ -76,7 +74,7 @@ public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictio
if (!writeStatus.Success)
{
if (_logInfo)
if (logInfo)
_log.Error(writeStatus.Exception, $"While processing status from probe [{probeName}]. Failed to write to transport.");
throw new ProbeUpdateException(ProbeKind.Readiness,
Expand All @@ -87,13 +85,14 @@ public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictio
Receive<Terminated>(t =>
{
var probeName = probeReverseLookup[t.ActorRef];
if (_logInfo)
_log.Info("Readiness probe {0} terminated", probeName);
if (logInfo)
_log.Debug("Readiness probe {0} terminated", probeName);
_readinessProbes.Remove(t.ActorRef);
if (_readinessProbes.Count == 0)
{
_log.Warning("All readiness probe actors terminated! Shutting down.");
if (logInfo)
_log.Info("All readiness probe actors terminated! Shutting down.");
Context.Stop(Self);
}
else
Expand Down

0 comments on commit c42639f

Please sign in to comment.