Skip to content

Commit f4ed902

Browse files
authored
CCS: Drop http address from remote cluster info (#29568)
They are expensive to fetch and no longer needed by Kibana so they *shouldn't* be needed by anyone else either. Closes #29207
1 parent 912fbb2 commit f4ed902

File tree

10 files changed

+71
-197
lines changed

10 files changed

+71
-197
lines changed

docs/reference/cluster/remote-info.asciidoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ the configured remote cluster alias.
1919
`seeds`::
2020
The configured initial seed transport addresses of the remote cluster.
2121

22-
`http_addresses`::
23-
The published http addresses of all connected remote nodes.
24-
2522
`connected`::
2623
True if there is at least one connection to the remote cluster.
2724

docs/reference/release-notes/7.0.0-alpha1.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ The changes listed below have been released for the first time in Elasticsearch
1010
Core::
1111
* Tribe node has been removed in favor of Cross-Cluster-Search
1212

13+
Cross-Cluster-Search::
14+
* `http_addresses` has been removed from the <<cluster-remote-info>> API
15+
because it is expensive to fetch and no longer needed by Kibana.
16+
1317
Rest API::
1418
* The Clear Cache API only supports `POST` as HTTP method

qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/20_info.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- match: { my_remote_cluster.num_nodes_connected: 1}
88
- match: { my_remote_cluster.max_connections_per_cluster: 1}
99
- match: { my_remote_cluster.initial_connect_timeout: "30s" }
10-
- is_true: my_remote_cluster.http_addresses.0
1110

1211
---
1312
"Add transient remote cluster based on the preset cluster and check remote info":
@@ -38,9 +37,6 @@
3837

3938
- do:
4039
cluster.remote_info: {}
41-
- set: { my_remote_cluster.http_addresses.0: remote_http }
42-
- match: { test_remote_cluster.http_addresses.0: $remote_http }
43-
4440
- match: { test_remote_cluster.connected: true }
4541
- match: { my_remote_cluster.connected: true }
4642

@@ -132,4 +128,3 @@
132128
transient:
133129
search.remote.remote1.seeds: null
134130
search.remote.remote1.skip_unavailable: null
135-

server/src/main/java/org/elasticsearch/action/admin/cluster/remote/TransportRemoteInfoAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.elasticsearch.threadpool.ThreadPool;
3131
import org.elasticsearch.transport.TransportService;
3232

33+
import static java.util.stream.Collectors.toList;
34+
3335
public final class TransportRemoteInfoAction extends HandledTransportAction<RemoteInfoRequest, RemoteInfoResponse> {
3436

3537
private final RemoteClusterService remoteClusterService;
@@ -45,7 +47,6 @@ public TransportRemoteInfoAction(Settings settings, ThreadPool threadPool, Trans
4547

4648
@Override
4749
protected void doExecute(RemoteInfoRequest remoteInfoRequest, ActionListener<RemoteInfoResponse> listener) {
48-
remoteClusterService.getRemoteConnectionInfos(ActionListener.wrap(remoteConnectionInfos
49-
-> listener.onResponse(new RemoteInfoResponse(remoteConnectionInfos)), listener::onFailure));
50+
listener.onResponse(new RemoteInfoResponse(remoteClusterService.getRemoteConnectionInfos().collect(toList())));
5051
}
5152
}

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.rest.RestResponse;
3333
import org.elasticsearch.rest.RestStatus;
3434
import org.elasticsearch.rest.action.RestBuilderListener;
35+
import org.elasticsearch.rest.action.RestToXContentListener;
3536

3637
import java.io.IOException;
3738

@@ -50,16 +51,8 @@ public String getName() {
5051
}
5152

5253
@Override
53-
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client)
54-
throws IOException {
55-
return channel -> client.execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest(),
56-
new RestBuilderListener<RemoteInfoResponse>(channel) {
57-
@Override
58-
public RestResponse buildResponse(RemoteInfoResponse response, XContentBuilder builder) throws Exception {
59-
response.toXContent(builder, request);
60-
return new BytesRestResponse(RestStatus.OK, builder);
61-
}
62-
});
54+
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
55+
return channel -> client.execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest(), new RestToXContentListener<>(channel));
6356
}
6457
@Override
6558
public boolean canTripCircuitBreaker() {

server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.elasticsearch.common.component.AbstractComponent;
4141
import org.elasticsearch.common.settings.Settings;
4242
import org.elasticsearch.common.transport.TransportAddress;
43+
import org.elasticsearch.common.unit.TimeValue;
4344
import org.elasticsearch.common.util.CancellableThreads;
4445
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
4546
import org.elasticsearch.common.util.concurrent.ThreadContext;
@@ -602,66 +603,13 @@ void addConnectedNode(DiscoveryNode node) {
602603
}
603604

604605
/**
605-
* Fetches connection info for this connection
606+
* Get the information about remote nodes to be rendered on {@code _remote/info} requests.
606607
*/
607-
public void getConnectionInfo(ActionListener<RemoteConnectionInfo> listener) {
608-
final Optional<DiscoveryNode> anyNode = connectedNodes.getAny();
609-
if (anyNode.isPresent() == false) {
610-
// not connected we return immediately
611-
RemoteConnectionInfo remoteConnectionStats = new RemoteConnectionInfo(clusterAlias,
612-
Collections.emptyList(), Collections.emptyList(), maxNumRemoteConnections, 0,
613-
RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings), skipUnavailable);
614-
listener.onResponse(remoteConnectionStats);
615-
} else {
616-
NodesInfoRequest request = new NodesInfoRequest();
617-
request.clear();
618-
request.http(true);
619-
620-
transportService.sendRequest(anyNode.get(), NodesInfoAction.NAME, request, new TransportResponseHandler<NodesInfoResponse>() {
621-
@Override
622-
public NodesInfoResponse newInstance() {
623-
return new NodesInfoResponse();
624-
}
625-
626-
@Override
627-
public void handleResponse(NodesInfoResponse response) {
628-
Collection<TransportAddress> httpAddresses = new HashSet<>();
629-
for (NodeInfo info : response.getNodes()) {
630-
if (connectedNodes.contains(info.getNode()) && info.getHttp() != null) {
631-
httpAddresses.add(info.getHttp().getAddress().publishAddress());
632-
}
633-
}
634-
635-
if (httpAddresses.size() < maxNumRemoteConnections) {
636-
// just in case non of the connected nodes have http enabled we get other http enabled nodes instead.
637-
for (NodeInfo info : response.getNodes()) {
638-
if (nodePredicate.test(info.getNode()) && info.getHttp() != null) {
639-
httpAddresses.add(info.getHttp().getAddress().publishAddress());
640-
}
641-
if (httpAddresses.size() == maxNumRemoteConnections) {
642-
break; // once we have enough return...
643-
}
644-
}
645-
}
646-
RemoteConnectionInfo remoteConnectionInfo = new RemoteConnectionInfo(clusterAlias,
647-
seedNodes.stream().map(DiscoveryNode::getAddress).collect(Collectors.toList()), new ArrayList<>(httpAddresses),
648-
maxNumRemoteConnections, connectedNodes.size(),
649-
RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings), skipUnavailable);
650-
listener.onResponse(remoteConnectionInfo);
651-
}
652-
653-
@Override
654-
public void handleException(TransportException exp) {
655-
listener.onFailure(exp);
656-
}
657-
658-
@Override
659-
public String executor() {
660-
return ThreadPool.Names.SAME;
661-
}
662-
});
663-
}
664-
608+
public RemoteConnectionInfo getConnectionInfo() {
609+
List<TransportAddress> seedNodeAddresses = seedNodes.stream().map(DiscoveryNode::getAddress).collect(Collectors.toList());
610+
TimeValue initialConnectionTimeout = RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
611+
return new RemoteConnectionInfo(clusterAlias, seedNodeAddresses, maxNumRemoteConnections, connectedNodes.size(),
612+
initialConnectionTimeout, skipUnavailable);
665613
}
666614

667615
int getNumNodesConnected() {

server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.elasticsearch.action.OriginalIndices;
2626
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest;
2727
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
28-
import org.elasticsearch.action.support.GroupedActionListener;
2928
import org.elasticsearch.action.support.IndicesOptions;
3029
import org.elasticsearch.action.support.PlainActionFuture;
3130
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -42,7 +41,6 @@
4241
import java.io.Closeable;
4342
import java.io.IOException;
4443
import java.net.InetSocketAddress;
45-
import java.util.Collection;
4644
import java.util.Collections;
4745
import java.util.HashMap;
4846
import java.util.List;
@@ -56,6 +54,7 @@
5654
import java.util.function.Function;
5755
import java.util.function.Predicate;
5856
import java.util.stream.Collectors;
57+
import java.util.stream.Stream;
5958

6059
import static org.elasticsearch.common.settings.Setting.boolSetting;
6160

@@ -348,17 +347,8 @@ public void close() throws IOException {
348347
IOUtils.close(remoteClusters.values());
349348
}
350349

351-
public void getRemoteConnectionInfos(ActionListener<Collection<RemoteConnectionInfo>> listener) {
352-
final Map<String, RemoteClusterConnection> remoteClusters = this.remoteClusters;
353-
if (remoteClusters.isEmpty()) {
354-
listener.onResponse(Collections.emptyList());
355-
} else {
356-
final GroupedActionListener<RemoteConnectionInfo> actionListener = new GroupedActionListener<>(listener,
357-
remoteClusters.size(), Collections.emptyList());
358-
for (RemoteClusterConnection connection : remoteClusters.values()) {
359-
connection.getConnectionInfo(actionListener);
360-
}
361-
}
350+
public Stream<RemoteConnectionInfo> getRemoteConnectionInfos() {
351+
return remoteClusters.values().stream().map(RemoteClusterConnection::getConnectionInfo);
362352
}
363353

364354
/**

server/src/main/java/org/elasticsearch/transport/RemoteConnectionInfo.java

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,29 @@
2727
import org.elasticsearch.common.xcontent.ToXContentFragment;
2828
import org.elasticsearch.common.xcontent.XContentBuilder;
2929

30+
import static java.util.Collections.emptyList;
31+
3032
import java.io.IOException;
3133
import java.util.List;
3234
import java.util.Objects;
3335

3436
/**
3537
* This class encapsulates all remote cluster information to be rendered on
36-
* <tt>_remote/info</tt> requests.
38+
* {@code _remote/info} requests.
3739
*/
3840
public final class RemoteConnectionInfo implements ToXContentFragment, Writeable {
3941
final List<TransportAddress> seedNodes;
40-
final List<TransportAddress> httpAddresses;
4142
final int connectionsPerCluster;
4243
final TimeValue initialConnectionTimeout;
4344
final int numNodesConnected;
4445
final String clusterAlias;
4546
final boolean skipUnavailable;
4647

4748
RemoteConnectionInfo(String clusterAlias, List<TransportAddress> seedNodes,
48-
List<TransportAddress> httpAddresses,
4949
int connectionsPerCluster, int numNodesConnected,
5050
TimeValue initialConnectionTimeout, boolean skipUnavailable) {
5151
this.clusterAlias = clusterAlias;
5252
this.seedNodes = seedNodes;
53-
this.httpAddresses = httpAddresses;
5453
this.connectionsPerCluster = connectionsPerCluster;
5554
this.numNodesConnected = numNodesConnected;
5655
this.initialConnectionTimeout = initialConnectionTimeout;
@@ -59,16 +58,45 @@ public final class RemoteConnectionInfo implements ToXContentFragment, Writeable
5958

6059
public RemoteConnectionInfo(StreamInput input) throws IOException {
6160
seedNodes = input.readList(TransportAddress::new);
62-
httpAddresses = input.readList(TransportAddress::new);
61+
if (input.getVersion().before(Version.V_7_0_0_alpha1)) {
62+
/*
63+
* Versions before 7.0 sent the HTTP addresses of all nodes in the
64+
* remote cluster here but it was expensive to fetch and we
65+
* ultimately figured out how to do without it. So we removed it.
66+
*
67+
* We just throw any HTTP addresses received here on the floor
68+
* because we don't need to do anything with them.
69+
*/
70+
input.readList(TransportAddress::new);
71+
}
6372
connectionsPerCluster = input.readVInt();
6473
initialConnectionTimeout = input.readTimeValue();
6574
numNodesConnected = input.readVInt();
6675
clusterAlias = input.readString();
67-
if (input.getVersion().onOrAfter(Version.V_6_1_0)) {
68-
skipUnavailable = input.readBoolean();
69-
} else {
70-
skipUnavailable = false;
76+
skipUnavailable = input.readBoolean();
77+
}
78+
79+
@Override
80+
public void writeTo(StreamOutput out) throws IOException {
81+
out.writeList(seedNodes);
82+
if (out.getVersion().before(Version.V_7_0_0_alpha1)) {
83+
/*
84+
* Versions before 7.0 sent the HTTP addresses of all nodes in the
85+
* remote cluster here but it was expensive to fetch and we
86+
* ultimately figured out how to do without it. So we removed it.
87+
*
88+
* When sending this request to a node that expects HTTP addresses
89+
* here we pretend that we didn't find any. This *should* be fine
90+
* because, after all, we haven't been using this information for
91+
* a while.
92+
*/
93+
out.writeList(emptyList());
7194
}
95+
out.writeVInt(connectionsPerCluster);
96+
out.writeTimeValue(initialConnectionTimeout);
97+
out.writeVInt(numNodesConnected);
98+
out.writeString(clusterAlias);
99+
out.writeBoolean(skipUnavailable);
72100
}
73101

74102
@Override
@@ -80,11 +108,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
80108
builder.value(addr.toString());
81109
}
82110
builder.endArray();
83-
builder.startArray("http_addresses");
84-
for (TransportAddress addr : httpAddresses) {
85-
builder.value(addr.toString());
86-
}
87-
builder.endArray();
88111
builder.field("connected", numNodesConnected > 0);
89112
builder.field("num_nodes_connected", numNodesConnected);
90113
builder.field("max_connections_per_cluster", connectionsPerCluster);
@@ -95,19 +118,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
95118
return builder;
96119
}
97120

98-
@Override
99-
public void writeTo(StreamOutput out) throws IOException {
100-
out.writeList(seedNodes);
101-
out.writeList(httpAddresses);
102-
out.writeVInt(connectionsPerCluster);
103-
out.writeTimeValue(initialConnectionTimeout);
104-
out.writeVInt(numNodesConnected);
105-
out.writeString(clusterAlias);
106-
if (out.getVersion().onOrAfter(Version.V_6_1_0)) {
107-
out.writeBoolean(skipUnavailable);
108-
}
109-
}
110-
111121
@Override
112122
public boolean equals(Object o) {
113123
if (this == o) return true;
@@ -116,15 +126,14 @@ public boolean equals(Object o) {
116126
return connectionsPerCluster == that.connectionsPerCluster &&
117127
numNodesConnected == that.numNodesConnected &&
118128
Objects.equals(seedNodes, that.seedNodes) &&
119-
Objects.equals(httpAddresses, that.httpAddresses) &&
120129
Objects.equals(initialConnectionTimeout, that.initialConnectionTimeout) &&
121130
Objects.equals(clusterAlias, that.clusterAlias) &&
122131
skipUnavailable == that.skipUnavailable;
123132
}
124133

125134
@Override
126135
public int hashCode() {
127-
return Objects.hash(seedNodes, httpAddresses, connectionsPerCluster, initialConnectionTimeout,
136+
return Objects.hash(seedNodes, connectionsPerCluster, initialConnectionTimeout,
128137
numNodesConnected, clusterAlias, skipUnavailable);
129138
}
130139
}

0 commit comments

Comments
 (0)