Skip to content

Commit

Permalink
Set includeShardsStats = false in NodesStatsRequest where the caller …
Browse files Browse the repository at this point in the history
…does not use shards-level statistics (#100938)

Relates #100466
  • Loading branch information
NEUpanning authored Nov 23, 2023
1 parent a9c286b commit 6cf4c80
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/100938.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 100938
summary: "Set includeShardsStats = false in NodesStatsRequest where the caller does not use shards-level statistics"
area: Stats
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public void onFailure(Exception e) {

private void fetchNodeStats() {
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
nodesStatsRequest.setIncludeShardsStats(false);
nodesStatsRequest.clear();
nodesStatsRequest.addMetric(NodesStatsRequest.Metric.FS.metricName());
nodesStatsRequest.timeout(fetchTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli
@Override
public void processResponse(final ClusterStateResponse state) {
NodesStatsRequest statsRequest = new NodesStatsRequest(nodes);
statsRequest.setIncludeShardsStats(false);
statsRequest.clear()
.addMetric(NodesStatsRequest.Metric.FS.metricName())
.indices(new CommonStatsFlags(CommonStatsFlags.Flag.Store));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public String getName() {
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
nodesStatsRequest.setIncludeShardsStats(false);
nodesStatsRequest.clear();
nodesStatsRequest.indices(true);
String[] fields = request.paramAsStringArray("fields", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli
);

final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
nodesStatsRequest.setIncludeShardsStats(false);
nodesStatsRequest.clear()
.indices(true)
.addMetrics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void processResponse(final ClusterStateResponse clusterStateResponse) {
@Override
public void processResponse(final NodesInfoResponse nodesInfoResponse) {
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
nodesStatsRequest.setIncludeShardsStats(false);
nodesStatsRequest.clear().addMetric(NodesStatsRequest.Metric.THREAD_POOL.metricName());
client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public List<Route> routes() {
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
var nodesStatsRequest = new NodesStatsRequest().clear();
nodesStatsRequest.setIncludeShardsStats(false);
var targets = Strings.tokenizeByCommaToSet(request.param("target"));

if (targets.size() == 1 && targets.contains("_all")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ private void sendToMissingNodes(Function<String, DiscoveryNode> nodeLookup, Set<
nodeToMemory = Collections.unmodifiableMap(builder);
}
};
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(
missingNodes.stream().map(DiscoveryNode::getId).toArray(String[]::new)
).clear().addMetric(NodesStatsRequest.Metric.OS.metricName()).timeout(fetchTimeout);
nodesStatsRequest.setIncludeShardsStats(false);
client.admin()
.cluster()
.nodesStats(
new NodesStatsRequest(missingNodes.stream().map(DiscoveryNode::getId).toArray(String[]::new)).clear()
.addMetric(NodesStatsRequest.Metric.OS.metricName())
.timeout(fetchTimeout),
nodesStatsRequest,
ActionListener.wrap(
nodesStatsResponse -> client.admin()
.cluster()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ static NodesStatsRequest nodeStatsRequest(ClusterState state, TaskId parentTaskI
String[] ingestNodes = state.nodes().getIngestNodes().keySet().toArray(String[]::new);
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(ingestNodes).clear()
.addMetric(NodesStatsRequest.Metric.INGEST.metricName());
nodesStatsRequest.setIncludeShardsStats(false);
nodesStatsRequest.setParentTask(parentTaskId);
return nodesStatsRequest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected boolean shouldCollect(final boolean isElectedMaster) {
@Override
protected Collection<MonitoringDoc> doCollect(final MonitoringDoc.Node node, final long interval, final ClusterState clusterState) {
NodesStatsRequest request = new NodesStatsRequest("_local");
request.setIncludeShardsStats(false);
request.indices(FLAGS);
request.addMetrics(
NodesStatsRequest.Metric.OS.metricName(),
Expand Down

0 comments on commit 6cf4c80

Please sign in to comment.