Skip to content

Commit

Permalink
Query ESQL usage stats from new nodes only (elastic#98617)
Browse files Browse the repository at this point in the history
The new ESQL stats action doesn't exist on old nodes; 
so we should avoid sending stats-requests to those nodes.

Closes elastic#98604
  • Loading branch information
dnhatn authored Aug 17, 2023
1 parent e2b0d7b commit 6019f38
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
*/
package org.elasticsearch.xpack.esql.plugin;

import org.elasticsearch.Version;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.nodes.TransportNodesAction;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
Expand All @@ -19,6 +21,7 @@
import org.elasticsearch.xpack.esql.execution.PlanExecutor;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -54,6 +57,16 @@ public TransportEsqlStatsAction(
this.planExecutor = planExecutor;
}

@Override
protected void resolveRequest(EsqlStatsRequest request, ClusterState clusterState) {
String[] nodesIds = clusterState.nodes().resolveNodes(request.nodesIds());
DiscoveryNode[] concreteNodes = Arrays.stream(nodesIds)
.map(clusterState.nodes()::get)
.filter(n -> n.getVersion().onOrAfter(Version.V_8_11_0))
.toArray(DiscoveryNode[]::new);
request.setConcreteNodes(concreteNodes);
}

@Override
protected EsqlStatsResponse newResponse(
EsqlStatsRequest request,
Expand Down

0 comments on commit 6019f38

Please sign in to comment.