Skip to content

Commit 7539fbb

Browse files
olegbonarDaveCTurner
authored andcommitted
Deprecate the 'local' parameter of /_cat/nodes (#50499)
The cat nodes API performs a `ClusterStateAction` then a `NodesInfoAction`. Today it accepts the `?local` parameter and passes this to the `ClusterStateAction` but this parameter has no effect on the `NodesInfoAction`. This is surprising, because `GET _cat/nodes?local` looks like it might be a completely local call but in fact it still depends on every node in the cluster. This commit deprecates the `?local` parameter on this API so that it can be removed in 8.0. Relates #50088
1 parent 4ecabe4 commit 7539fbb

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

docs/reference/cat/nodes.asciidoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ Number of suggest operations, such as `0`.
286286
include::{docdir}/rest-api/common-parms.asciidoc[tag=help]
287287

288288
include::{docdir}/rest-api/common-parms.asciidoc[tag=local]
289+
+
290+
--
291+
`local`::
292+
(Optional, boolean) If `true`, the request computes the list of selected nodes
293+
from the local cluster state. Defaults to `false`, which means the list of
294+
selected nodes is computed from the cluster state on the master node. In either
295+
case the coordinating node sends a request for further information to each
296+
selected node. deprecated::[7.6,This parameter does not cause this API to act
297+
locally. It will be removed in version 8.0.]
298+
--
289299

290300
include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout]
291301

rest-api-spec/src/main/resources/rest-api-spec/api/cat.nodes.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343
},
4444
"local":{
4545
"type":"boolean",
46-
"description":"Return local information, do not retrieve the state from master node (default: false)"
46+
"description":"Calculate the selected nodes using the local cluster state rather than the state from master node (default: false)",
47+
"deprecated":{
48+
"version":"7.6.0",
49+
"description":"This parameter does not cause this API to act locally."
50+
}
4751
},
4852
"master_timeout":{
4953
"type":"time",

server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.rest.action.cat;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
2324
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
2425
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
@@ -33,6 +34,7 @@
3334
import org.elasticsearch.cluster.node.DiscoveryNodes;
3435
import org.elasticsearch.common.Strings;
3536
import org.elasticsearch.common.Table;
37+
import org.elasticsearch.common.logging.DeprecationLogger;
3638
import org.elasticsearch.common.network.NetworkAddress;
3739
import org.elasticsearch.common.transport.TransportAddress;
3840
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -67,6 +69,10 @@
6769
import static org.elasticsearch.rest.RestRequest.Method.GET;
6870

6971
public class RestNodesAction extends AbstractCatAction {
72+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
73+
LogManager.getLogger(RestNodesAction.class));
74+
static final String LOCAL_DEPRECATED_MESSAGE = "Deprecated parameter [local] used. This parameter does not cause this API to act " +
75+
"locally, and should not be used. It will be unsupported in version 8.0.";
7076

7177
public RestNodesAction(RestController controller) {
7278
controller.registerHandler(GET, "/_cat/nodes", this);
@@ -86,6 +92,9 @@ protected void documentation(StringBuilder sb) {
8692
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
8793
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
8894
clusterStateRequest.clear().nodes(true);
95+
if (request.hasParam("local")) {
96+
deprecationLogger.deprecated(LOCAL_DEPRECATED_MESSAGE);
97+
}
8998
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
9099
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
91100
final boolean fullId = request.paramAsBoolean("full_id", false);

server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
2424
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
2525
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
26+
import org.elasticsearch.client.node.NodeClient;
2627
import org.elasticsearch.cluster.ClusterName;
2728
import org.elasticsearch.cluster.ClusterState;
2829
import org.elasticsearch.cluster.node.DiscoveryNode;
2930
import org.elasticsearch.cluster.node.DiscoveryNodes;
31+
import org.elasticsearch.common.settings.Settings;
3032
import org.elasticsearch.rest.RestController;
3133
import org.elasticsearch.test.ESTestCase;
3234
import org.elasticsearch.test.rest.FakeRestRequest;
35+
import org.elasticsearch.threadpool.TestThreadPool;
3336
import org.elasticsearch.usage.UsageService;
3437
import org.junit.Before;
3538

@@ -65,4 +68,16 @@ public void testBuildTableDoesNotThrowGivenNullNodeInfoAndStats() {
6568

6669
action.buildTable(false, new FakeRestRequest(), clusterStateResponse, nodesInfoResponse, nodesStatsResponse);
6770
}
71+
72+
public void testCatNodesWithLocalDeprecationWarning() {
73+
TestThreadPool threadPool = new TestThreadPool(RestNodesActionTests.class.getName());
74+
NodeClient client = new NodeClient(Settings.EMPTY, threadPool);
75+
FakeRestRequest request = new FakeRestRequest();
76+
request.params().put("local", randomFrom("", "true", "false"));
77+
78+
action.doCatRequest(request, client);
79+
assertWarnings(RestNodesAction.LOCAL_DEPRECATED_MESSAGE);
80+
81+
terminate(threadPool);
82+
}
6883
}

0 commit comments

Comments
 (0)