diff --git a/src/Akka.HealthCheck.Cluster.Tests/ReadinessStatusClusterUpSpecs.cs b/src/Akka.HealthCheck.Cluster.Tests/ReadinessStatusClusterUpSpecs.cs index f45f3eb..f2453de 100644 --- a/src/Akka.HealthCheck.Cluster.Tests/ReadinessStatusClusterUpSpecs.cs +++ b/src/Akka.HealthCheck.Cluster.Tests/ReadinessStatusClusterUpSpecs.cs @@ -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 @@ -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 diff --git a/src/Akka.HealthCheck.Cluster/ClusterLivenessProbe.cs b/src/Akka.HealthCheck.Cluster/ClusterLivenessProbe.cs index 0decabf..3dc9859 100644 --- a/src/Akka.HealthCheck.Cluster/ClusterLivenessProbe.cs +++ b/src/Akka.HealthCheck.Cluster/ClusterLivenessProbe.cs @@ -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 _subscribers = new HashSet(); + 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(s => diff --git a/src/Akka.HealthCheck.Cluster/ClusterLivenessProbeProvider.cs b/src/Akka.HealthCheck.Cluster/ClusterLivenessProbeProvider.cs index 102ba2a..24d8068 100644 --- a/src/Akka.HealthCheck.Cluster/ClusterLivenessProbeProvider.cs +++ b/src/Akka.HealthCheck.Cluster/ClusterLivenessProbeProvider.cs @@ -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)); } } \ No newline at end of file diff --git a/src/Akka.HealthCheck.Cluster/ClusterReadinessProbeProvider.cs b/src/Akka.HealthCheck.Cluster/ClusterReadinessProbeProvider.cs index 34cdeb4..598235b 100644 --- a/src/Akka.HealthCheck.Cluster/ClusterReadinessProbeProvider.cs +++ b/src/Akka.HealthCheck.Cluster/ClusterReadinessProbeProvider.cs @@ -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)); } /// @@ -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 _subscribers = new HashSet(); + 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(s => diff --git a/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableDueToSnapshotStoreSpecs.cs b/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableDueToSnapshotStoreSpecs.cs index 39cbf2e..1e39796 100644 --- a/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableDueToSnapshotStoreSpecs.cs +++ b/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableDueToSnapshotStoreSpecs.cs @@ -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().IsLive.Should().BeFalse("System should not be live"); ExpectMsg(TimeSpan.FromMinutes(1)).IsLive.Should().BeFalse("System should not be live"); diff --git a/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableduetoJournalSpecs.cs b/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableduetoJournalSpecs.cs index 77e4957..da1b6ab 100644 --- a/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableduetoJournalSpecs.cs +++ b/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeNotAvailableduetoJournalSpecs.cs @@ -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().IsLive.Should().BeFalse("System should not be live"); ExpectMsg(TimeSpan.FromMinutes(1)).IsLive.Should().BeFalse("System should not be live"); diff --git a/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeSubscriptionTest.cs b/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeSubscriptionTest.cs index 308d460..2048cf0 100644 --- a/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeSubscriptionTest.cs +++ b/src/Akka.HealthCheck.Persistence.Tests/AkkaPersistenceLivenessProbeSubscriptionTest.cs @@ -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().IsLive.Should().BeFalse(); AwaitAssert(() => ExpectMsg().IsLive.Should().BeTrue(),TimeSpan.FromSeconds(10)); diff --git a/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs b/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs index 8ae7d52..2cc56d0 100644 --- a/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs +++ b/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbe.cs @@ -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); } @@ -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; @@ -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(); } @@ -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: diff --git a/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbeProvider.cs b/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbeProvider.cs index 5661b7b..1855597 100644 --- a/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbeProvider.cs +++ b/src/Akka.HealthCheck.Persistence/AkkaPersistenceLivenessProbeProvider.cs @@ -17,6 +17,6 @@ public AkkaPersistenceLivenessProbeProvider(ActorSystem system) : base(system) { } - public override Props ProbeProps => AkkaPersistenceLivenessProbe.PersistentHealthCheckProps(); + public override Props ProbeProps => AkkaPersistenceLivenessProbe.PersistentHealthCheckProps(Settings.LogInfoEvents); } } \ No newline at end of file diff --git a/src/Akka.HealthCheck.Tests/Configuration/HealthCheckSettingsSpecs.cs b/src/Akka.HealthCheck.Tests/Configuration/HealthCheckSettingsSpecs.cs index 203f6d2..cb5553b 100644 --- a/src/Akka.HealthCheck.Tests/Configuration/HealthCheckSettingsSpecs.cs +++ b/src/Akka.HealthCheck.Tests/Configuration/HealthCheckSettingsSpecs.cs @@ -35,8 +35,8 @@ public void Should_load_default_HealthCheck_Settings() settings.ReadinessTransport.Should().Be(ProbeTransport.Custom); settings.LivenessTransportSettings.Should().BeOfType(); settings.ReadinessTransportSettings.Should().BeOfType(); - 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")] @@ -44,14 +44,14 @@ 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")] diff --git a/src/Akka.HealthCheck/Configuration/akka.healthcheck.conf b/src/Akka.HealthCheck/Configuration/akka.healthcheck.conf index 960dfb9..0a9005a 100644 --- a/src/Akka.HealthCheck/Configuration/akka.healthcheck.conf +++ b/src/Akka.HealthCheck/Configuration/akka.healthcheck.conf @@ -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. diff --git a/src/Akka.HealthCheck/ProbeProviderBase.cs b/src/Akka.HealthCheck/ProbeProviderBase.cs index c285c27..a4649cb 100644 --- a/src/Akka.HealthCheck/ProbeProviderBase.cs +++ b/src/Akka.HealthCheck/ProbeProviderBase.cs @@ -5,6 +5,7 @@ // ----------------------------------------------------------------------- using Akka.Actor; +using Akka.HealthCheck.Configuration; namespace Akka.HealthCheck { @@ -16,6 +17,8 @@ namespace Akka.HealthCheck /// public abstract class ProbeProviderBase : IProbeProvider { + protected HealthCheckSettings Settings { get; } + /// /// Constructor takes the on which this /// healthcheck will run as a current argument. Designed to allow @@ -25,6 +28,7 @@ public abstract class ProbeProviderBase : IProbeProvider /// The current actor system. protected ProbeProviderBase(ActorSystem system) { + Settings = new HealthCheckSettings(system); } /// diff --git a/src/Akka.HealthCheck/Transports/LivenessTransportActor.cs b/src/Akka.HealthCheck/Transports/LivenessTransportActor.cs index ff02bb1..12377bb 100644 --- a/src/Akka.HealthCheck/Transports/LivenessTransportActor.cs +++ b/src/Akka.HealthCheck/Transports/LivenessTransportActor.cs @@ -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; @@ -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 diff --git a/src/Akka.HealthCheck/Transports/ReadinessTransportActor.cs b/src/Akka.HealthCheck/Transports/ReadinessTransportActor.cs index 594c89e..42c5d7d 100644 --- a/src/Akka.HealthCheck/Transports/ReadinessTransportActor.cs +++ b/src/Akka.HealthCheck/Transports/ReadinessTransportActor.cs @@ -26,9 +26,8 @@ public sealed class ReadinessTransportActor : ReceiveActor private readonly List _readinessProbes; private readonly Dictionary _statuses = new (); private readonly IStatusTransport _statusTransport; - private readonly bool _logInfo; - public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictionary readinessProbe, bool log) + public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictionary readinessProbe, bool logInfo) { _statusTransport = statusTransport; var probeReverseLookup = readinessProbe.ToImmutableDictionary(kvp => kvp.Value, kvp => kvp.Key); @@ -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(async status => { @@ -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; @@ -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, @@ -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, @@ -87,13 +85,14 @@ public ReadinessTransportActor(IStatusTransport statusTransport, ImmutableDictio Receive(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