Skip to content

Commit

Permalink
Prune unnecessary information from TransportNodesInfoAction.NodeInfoR…
Browse files Browse the repository at this point in the history
…equest (elastic#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 elastic#99744
  • Loading branch information
NEUpanning authored and jakelandis committed Oct 2, 2023
1 parent 523f748 commit a569b95
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/99938.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 99938
summary: "Prune unnecessary information from TransportNodesInfoAction.NodeInfoRequest"
area: Stats
type: enhancement
issues: [99744]
Original file line number Diff line number Diff line change
Expand Up @@ -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,
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public NodesInfoRequest addMetric(String metric) {
*/
public NodesInfoRequest addMetrics(String... metrics) {
SortedSet<String> metricsSet = new TreeSet<>(Set.of(metrics));
return addMetrics(metricsSet);
}

/**
* Add multiple metrics
*/
public NodesInfoRequest addMetrics(Set<String> metricsSet) {
if (NodesInfoMetrics.Metric.allMetrics().containsAll(metricsSet) == false) {
metricsSet.removeAll(NodesInfoMetrics.Metric.allMetrics());
String plural = metricsSet.size() == 1 ? "" : "s";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String> metrics = request.requestedMetrics();
Set<String> metrics = nodeRequest.requestedMetrics();
return nodeService.info(
metrics.contains(NodesInfoMetrics.Metric.SETTINGS.metricName()),
metrics.contains(NodesInfoMetrics.Metric.OS.metricName()),
Expand All @@ -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<String> requestedMetrics() {
return nodesInfoMetrics.requestedMetrics();
}
}
}

0 comments on commit a569b95

Please sign in to comment.