Skip to content

Commit

Permalink
More verbose logging for dynamic configuration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
klaren committed Oct 16, 2017
1 parent c493c64 commit 1b49567
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Expand Up @@ -572,10 +572,11 @@ public Optional<?> getValue( @Nonnull String key )
*
* @param setting The setting to set to the specified value.
* @param newValue The new value to set, passing {@code null} or empty should reset the value back to default value.
* @param origin The source of the change, e.g. {@code dbms.setConfigValue()}.
* @throws IllegalArgumentException if the provided setting is unknown or not dynamic.
* @throws InvalidSettingException if the value is not formatted correctly.
*/
public void updateDynamicSetting( String setting, String newValue ) throws IllegalArgumentException, InvalidSettingException
public void updateDynamicSetting( String setting, String newValue, String origin ) throws IllegalArgumentException, InvalidSettingException
{
// Make sure the setting is valid and is marked as dynamic
Optional<ConfigValue> option = findConfigValue( setting );
Expand All @@ -601,7 +602,7 @@ public void updateDynamicSetting( String setting, String newValue ) throws Illeg
{
params.put( setting, overriddenDefaults.get( setting ) );
}
newValue = getDefaultValueOf( setting );
newValue = "default (" + getConfiguredValueOf( setting ) + ")";
}
else
{
Expand All @@ -615,14 +616,17 @@ public void updateDynamicSetting( String setting, String newValue ) throws Illeg
validator.validate( newEntry, ignore -> {} ); // Throws if invalid
}

oldValue = getDefaultValueOf( setting );
oldValue = getConfiguredValueOf( setting );

params.put( setting, newValue );
if ( params.put( setting, newValue ) == null )
{
oldValue = "default (" + oldValue + ")";
}
}
log.info( "Setting changed: '%s' changed from '%s' to '%s'", setting, oldValue, newValue );
log.info( "Setting changed: '%s' changed from '%s' to '%s' via '%s'", setting, oldValue, newValue, origin );
}

private String getDefaultValueOf( String setting )
private String getConfiguredValueOf( String setting )
{
return getValue( setting ).map( Object::toString ).orElse( "<no default>" );
}
Expand Down
Expand Up @@ -369,13 +369,16 @@ public void updateDynamicShouldLogChanges() throws Exception
Log log = mock( Log.class );
config.setLogger( log );

config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "false" );
config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "true" );
config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "" );

verify( log ).info("Setting changed: '%s' changed from '%s' to '%s'", MyDynamicSettings.boolSetting.name(), "true", "false" );
verify( log ).info("Setting changed: '%s' changed from '%s' to '%s'", MyDynamicSettings.boolSetting.name(), "false", "true" );
verify( log ).info("Setting changed: '%s' changed from '%s' to '%s'", MyDynamicSettings.boolSetting.name(), "true", "true" );
config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "false", "test" );
config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "true", "test" );
config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "", "test" );

verify( log ).info("Setting changed: '%s' changed from '%s' to '%s' via '%s'",
MyDynamicSettings.boolSetting.name(), "default (true)", "false", "test" );
verify( log ).info("Setting changed: '%s' changed from '%s' to '%s' via '%s'",
MyDynamicSettings.boolSetting.name(), "false", "true", "test" );
verify( log ).info("Setting changed: '%s' changed from '%s' to '%s' via '%s'",
MyDynamicSettings.boolSetting.name(), "true", "default (true)", "test" );
verifyNoMoreInteractions( log );
}
}
Expand Up @@ -282,7 +282,7 @@ public void setConfigValue( @Name( "setting" ) String setting, @Name( "value" )
assertAdmin();

Config config = resolver.resolveDependency( Config.class );
config.updateDynamicSetting( setting, value ); // throws if something goes wrong
config.updateDynamicSetting( setting, value, "dbms.setConfigValue" ); // throws if something goes wrong
}

/*
Expand Down

0 comments on commit 1b49567

Please sign in to comment.