Skip to content

Commit

Permalink
Add server name to remote info API (#53634)
Browse files Browse the repository at this point in the history
This commit adds the configured server_name to the proxy mode info so
that it can be exposed in the remote info API.
  • Loading branch information
jasontedor committed Mar 17, 2020
1 parent 12e2485 commit 2abf40a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {
static final String NAME = "proxy";
static final String PROXY_ADDRESS = "proxy_address";
static final String SERVER_NAME = "server_name";
static final String NUM_PROXY_SOCKETS_CONNECTED = "num_proxy_sockets_connected";
static final String MAX_PROXY_SOCKET_CONNECTIONS = "max_proxy_socket_connections";
private final String address;
private final String serverName;
private final int maxSocketConnections;
private final int numSocketsConnected;

ProxyModeInfo(String address, int maxSocketConnections, int numSocketsConnected) {
ProxyModeInfo(String address, String serverName, int maxSocketConnections, int numSocketsConnected) {
this.address = address;
this.serverName = serverName;
this.maxSocketConnections = maxSocketConnections;
this.numSocketsConnected = numSocketsConnected;
}
Expand All @@ -50,6 +53,10 @@ public String getAddress() {
return address;
}

public String getServerName() {
return serverName;
}

public int getMaxSocketConnections() {
return maxSocketConnections;
}
Expand All @@ -65,11 +72,12 @@ public boolean equals(Object o) {
ProxyModeInfo otherProxy = (ProxyModeInfo) o;
return maxSocketConnections == otherProxy.maxSocketConnections &&
numSocketsConnected == otherProxy.numSocketsConnected &&
Objects.equals(address, otherProxy.address);
Objects.equals(address, otherProxy.address) &&
Objects.equals(serverName, otherProxy.serverName);
}

@Override
public int hashCode() {
return Objects.hash(address, maxSocketConnections, numSocketsConnected);
return Objects.hash(address, serverName, maxSocketConnections, numSocketsConnected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public final class RemoteConnectionInfo {
String mode = (String) args[1];
ModeInfo modeInfo;
if (mode.equals(ProxyModeInfo.NAME)) {
modeInfo = new ProxyModeInfo((String) args[4], (int) args[5], (int) args[6]);
modeInfo = new ProxyModeInfo((String) args[4], (String) args[5], (int) args[6], (int) args[7]);
} else if (mode.equals(SniffModeInfo.NAME)) {
modeInfo = new SniffModeInfo((List<String>) args[7], (int) args[8], (int) args[9]);
modeInfo = new SniffModeInfo((List<String>) args[8], (int) args[9], (int) args[10]);
} else {
throw new IllegalArgumentException("mode cannot be " + mode);
}
Expand All @@ -67,6 +67,7 @@ public final class RemoteConnectionInfo {
PARSER.declareBoolean(constructorArg(), new ParseField(SKIP_UNAVAILABLE));

PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.PROXY_ADDRESS));
PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.SERVER_NAME));
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.MAX_PROXY_SOCKET_CONNECTIONS));
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.NUM_PROXY_SOCKETS_CONNECTED));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected void assertInstances(org.elasticsearch.action.admin.cluster.remote.Rem
ProxyConnectionStrategy.ProxyModeInfo serverModeInfo =
(ProxyConnectionStrategy.ProxyModeInfo) serverRemoteInfo.getModeInfo();
assertThat(clientModeInfo.getAddress(), equalTo(serverModeInfo.getAddress()));
assertThat(clientModeInfo.getServerName(), equalTo(serverModeInfo.getServerName()));
assertThat(clientModeInfo.getMaxSocketConnections(), equalTo(serverModeInfo.getMaxSocketConnections()));
assertThat(clientModeInfo.getNumSocketsConnected(), equalTo(serverModeInfo.getNumSocketsConnected()));
} else {
Expand All @@ -95,9 +96,10 @@ private static RemoteConnectionInfo createRandomRemoteConnectionInfo() {
RemoteConnectionInfo.ModeInfo modeInfo;
if (randomBoolean()) {
String address = randomAlphaOfLength(8);
String serverName = randomAlphaOfLength(8);
int maxSocketConnections = randomInt(5);
int numSocketsConnected = randomInt(5);
modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(address, maxSocketConnections, numSocketsConnected);
modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(address, serverName, maxSocketConnections, numSocketsConnected);
} else {
List<String> seedNodes = randomList(randomInt(8), () -> randomAlphaOfLength(8));
int maxConnectionsPerCluster = randomInt(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected void connectImpl(ActionListener<Void> listener) {

@Override
public RemoteConnectionInfo.ModeInfo getModeInfo() {
return new ProxyModeInfo(configuredAddress, maxNumConnections, connectionManager.size());
return new ProxyModeInfo(configuredAddress, configuredServerName, maxNumConnections, connectionManager.size());
}

private void performProxyConnectionProcess(ActionListener<Void> listener) {
Expand Down Expand Up @@ -255,24 +255,32 @@ private static TransportAddress resolveAddress(String address) {
public static class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {

private final String address;
private final String serverName;
private final int maxSocketConnections;
private final int numSocketsConnected;

public ProxyModeInfo(String address, int maxSocketConnections, int numSocketsConnected) {
public ProxyModeInfo(String address, String serverName, int maxSocketConnections, int numSocketsConnected) {
this.address = address;
this.serverName = serverName;
this.maxSocketConnections = maxSocketConnections;
this.numSocketsConnected = numSocketsConnected;
}

private ProxyModeInfo(StreamInput input) throws IOException {
address = input.readString();
if (input.getVersion().onOrAfter(Version.V_8_0_0)) {
serverName = input.readString();
} else {
serverName = null;
}
maxSocketConnections = input.readVInt();
numSocketsConnected = input.readVInt();
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("proxy_address", address);
builder.field("server_name", serverName);
builder.field("num_proxy_sockets_connected", numSocketsConnected);
builder.field("max_proxy_socket_connections", maxSocketConnections);
return builder;
Expand All @@ -281,6 +289,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(address);
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
out.writeString(serverName);
}
out.writeVInt(maxSocketConnections);
out.writeVInt(numSocketsConnected);
}
Expand All @@ -299,6 +310,10 @@ public String getAddress() {
return address;
}

public String getServerName() {
return serverName;
}

public int getMaxSocketConnections() {
return maxSocketConnections;
}
Expand All @@ -319,12 +334,13 @@ public boolean equals(Object o) {
ProxyModeInfo otherProxy = (ProxyModeInfo) o;
return maxSocketConnections == otherProxy.maxSocketConnections &&
numSocketsConnected == otherProxy.numSocketsConnected &&
Objects.equals(address, otherProxy.address);
Objects.equals(address, otherProxy.address) &&
Objects.equals(serverName, otherProxy.serverName);
}

@Override
public int hashCode() {
return Objects.hash(address, maxSocketConnections, numSocketsConnected);
return Objects.hash(address, serverName, maxSocketConnections, numSocketsConnected);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ public void testGetConnectionInfo() throws Exception {

public void testRemoteConnectionInfo() throws IOException {
List<String> remoteAddresses = Collections.singletonList("seed:1");
String serverName = "the_server_name";

RemoteConnectionInfo.ModeInfo modeInfo1;
RemoteConnectionInfo.ModeInfo modeInfo2;
Expand All @@ -354,8 +355,8 @@ public void testRemoteConnectionInfo() throws IOException {
modeInfo1 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 4);
modeInfo2 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 3);
} else {
modeInfo1 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 18);
modeInfo2 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 17);
modeInfo1 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName, 18, 18);
modeInfo2 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName,18, 17);
}

RemoteConnectionInfo stats =
Expand Down Expand Up @@ -395,14 +396,15 @@ private static RemoteConnectionInfo assertSerialization(RemoteConnectionInfo inf

public void testRenderConnectionInfoXContent() throws IOException {
List<String> remoteAddresses = Arrays.asList("seed:1", "seed:2");
String serverName = "the_server_name";

RemoteConnectionInfo.ModeInfo modeInfo;

boolean sniff = randomBoolean();
if (sniff) {
modeInfo = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 3, 2);
} else {
modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 16);
modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName,18, 16);
}

RemoteConnectionInfo stats = new RemoteConnectionInfo("test_cluster", modeInfo, TimeValue.timeValueMinutes(30), true);
Expand All @@ -418,8 +420,8 @@ public void testRenderConnectionInfoXContent() throws IOException {
"\"skip_unavailable\":true}}", Strings.toString(builder));
} else {
assertEquals("{\"test_cluster\":{\"connected\":true,\"mode\":\"proxy\",\"proxy_address\":\"seed:1\"," +
"\"num_proxy_sockets_connected\":16,\"max_proxy_socket_connections\":18,\"initial_connect_timeout\":\"30m\"," +
"\"skip_unavailable\":true}}", Strings.toString(builder));
"\"server_name\":\"the_server_name\",\"num_proxy_sockets_connected\":16,\"max_proxy_socket_connections\":18,"+
"\"initial_connect_timeout\":\"30m\",\"skip_unavailable\":true}}", Strings.toString(builder));
}
}

Expand Down

0 comments on commit 2abf40a

Please sign in to comment.