From f7db7eb99e00bb0cf6d9c69b864183463fb6d67e Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Thu, 9 Jan 2014 12:44:05 +0100 Subject: [PATCH] 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. --- .../cluster/node/info/RestNodesInfoAction.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java b/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java index 220e75421602b..fe22ffb6f6462 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.admin.cluster.node.info; +import com.google.common.collect.Sets; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; @@ -43,6 +44,7 @@ public class RestNodesInfoAction extends BaseRestHandler { private final SettingsFilter settingsFilter; + private final static Set ALLOWED_METRICS = Sets.newHashSet("http", "jvm", "network", "os", "plugin", "process", "settings", "thread_pool", "transport"); @Inject public RestNodesInfoAction(Settings settings, Client client, RestController controller, @@ -62,10 +64,20 @@ public RestNodesInfoAction(Settings settings, Client client, RestController cont public void handleRequest(final RestRequest request, final RestChannel channel) { String[] nodeIds; Set metrics; - // special case like /_nodes/fs (in this case fs are metrics and not the nodeId) + + // special case like /_nodes/os (in this case os are metrics and not the nodeId) + // still, /_nodes/_local (or any other node id) should work and be treated as usual + // this means one must differentiate between allowed metrics and arbitrary node ids in the same place if (request.hasParam("nodeId") && !request.hasParam("metrics")) { - nodeIds = new String[] { "_all" }; - metrics = Strings.splitStringByCommaToSet(request.param("nodeId", "_all")); + Set metricsOrNodeIds = Strings.splitStringByCommaToSet(request.param("nodeId", "_all")); + boolean isMetricsOnly = ALLOWED_METRICS.containsAll(metricsOrNodeIds); + if (isMetricsOnly) { + nodeIds = new String[] { "_all" }; + metrics = metricsOrNodeIds; + } else { + nodeIds = metricsOrNodeIds.toArray(new String[]{}); + metrics = Sets.newHashSet("_all"); + } } else { nodeIds = Strings.splitStringByCommaToArray(request.param("nodeId", "_all")); metrics = Strings.splitStringByCommaToSet(request.param("metrics", "_all"));