19
19
20
20
package org .elasticsearch .rest .action .admin .cluster .node .info ;
21
21
22
+ import com .google .common .collect .Sets ;
22
23
import org .elasticsearch .action .ActionListener ;
23
24
import org .elasticsearch .action .admin .cluster .node .info .NodesInfoRequest ;
24
25
import org .elasticsearch .action .admin .cluster .node .info .NodesInfoResponse ;
43
44
public class RestNodesInfoAction extends BaseRestHandler {
44
45
45
46
private final SettingsFilter settingsFilter ;
47
+ private final static Set <String > ALLOWED_METRICS = Sets .newHashSet ("http" , "jvm" , "network" , "os" , "plugin" , "process" , "settings" , "thread_pool" , "transport" );
46
48
47
49
@ Inject
48
50
public RestNodesInfoAction (Settings settings , Client client , RestController controller ,
@@ -62,10 +64,20 @@ public RestNodesInfoAction(Settings settings, Client client, RestController cont
62
64
public void handleRequest (final RestRequest request , final RestChannel channel ) {
63
65
String [] nodeIds ;
64
66
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
66
71
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
+ }
69
81
} else {
70
82
nodeIds = Strings .splitStringByCommaToArray (request .param ("nodeId" , "_all" ));
71
83
metrics = Strings .splitStringByCommaToSet (request .param ("metrics" , "_all" ));
0 commit comments