Skip to content

Commit

Permalink
Fix for issue #6377 (#6378)
Browse files Browse the repository at this point in the history
* 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

* added API approvals

---------

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
  • Loading branch information
beachwalker and Aaronontheweb committed Feb 7, 2023
1 parent 83341fa commit 2f5aab2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
Expand Up @@ -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<string> Loggers { get; }
Expand Down
Expand Up @@ -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<string> Loggers { get; }
Expand Down
Expand Up @@ -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<string> Loggers { get; }
Expand Down
1 change: 1 addition & 0 deletions src/core/Akka.Tests/Configuration/ConfigurationSpec.cs
Expand Up @@ -46,6 +46,7 @@ public void The_default_configuration_file_contain_all_configuration_properties(
settings.StdoutLogger.Should().NotBeNull();
settings.StdoutLogger.Should().BeOfType<StandardOutLogger>();
settings.LogConfigOnStart.ShouldBeFalse();
settings.LogSerializerOverrideOnStart.ShouldBeTrue();
settings.LogDeadLetters.ShouldBe(10);
settings.LogDeadLettersDuringShutdown.ShouldBeFalse();
settings.LogDeadLettersSuspendDuration.ShouldBe(TimeSpan.FromMinutes(5));
Expand Down
8 changes: 8 additions & 0 deletions src/core/Akka/Actor/Settings.cs
Expand Up @@ -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))
{
Expand Down Expand Up @@ -320,6 +321,13 @@ public Settings(ActorSystem system, Config config, ActorSystemSetup setup)
/// <value><c>true</c> if [log configuration on start]; otherwise, <c>false</c>.</value>
public bool LogConfigOnStart { get; private set; }


/// <summary>
/// Gets a value indicating whether [log serializer override on start].
/// </summary>
/// <value><c>true</c> if [log serializer override on start]; otherwise, <c>false</c>.</value>
public bool LogSerializerOverrideOnStart { get; private set; }

/// <summary>
/// Gets the log dead letters.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/core/Akka/Configuration/Pigeon.conf
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions src/core/Akka/Serialization/Serialization.cs
Expand Up @@ -150,6 +150,8 @@ public static T WithTransport<T>(ActorSystem system, Address address, Func<T> ac
private readonly ImmutableHashSet<SerializerDetails> _serializerDetails;
private readonly MinimalLogger _initializationLogger;

private readonly bool _logSerializerOverrideOnStart;

/// <summary>
/// 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.
Expand All @@ -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");
Expand Down Expand Up @@ -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 " +
Expand All @@ -352,15 +357,15 @@ 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 " +
$"from [{_serializersById[id].GetType()}] to [{serializer.GetType()}]. " +
"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()}]. " +
Expand All @@ -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()}]. " +
Expand Down

0 comments on commit 2f5aab2

Please sign in to comment.