Add server name to remote info API (#53634)
This commit adds the configured server_name to the proxy mode info so that it can be exposed in the remote info API.
This commit is contained in:
parent
c3d2417448
commit
881d0bfa8a
|
@ -24,14 +24,17 @@ import java.util.Objects;
|
||||||
public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {
|
public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {
|
||||||
static final String NAME = "proxy";
|
static final String NAME = "proxy";
|
||||||
static final String ADDRESS = "address";
|
static final String ADDRESS = "address";
|
||||||
|
static final String SERVER_NAME = "server_name";
|
||||||
static final String NUM_SOCKETS_CONNECTED = "num_sockets_connected";
|
static final String NUM_SOCKETS_CONNECTED = "num_sockets_connected";
|
||||||
static final String MAX_SOCKET_CONNECTIONS = "max_socket_connections";
|
static final String MAX_SOCKET_CONNECTIONS = "max_socket_connections";
|
||||||
private final String address;
|
private final String address;
|
||||||
|
private final String serverName;
|
||||||
private final int maxSocketConnections;
|
private final int maxSocketConnections;
|
||||||
private final int numSocketsConnected;
|
private final int numSocketsConnected;
|
||||||
|
|
||||||
ProxyModeInfo(String address, int maxSocketConnections, int numSocketsConnected) {
|
ProxyModeInfo(String address, String serverName, int maxSocketConnections, int numSocketsConnected) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
this.serverName = serverName;
|
||||||
this.maxSocketConnections = maxSocketConnections;
|
this.maxSocketConnections = maxSocketConnections;
|
||||||
this.numSocketsConnected = numSocketsConnected;
|
this.numSocketsConnected = numSocketsConnected;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +53,10 @@ public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMaxSocketConnections() {
|
public int getMaxSocketConnections() {
|
||||||
return maxSocketConnections;
|
return maxSocketConnections;
|
||||||
}
|
}
|
||||||
|
@ -65,11 +72,12 @@ public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {
|
||||||
ProxyModeInfo otherProxy = (ProxyModeInfo) o;
|
ProxyModeInfo otherProxy = (ProxyModeInfo) o;
|
||||||
return maxSocketConnections == otherProxy.maxSocketConnections &&
|
return maxSocketConnections == otherProxy.maxSocketConnections &&
|
||||||
numSocketsConnected == otherProxy.numSocketsConnected &&
|
numSocketsConnected == otherProxy.numSocketsConnected &&
|
||||||
Objects.equals(address, otherProxy.address);
|
Objects.equals(address, otherProxy.address) &&
|
||||||
|
Objects.equals(serverName, otherProxy.serverName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(address, maxSocketConnections, numSocketsConnected);
|
return Objects.hash(address, serverName, maxSocketConnections, numSocketsConnected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,9 @@ public final class RemoteConnectionInfo {
|
||||||
String mode = (String) args[1];
|
String mode = (String) args[1];
|
||||||
ModeInfo modeInfo;
|
ModeInfo modeInfo;
|
||||||
if (mode.equals(ProxyModeInfo.NAME)) {
|
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)) {
|
} 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 {
|
} else {
|
||||||
throw new IllegalArgumentException("mode cannot be " + mode);
|
throw new IllegalArgumentException("mode cannot be " + mode);
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ public final class RemoteConnectionInfo {
|
||||||
PARSER.declareBoolean(constructorArg(), new ParseField(SKIP_UNAVAILABLE));
|
PARSER.declareBoolean(constructorArg(), new ParseField(SKIP_UNAVAILABLE));
|
||||||
|
|
||||||
PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.ADDRESS));
|
PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.ADDRESS));
|
||||||
|
PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.SERVER_NAME));
|
||||||
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.MAX_SOCKET_CONNECTIONS));
|
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.MAX_SOCKET_CONNECTIONS));
|
||||||
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.NUM_SOCKETS_CONNECTED));
|
PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.NUM_SOCKETS_CONNECTED));
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class RemoteInfoResponseTests extends AbstractResponseTestCase<org.elasti
|
||||||
ProxyConnectionStrategy.ProxyModeInfo serverModeInfo =
|
ProxyConnectionStrategy.ProxyModeInfo serverModeInfo =
|
||||||
(ProxyConnectionStrategy.ProxyModeInfo) serverRemoteInfo.getModeInfo();
|
(ProxyConnectionStrategy.ProxyModeInfo) serverRemoteInfo.getModeInfo();
|
||||||
assertThat(clientModeInfo.getAddress(), equalTo(serverModeInfo.getAddress()));
|
assertThat(clientModeInfo.getAddress(), equalTo(serverModeInfo.getAddress()));
|
||||||
|
assertThat(clientModeInfo.getServerName(), equalTo(serverModeInfo.getServerName()));
|
||||||
assertThat(clientModeInfo.getMaxSocketConnections(), equalTo(serverModeInfo.getMaxSocketConnections()));
|
assertThat(clientModeInfo.getMaxSocketConnections(), equalTo(serverModeInfo.getMaxSocketConnections()));
|
||||||
assertThat(clientModeInfo.getNumSocketsConnected(), equalTo(serverModeInfo.getNumSocketsConnected()));
|
assertThat(clientModeInfo.getNumSocketsConnected(), equalTo(serverModeInfo.getNumSocketsConnected()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -95,9 +96,10 @@ public class RemoteInfoResponseTests extends AbstractResponseTestCase<org.elasti
|
||||||
RemoteConnectionInfo.ModeInfo modeInfo;
|
RemoteConnectionInfo.ModeInfo modeInfo;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
String address = randomAlphaOfLength(8);
|
String address = randomAlphaOfLength(8);
|
||||||
|
String serverName = randomAlphaOfLength(8);
|
||||||
int maxSocketConnections = randomInt(5);
|
int maxSocketConnections = randomInt(5);
|
||||||
int numSocketsConnected = randomInt(5);
|
int numSocketsConnected = randomInt(5);
|
||||||
modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(address, maxSocketConnections, numSocketsConnected);
|
modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(address, serverName, maxSocketConnections, numSocketsConnected);
|
||||||
} else {
|
} else {
|
||||||
List<String> seedNodes = randomList(randomInt(8), () -> randomAlphaOfLength(8));
|
List<String> seedNodes = randomList(randomInt(8), () -> randomAlphaOfLength(8));
|
||||||
int maxConnectionsPerCluster = randomInt(5);
|
int maxConnectionsPerCluster = randomInt(5);
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteConnectionInfo.ModeInfo getModeInfo() {
|
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) {
|
private void performProxyConnectionProcess(ActionListener<Void> listener) {
|
||||||
|
@ -255,17 +255,24 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy {
|
||||||
public static class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {
|
public static class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo {
|
||||||
|
|
||||||
private final String address;
|
private final String address;
|
||||||
|
private final String serverName;
|
||||||
private final int maxSocketConnections;
|
private final int maxSocketConnections;
|
||||||
private final int numSocketsConnected;
|
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.address = address;
|
||||||
|
this.serverName = serverName;
|
||||||
this.maxSocketConnections = maxSocketConnections;
|
this.maxSocketConnections = maxSocketConnections;
|
||||||
this.numSocketsConnected = numSocketsConnected;
|
this.numSocketsConnected = numSocketsConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProxyModeInfo(StreamInput input) throws IOException {
|
private ProxyModeInfo(StreamInput input) throws IOException {
|
||||||
address = input.readString();
|
address = input.readString();
|
||||||
|
if (input.getVersion().onOrAfter(Version.V_7_7_0)) {
|
||||||
|
serverName = input.readString();
|
||||||
|
} else {
|
||||||
|
serverName = null;
|
||||||
|
}
|
||||||
maxSocketConnections = input.readVInt();
|
maxSocketConnections = input.readVInt();
|
||||||
numSocketsConnected = input.readVInt();
|
numSocketsConnected = input.readVInt();
|
||||||
}
|
}
|
||||||
|
@ -273,6 +280,7 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy {
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field("address", address);
|
builder.field("address", address);
|
||||||
|
builder.field("server_name", serverName);
|
||||||
builder.field("num_sockets_connected", numSocketsConnected);
|
builder.field("num_sockets_connected", numSocketsConnected);
|
||||||
builder.field("max_socket_connections", maxSocketConnections);
|
builder.field("max_socket_connections", maxSocketConnections);
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -281,6 +289,9 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy {
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeString(address);
|
out.writeString(address);
|
||||||
|
if (out.getVersion().onOrAfter(Version.V_7_7_0)) {
|
||||||
|
out.writeString(serverName);
|
||||||
|
}
|
||||||
out.writeVInt(maxSocketConnections);
|
out.writeVInt(maxSocketConnections);
|
||||||
out.writeVInt(numSocketsConnected);
|
out.writeVInt(numSocketsConnected);
|
||||||
}
|
}
|
||||||
|
@ -299,6 +310,10 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMaxSocketConnections() {
|
public int getMaxSocketConnections() {
|
||||||
return maxSocketConnections;
|
return maxSocketConnections;
|
||||||
}
|
}
|
||||||
|
@ -319,12 +334,13 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy {
|
||||||
ProxyModeInfo otherProxy = (ProxyModeInfo) o;
|
ProxyModeInfo otherProxy = (ProxyModeInfo) o;
|
||||||
return maxSocketConnections == otherProxy.maxSocketConnections &&
|
return maxSocketConnections == otherProxy.maxSocketConnections &&
|
||||||
numSocketsConnected == otherProxy.numSocketsConnected &&
|
numSocketsConnected == otherProxy.numSocketsConnected &&
|
||||||
Objects.equals(address, otherProxy.address);
|
Objects.equals(address, otherProxy.address) &&
|
||||||
|
Objects.equals(serverName, otherProxy.serverName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(address, maxSocketConnections, numSocketsConnected);
|
return Objects.hash(address, serverName, maxSocketConnections, numSocketsConnected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,6 +348,7 @@ public class RemoteClusterConnectionTests extends ESTestCase {
|
||||||
|
|
||||||
public void testRemoteConnectionInfo() throws IOException {
|
public void testRemoteConnectionInfo() throws IOException {
|
||||||
List<String> remoteAddresses = Collections.singletonList("seed:1");
|
List<String> remoteAddresses = Collections.singletonList("seed:1");
|
||||||
|
String serverName = "the_server_name";
|
||||||
|
|
||||||
RemoteConnectionInfo.ModeInfo modeInfo1;
|
RemoteConnectionInfo.ModeInfo modeInfo1;
|
||||||
RemoteConnectionInfo.ModeInfo modeInfo2;
|
RemoteConnectionInfo.ModeInfo modeInfo2;
|
||||||
|
@ -356,8 +357,8 @@ public class RemoteClusterConnectionTests extends ESTestCase {
|
||||||
modeInfo1 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 4);
|
modeInfo1 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 4);
|
||||||
modeInfo2 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 3);
|
modeInfo2 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 3);
|
||||||
} else {
|
} else {
|
||||||
modeInfo1 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 18);
|
modeInfo1 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName, 18, 18);
|
||||||
modeInfo2 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 17);
|
modeInfo2 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName,18, 17);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteConnectionInfo stats =
|
RemoteConnectionInfo stats =
|
||||||
|
@ -425,6 +426,7 @@ public class RemoteClusterConnectionTests extends ESTestCase {
|
||||||
|
|
||||||
public void testRenderConnectionInfoXContent() throws IOException {
|
public void testRenderConnectionInfoXContent() throws IOException {
|
||||||
List<String> remoteAddresses = Arrays.asList("seed:1", "seed:2");
|
List<String> remoteAddresses = Arrays.asList("seed:1", "seed:2");
|
||||||
|
String serverName = "the_server_name";
|
||||||
|
|
||||||
RemoteConnectionInfo.ModeInfo modeInfo;
|
RemoteConnectionInfo.ModeInfo modeInfo;
|
||||||
|
|
||||||
|
@ -432,7 +434,7 @@ public class RemoteClusterConnectionTests extends ESTestCase {
|
||||||
if (sniff) {
|
if (sniff) {
|
||||||
modeInfo = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 3, 2);
|
modeInfo = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 3, 2);
|
||||||
} else {
|
} 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);
|
RemoteConnectionInfo stats = new RemoteConnectionInfo("test_cluster", modeInfo, TimeValue.timeValueMinutes(30), true);
|
||||||
|
@ -448,8 +450,8 @@ public class RemoteClusterConnectionTests extends ESTestCase {
|
||||||
"\"skip_unavailable\":true}}", Strings.toString(builder));
|
"\"skip_unavailable\":true}}", Strings.toString(builder));
|
||||||
} else {
|
} else {
|
||||||
assertEquals("{\"test_cluster\":{\"connected\":true,\"mode\":\"proxy\",\"address\":\"seed:1\"," +
|
assertEquals("{\"test_cluster\":{\"connected\":true,\"mode\":\"proxy\",\"address\":\"seed:1\"," +
|
||||||
"\"num_sockets_connected\":16,\"max_socket_connections\":18,\"initial_connect_timeout\":\"30m\"," +
|
"\"server_name\":\"the_server_name\",\"num_sockets_connected\":16,\"max_socket_connections\":18,"
|
||||||
"\"skip_unavailable\":true}}", Strings.toString(builder));
|
+"\"initial_connect_timeout\":\"30m\",\"skip_unavailable\":true}}", Strings.toString(builder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue