Allow proxy mode server name to be updated (#54107)

Currently there is a bug where the proxy strategy will not be rebuilt if
the server_name is dynamically updated. This commit fixes this issue.
This commit is contained in:
Tim Brooks 2020-03-24 11:43:46 -06:00
parent 21afc788f8
commit b21b7fb09b
No known key found for this signature in database
GPG Key ID: C2AA3BB91A889E77
2 changed files with 15 additions and 3 deletions

View File

@ -157,7 +157,9 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy {
protected boolean strategyMustBeRebuilt(Settings newSettings) {
String address = PROXY_ADDRESS.getConcreteSettingForNamespace(clusterAlias).get(newSettings);
int numOfSockets = REMOTE_SOCKET_CONNECTIONS.getConcreteSettingForNamespace(clusterAlias).get(newSettings);
return numOfSockets != maxNumConnections || configuredAddress.equals(address) == false;
String serverName = SERVER_NAME.getConcreteSettingForNamespace(clusterAlias).get(newSettings);
return numOfSockets != maxNumConnections || configuredAddress.equals(address) == false ||
Objects.equals(serverName, configuredServerName) == false;
}
@Override

View File

@ -268,7 +268,7 @@ public class ProxyConnectionStrategyTests extends ESTestCase {
}
}
public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesChange() {
public void testProxyStrategyWillNeedToBeRebuiltIfNumOfSocketsOrAddressesOrServerNameChange() {
try (MockTransportService remoteTransport = startTransport("node1", Version.CURRENT)) {
TransportAddress remoteAddress = remoteTransport.boundAddress().publishAddress();
@ -280,7 +280,7 @@ public class ProxyConnectionStrategyTests extends ESTestCase {
int numOfConnections = randomIntBetween(4, 8);
try (RemoteConnectionManager remoteConnectionManager = new RemoteConnectionManager(clusterAlias, connectionManager);
ProxyConnectionStrategy strategy = new ProxyConnectionStrategy(clusterAlias, localService, remoteConnectionManager,
numOfConnections, remoteAddress.toString())) {
numOfConnections, remoteAddress.toString(), "server-name")) {
PlainActionFuture<Void> connectFuture = PlainActionFuture.newFuture();
strategy.connect(connectFuture);
connectFuture.actionGet();
@ -295,11 +295,14 @@ public class ProxyConnectionStrategyTests extends ESTestCase {
.getConcreteSettingForNamespace("cluster-alias");
Setting<?> socketConnections = ProxyConnectionStrategy.REMOTE_SOCKET_CONNECTIONS
.getConcreteSettingForNamespace("cluster-alias");
Setting<?> serverName = ProxyConnectionStrategy.SERVER_NAME
.getConcreteSettingForNamespace("cluster-alias");
Settings noChange = Settings.builder()
.put(modeSetting.getKey(), "proxy")
.put(addressesSetting.getKey(), remoteAddress.toString())
.put(socketConnections.getKey(), numOfConnections)
.put(serverName.getKey(), "server-name")
.build();
assertFalse(strategy.shouldRebuildConnection(noChange));
Settings addressesChanged = Settings.builder()
@ -313,6 +316,13 @@ public class ProxyConnectionStrategyTests extends ESTestCase {
.put(socketConnections.getKey(), numOfConnections + 1)
.build();
assertTrue(strategy.shouldRebuildConnection(socketsChanged));
Settings serverNameChange = Settings.builder()
.put(modeSetting.getKey(), "proxy")
.put(addressesSetting.getKey(), remoteAddress.toString())
.put(socketConnections.getKey(), numOfConnections)
.put(serverName.getKey(), "server-name2")
.build();
assertTrue(strategy.shouldRebuildConnection(serverNameChange));
}
}
}