From df52701d1d60ce9127cdafc7d7100a05ae9caf4f Mon Sep 17 00:00:00 2001 From: Jaime Pan <33685703+NEUpanning@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:02:38 +0800 Subject: [PATCH] Prune unnecessary information from TransportNodesInfoAction.NodeInfoRequest (#99938) There's no need to include the whole top-level `NodesInfoRequest` in the requests for info from individual nodes, and this can add substantial overhead if there are lots of nodes in the cluster. With this commit we drop the wrapper in favour of just the parts of the top-level request needed for the node-level processing. Relates #99744 --- docs/changelog/99938.yaml | 5 ++++ .../org/elasticsearch/TransportVersions.java | 1 + .../cluster/node/info/NodesInfoRequest.java | 7 ++++++ .../node/info/TransportNodesInfoAction.java | 25 ++++++++++++++----- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 docs/changelog/99938.yaml diff --git a/docs/changelog/99938.yaml b/docs/changelog/99938.yaml new file mode 100644 index 0000000000000..4349b73516cae --- /dev/null +++ b/docs/changelog/99938.yaml @@ -0,0 +1,5 @@ +pr: 99938 +summary: "Prune unnecessary information from TransportNodesInfoAction.NodeInfoRequest" +area: Stats +type: enhancement +issues: [99744] diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index 77fc98971ef0f..62f39260aeec4 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -150,6 +150,7 @@ static TransportVersion def(int id) { public static final TransportVersion ML_TRAINED_MODEL_CONFIG_PLATFORM_ADDED = def(8_507_00_0); public static final TransportVersion LONG_COUNT_IN_HISTOGRAM_ADDED = def(8_508_00_0); public static final TransportVersion INFERENCE_MODEL_SECRETS_ADDED = def(8_509_00_0); + public static final TransportVersion NODE_INFO_REQUEST_SIMPLIFIED = def(8_510_00_0); /* * STOP! READ THIS FIRST! No, really, * ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _ diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java index 04b2a7d980678..d7734f7a0eea3 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java @@ -85,6 +85,13 @@ public NodesInfoRequest addMetric(String metric) { */ public NodesInfoRequest addMetrics(String... metrics) { SortedSet metricsSet = new TreeSet<>(Set.of(metrics)); + return addMetrics(metricsSet); + } + + /** + * Add multiple metrics + */ + public NodesInfoRequest addMetrics(Set metricsSet) { if (NodesInfoMetrics.Metric.allMetrics().containsAll(metricsSet) == false) { metricsSet.removeAll(NodesInfoMetrics.Metric.allMetrics()); String plural = metricsSet.size() == 1 ? "" : "s"; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java index 14dffce86daa5..c263bea92ffa3 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Set; +import static org.elasticsearch.TransportVersions.NODE_INFO_REQUEST_SIMPLIFIED; + public class TransportNodesInfoAction extends TransportNodesAction< NodesInfoRequest, NodesInfoResponse, @@ -76,8 +78,7 @@ protected NodeInfo newNodeResponse(StreamInput in, DiscoveryNode node) throws IO @Override protected NodeInfo nodeOperation(NodeInfoRequest nodeRequest, Task task) { - NodesInfoRequest request = nodeRequest.request; - Set metrics = request.requestedMetrics(); + Set metrics = nodeRequest.requestedMetrics(); return nodeService.info( metrics.contains(NodesInfoMetrics.Metric.SETTINGS.metricName()), metrics.contains(NodesInfoMetrics.Metric.OS.metricName()), @@ -96,21 +97,33 @@ protected NodeInfo nodeOperation(NodeInfoRequest nodeRequest, Task task) { public static class NodeInfoRequest extends TransportRequest { - NodesInfoRequest request; + private NodesInfoMetrics nodesInfoMetrics; public NodeInfoRequest(StreamInput in) throws IOException { super(in); - request = new NodesInfoRequest(in); + if (in.getTransportVersion().onOrAfter(NODE_INFO_REQUEST_SIMPLIFIED)) { + this.nodesInfoMetrics = new NodesInfoMetrics(in); + } else { + this.nodesInfoMetrics = new NodesInfoRequest(in).getNodesInfoMetrics(); + } } public NodeInfoRequest(NodesInfoRequest request) { - this.request = request; + this.nodesInfoMetrics = request.getNodesInfoMetrics(); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - request.writeTo(out); + if (out.getTransportVersion().onOrAfter(NODE_INFO_REQUEST_SIMPLIFIED)) { + this.nodesInfoMetrics.writeTo(out); + } else { + new NodesInfoRequest().clear().addMetrics(nodesInfoMetrics.requestedMetrics()).writeTo(out); + } + } + + public Set requestedMetrics() { + return nodesInfoMetrics.requestedMetrics(); } } }