Skip to content
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

Fix logging IP version 6 addresses with scope in RediscoveryImpl #1435

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -316,13 +316,11 @@ private ClusterComposition handleRoutingProcedureError(
throw new CompletionException(error);
}

// Retriable error happened during discovery.
DiscoveryException discoveryError =
new DiscoveryException(format(RECOVERABLE_ROUTING_ERROR, routerAddress), error);
// Retryable error happened during discovery.
var discoveryError = new DiscoveryException(format(RECOVERABLE_ROUTING_ERROR, routerAddress), error);
Futures.combineErrors(baseError, discoveryError); // we record each failure here
String warningMessage = format(RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress);
log.warn(warningMessage);
log.debug(warningMessage, discoveryError);
log.warn(RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress);
log.debug(format(RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress), discoveryError);
routingTable.forget(routerAddress);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
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.BDDMockito.given;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.startsWith;
Expand All @@ -54,6 +56,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -525,6 +528,35 @@ void shouldFailImmediatelyOnUnsupportedFeatureException() {
verify(table).forget(A);
}

@Test
void shouldLogScopedIPV6AddressWithStringFormattingLogger() throws UnknownHostException {
// GIVEN
var initialRouter = new BoltServerAddress("initialRouter", 7687);
var compositionProvider = compositionProviderMock(Collections.emptyMap());
var resolver = resolverMock(initialRouter, initialRouter);
var domainNameResolver = mock(DomainNameResolver.class);
var address = mock(InetAddress.class);
given(address.getHostAddress()).willReturn("fe80:0:0:0:ce66:1564:db8q:94b6%6");
given(domainNameResolver.resolve(initialRouter.host())).willReturn(new InetAddress[] {address});
var table = routingTableMock(true);
var pool = mock(ConnectionPool.class);
given(pool.acquire(any(), any()))
.willReturn(CompletableFuture.failedFuture(new ServiceUnavailableException("not available")));
var logging = mock(Logging.class);
var logger = mock(Logger.class);
given(logging.getLog(any(Class.class))).willReturn(logger);
doAnswer(invocationOnMock -> String.format(invocationOnMock.getArgument(0), invocationOnMock.getArgument(1)))
.when(logger)
.warn(any());
var rediscovery =
new RediscoveryImpl(initialRouter, compositionProvider, resolver, logging, domainNameResolver);

// WHEN & THEN
assertThrows(
ServiceUnavailableException.class,
() -> await(rediscovery.lookupClusterComposition(table, pool, Collections.emptySet(), null, null)));
}

private Rediscovery newRediscovery(
BoltServerAddress initialRouter,
ClusterCompositionProvider compositionProvider,
Expand Down