Skip to content

Remove stacktrace from recoverable discovery log warnings #943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@
import static org.neo4j.driver.internal.util.Futures.failedFuture;

/**
* This class is used by all router tables to perform discovery.
* In other words, the methods in this class could be called by multiple threads concurrently.
* This class is used by all router tables to perform discovery. In other words, the methods in this class could be called by multiple threads concurrently.
*/
public class RediscoveryImpl implements Rediscovery
{
private static final String NO_ROUTERS_AVAILABLE = "Could not perform discovery for database '%s'. No routing server available.";
private static final String RECOVERABLE_ROUTING_ERROR = "Failed to update routing table with server '%s'.";
private static final String RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER = "Received a recoverable discovery error with server '%s', " +
"will continue discovery with other routing servers if available. " +
"Complete routing failures will be reported separately from this warning.";

private final BoltServerAddress initialRouter;
private final RoutingSettings settings;
Expand Down Expand Up @@ -291,8 +293,9 @@ private ClusterComposition handleRoutingProcedureError( Throwable error, Routing
// Retriable error happened during discovery.
DiscoveryException discoveryError = new DiscoveryException( format( RECOVERABLE_ROUTING_ERROR, routerAddress ), error );
Futures.combineErrors( baseError, discoveryError ); // we record each failure here
logger.warn( format( "Received a recoverable discovery error with server '%s', will continue discovery with other routing servers if available.",
routerAddress ), discoveryError );
String warningMessage = format( RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress );
logger.warn( warningMessage );
logger.debug( warningMessage, discoveryError );
routingTable.forget( routerAddress );
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.startsWith;
Expand Down Expand Up @@ -187,9 +186,14 @@ void shouldFailImmediatelyWhenClusterCompositionProviderReturnsFailure()
ClusterComposition composition = await( rediscovery.lookupClusterComposition( table, pool, empty() ) ).getClusterComposition();
assertEquals( validComposition, composition );

ArgumentCaptor<DiscoveryException> argument = ArgumentCaptor.forClass( DiscoveryException.class );
verify( logger ).warn( anyString(), argument.capture() );
assertThat( argument.getValue().getCause(), equalTo( protocolError ) );
ArgumentCaptor<String> warningMessageCaptor = ArgumentCaptor.forClass( String.class );
ArgumentCaptor<String> debugMessageCaptor = ArgumentCaptor.forClass( String.class );
ArgumentCaptor<DiscoveryException> debugThrowableCaptor = ArgumentCaptor.forClass( DiscoveryException.class );
verify( logger ).warn( warningMessageCaptor.capture() );
verify( logger ).debug( debugMessageCaptor.capture(), debugThrowableCaptor.capture() );
assertNotNull( warningMessageCaptor.getValue() );
assertEquals( warningMessageCaptor.getValue(), debugMessageCaptor.getValue() );
assertThat( debugThrowableCaptor.getValue().getCause(), equalTo( protocolError ) );
}

@Test
Expand Down