Skip to content

Commit f7db7eb

Browse files
committed
Improve nodes/metric detection in RestNodesInfo
Because one URI parameter can contain either nodeIds or a list of metrics, the check to detect if this parameter is either a nodeId or a metric needs to be more accurate.
1 parent dbecc71 commit f7db7eb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java

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

2020
package org.elasticsearch.rest.action.admin.cluster.node.info;
2121

22+
import com.google.common.collect.Sets;
2223
import org.elasticsearch.action.ActionListener;
2324
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
2425
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
@@ -43,6 +44,7 @@
4344
public class RestNodesInfoAction extends BaseRestHandler {
4445

4546
private final SettingsFilter settingsFilter;
47+
private final static Set<String> ALLOWED_METRICS = Sets.newHashSet("http", "jvm", "network", "os", "plugin", "process", "settings", "thread_pool", "transport");
4648

4749
@Inject
4850
public RestNodesInfoAction(Settings settings, Client client, RestController controller,
@@ -62,10 +64,20 @@ public RestNodesInfoAction(Settings settings, Client client, RestController cont
6264
public void handleRequest(final RestRequest request, final RestChannel channel) {
6365
String[] nodeIds;
6466
Set<String> metrics;
65-
// special case like /_nodes/fs (in this case fs are metrics and not the nodeId)
67+
68+
// special case like /_nodes/os (in this case os are metrics and not the nodeId)
69+
// still, /_nodes/_local (or any other node id) should work and be treated as usual
70+
// this means one must differentiate between allowed metrics and arbitrary node ids in the same place
6671
if (request.hasParam("nodeId") && !request.hasParam("metrics")) {
67-
nodeIds = new String[] { "_all" };
68-
metrics = Strings.splitStringByCommaToSet(request.param("nodeId", "_all"));
72+
Set<String> metricsOrNodeIds = Strings.splitStringByCommaToSet(request.param("nodeId", "_all"));
73+
boolean isMetricsOnly = ALLOWED_METRICS.containsAll(metricsOrNodeIds);
74+
if (isMetricsOnly) {
75+
nodeIds = new String[] { "_all" };
76+
metrics = metricsOrNodeIds;
77+
} else {
78+
nodeIds = metricsOrNodeIds.toArray(new String[]{});
79+
metrics = Sets.newHashSet("_all");
80+
}
6981
} else {
7082
nodeIds = Strings.splitStringByCommaToArray(request.param("nodeId", "_all"));
7183
metrics = Strings.splitStringByCommaToSet(request.param("metrics", "_all"));

0 commit comments

Comments
 (0)