From d80bb1e02fb538020d392deea5ed6c9fc19bdab2 Mon Sep 17 00:00:00 2001 From: Thomas Stegemann Date: Wed, 1 Feb 2023 00:00:53 +0100 Subject: [PATCH 1/2] Fix for issue #6377 * created a setting property LogSerializerOverrideOnStart to reflect if warning should be logged or not * updated default config to enable logging for this issue by default * added property to the configuration Spezifikation --- .../Akka.Tests/Configuration/ConfigurationSpec.cs | 1 + src/core/Akka/Actor/Settings.cs | 8 ++++++++ src/core/Akka/Configuration/Pigeon.conf | 5 +++++ src/core/Akka/Serialization/Serialization.cs | 13 +++++++++---- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/core/Akka.Tests/Configuration/ConfigurationSpec.cs b/src/core/Akka.Tests/Configuration/ConfigurationSpec.cs index 0f6877cd1a9..25c926e68f7 100644 --- a/src/core/Akka.Tests/Configuration/ConfigurationSpec.cs +++ b/src/core/Akka.Tests/Configuration/ConfigurationSpec.cs @@ -46,6 +46,7 @@ public void The_default_configuration_file_contain_all_configuration_properties( settings.StdoutLogger.Should().NotBeNull(); settings.StdoutLogger.Should().BeOfType(); settings.LogConfigOnStart.ShouldBeFalse(); + settings.LogSerializerOverrideOnStart.ShouldBeTrue(); settings.LogDeadLetters.ShouldBe(10); settings.LogDeadLettersDuringShutdown.ShouldBeFalse(); settings.LogDeadLettersSuspendDuration.ShouldBe(TimeSpan.FromMinutes(5)); diff --git a/src/core/Akka/Actor/Settings.cs b/src/core/Akka/Actor/Settings.cs index 5f2ae5dccf2..7ad4e907757 100644 --- a/src/core/Akka/Actor/Settings.cs +++ b/src/core/Akka/Actor/Settings.cs @@ -143,6 +143,7 @@ public Settings(ActorSystem system, Config config, ActorSystemSetup setup) //handled LogConfigOnStart = Config.GetBoolean("akka.log-config-on-start", false); + LogSerializerOverrideOnStart = Config.GetBoolean("akka.log-serializer-override-on-start", true); LogDeadLetters = 0; switch (Config.GetString("akka.log-dead-letters", null)) { @@ -320,6 +321,13 @@ public Settings(ActorSystem system, Config config, ActorSystemSetup setup) /// true if [log configuration on start]; otherwise, false. public bool LogConfigOnStart { get; private set; } + + /// + /// Gets a value indicating whether [log serializer override on start]. + /// + /// true if [log serializer override on start]; otherwise, false. + public bool LogSerializerOverrideOnStart { get; private set; } + /// /// Gets the log dead letters. /// diff --git a/src/core/Akka/Configuration/Pigeon.conf b/src/core/Akka/Configuration/Pigeon.conf index c748b84f9da..cfb71b12445 100644 --- a/src/core/Akka/Configuration/Pigeon.conf +++ b/src/core/Akka/Configuration/Pigeon.conf @@ -51,6 +51,11 @@ akka { # This is useful when you are uncertain of what configuration is used. log-config-on-start = off + # Log the serializer override notification at WARNING level when the actor system is started. + # This is useful if want to make a change of the default serializer(s) and suppress the warning + # that is created if the configuration is changed. + log-serializer-override-on-start = on + # Log at info level when messages are sent to dead letters, or published to # eventStream as `DeadLetter`, `Dropped` or `UnhandledMessage`. # Possible values: diff --git a/src/core/Akka/Serialization/Serialization.cs b/src/core/Akka/Serialization/Serialization.cs index 78ed1e2f792..7111eb04881 100644 --- a/src/core/Akka/Serialization/Serialization.cs +++ b/src/core/Akka/Serialization/Serialization.cs @@ -150,6 +150,8 @@ public static T WithTransport(ActorSystem system, Address address, Func ac private readonly ImmutableHashSet _serializerDetails; private readonly MinimalLogger _initializationLogger; + private readonly bool _logSerializerOverrideOnStart; + /// /// Serialization module. Contains methods for serialization and deserialization as well as /// locating a Serializer for a particular class as defined in the mapping in the configuration. @@ -165,6 +167,9 @@ public Serialization(ExtendedActorSystem system) _nullSerializer = new NullSerializer(system); AddSerializer("null", _nullSerializer); + + _logSerializerOverrideOnStart = system.Settings.LogSerializerOverrideOnStart; + var serializersConfig = system.Settings.Config.GetConfig("akka.actor.serializers").AsEnumerable().ToList(); var serializerBindingConfig = system.Settings.Config.GetConfig("akka.actor.serialization-bindings").AsEnumerable().ToList(); var serializerSettingsConfig = system.Settings.Config.GetConfig("akka.actor.serialization-settings"); @@ -333,7 +338,7 @@ private Serializer GetSerializerByName(string name) public void AddSerializer(Serializer serializer) { var id = serializer.Identifier; - if(_serializersById.ContainsKey(id) && _serializersById[id].GetType() != serializer.GetType()) + if(_logSerializerOverrideOnStart && _serializersById.ContainsKey(id) && _serializersById[id].GetType() != serializer.GetType()) { LogWarning( $"Serializer with identifier [{id}] are being overriden " + @@ -352,7 +357,7 @@ public void AddSerializer(Serializer serializer) public void AddSerializer(string name, Serializer serializer) { var id = serializer.Identifier; - if(_serializersById.ContainsKey(id) && _serializersById[id].GetType() != serializer.GetType()) + if(_logSerializerOverrideOnStart && _serializersById.ContainsKey(id) && _serializersById[id].GetType() != serializer.GetType()) { LogWarning( $"Serializer with identifier [{id}] are being overriden " + @@ -360,7 +365,7 @@ public void AddSerializer(string name, Serializer serializer) "Did you mean to do this?"); } - if(_serializersByName.ContainsKey(name) && _serializersByName[name].GetType() != serializer.GetType()) + if(_logSerializerOverrideOnStart && _serializersByName.ContainsKey(name) && _serializersByName[name].GetType() != serializer.GetType()) LogWarning( $"Serializer with name [{serializer.Identifier}] are being overriden " + $"from [{_serializersByName[name].GetType()}] to [{serializer.GetType()}]. " + @@ -379,7 +384,7 @@ public void AddSerializer(string name, Serializer serializer) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddSerializationMap(Type type, Serializer serializer) { - if(_serializerMap.ContainsKey(type) && _serializerMap[type].GetType() != serializer.GetType()) + if(_logSerializerOverrideOnStart && _serializerMap.ContainsKey(type) && _serializerMap[type].GetType() != serializer.GetType()) LogWarning( $"Serializer for type [{type}] are being overriden " + $"from [{_serializerMap[type].GetType()}] to [{serializer.GetType()}]. " + From dfd3aafe8defe812ac568d226f81ec0851c2cd14 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Mon, 6 Feb 2023 20:37:39 -0600 Subject: [PATCH 2/2] added API approvals --- .../verify/CoreAPISpec.ApproveCore.Core.verified.txt | 1 + .../verify/CoreAPISpec.ApproveCore.DotNet.verified.txt | 1 + .../verify/CoreAPISpec.ApproveCore.Net.verified.txt | 1 + 3 files changed, 3 insertions(+) diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Core.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Core.verified.txt index 2d915b23f48..e1ee2709dbb 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Core.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Core.verified.txt @@ -1721,6 +1721,7 @@ namespace Akka.Actor public bool LogDeadLettersDuringShutdown { get; } public System.TimeSpan LogDeadLettersSuspendDuration { get; } public string LogLevel { get; } + public bool LogSerializerOverrideOnStart { get; } public bool LoggerAsyncStart { get; } public System.TimeSpan LoggerStartTimeout { get; } public System.Collections.Generic.IList Loggers { get; } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt index 076a9e39bf8..5aaa234a5fe 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt @@ -1723,6 +1723,7 @@ namespace Akka.Actor public bool LogDeadLettersDuringShutdown { get; } public System.TimeSpan LogDeadLettersSuspendDuration { get; } public string LogLevel { get; } + public bool LogSerializerOverrideOnStart { get; } public bool LoggerAsyncStart { get; } public System.TimeSpan LoggerStartTimeout { get; } public System.Collections.Generic.IList Loggers { get; } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt index 2d915b23f48..e1ee2709dbb 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt @@ -1721,6 +1721,7 @@ namespace Akka.Actor public bool LogDeadLettersDuringShutdown { get; } public System.TimeSpan LogDeadLettersSuspendDuration { get; } public string LogLevel { get; } + public bool LogSerializerOverrideOnStart { get; } public bool LoggerAsyncStart { get; } public System.TimeSpan LoggerStartTimeout { get; } public System.Collections.Generic.IList Loggers { get; }