From b678227f58bfa87917e900399613c5c80ab3cc21 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Mon, 20 Jan 2014 16:31:48 +0100 Subject: [PATCH] [API] [1.0] Update the "Nodes Stats" API to the 1.0 changes Related: elasticsearch/elasticsearch#4057, elasticsearch/elasticsearch#4347 See: http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/_stats_and_info_apis.html --- .../api/actions/cluster/node_stats.rb | 96 ++++++++++--------- .../lib/elasticsearch/api/utils.rb | 2 - .../test/unit/cluster/node_stats_test.rb | 12 +-- 3 files changed, 56 insertions(+), 54 deletions(-) diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/cluster/node_stats.rb b/elasticsearch-api/lib/elasticsearch/api/actions/cluster/node_stats.rb index b838a9b736..ad99646a42 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/cluster/node_stats.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/cluster/node_stats.rb @@ -7,65 +7,69 @@ module Actions # # @example Return statistics about JVM # - # client.cluster.node_stats clear: true, jvm: true + # client.cluster.node_stats metric: 'jvm' # - # @option arguments [List] :metric Limit the information returned for `indices` family to a specific metric - # (options: docs, fielddata, filter_cache, flush, get, id_cache, indexing, merges, - # refresh, search, store, warmer) - # @option arguments [List] :node_id A comma-separated list of node IDs or names to limit the returned information; - # use `_local` to return information from the node you're connecting to, leave - # empty to get information from all nodes - # @option arguments [Boolean] :all Return all available information - # @option arguments [Boolean] :clear Reset the default level of detail - # @option arguments [List] :fields A comma-separated list of fields for `fielddata` metric (supports wildcards) - # @option arguments [Boolean] :fs Return information about the filesystem - # @option arguments [Boolean] :http Return information about HTTP - # @option arguments [Boolean] :indices Return information about indices - # @option arguments [Boolean] :jvm Return information about the JVM - # @option arguments [Boolean] :network Return information about network - # @option arguments [Boolean] :os Return information about the operating system - # @option arguments [Boolean] :process Return information about the Elasticsearch process - # @option arguments [Boolean] :thread_pool Return information about the thread pool - # @option arguments [Boolean] :transport Return information about transport + # @example Return statistics about field data structures for all fields # - # @see http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/ + # client.cluster.node_stats metric: 'indices', index_metric: 'fielddata', fields: '*', human: true + # + # @option arguments [List] :metric Limit the information returned to the specified metrics + # (options: _all, breaker, fs, http, indices, jvm, network, + # os, process, thread_pool, transport) + # @option arguments [List] :index_metric Limit the information returned for the `indices` metric + # to the specified index metrics. Used only when + # `indices` or `all` metric is specified. + # (options: _all, completion, docs, fielddata, filter_cache, flush, get, + # id_cache, indexing, merge, percolate, refresh, search, segments, store, + # warmer) + # @option arguments [List] :node_id A comma-separated list of node IDs or names to limit + # the returned information; use `_local` to return information + # from the node you're connecting to, leave empty to get information + # from all nodes + # @option arguments [List] :completion_fields A comma-separated list of fields for `fielddata` and `suggest` + # index metrics (supports wildcards) + # @option arguments [List] :fielddata_fields A comma-separated list of fields for `fielddata` index metric + # (supports wildcards) + # @option arguments [List] :fields A comma-separated list of fields for `fielddata` and `completion` index + # metrics (supports wildcards) + # @option arguments [Boolean] :groups A comma-separated list of search groups for `search` index metric + # @option arguments [Boolean] :human Whether to return time and byte values in human-readable format + # @option arguments [String] :level Specify the level for aggregating indices stats + # (options: node, indices, shards) + # @option arguments [List] :types A comma-separated list of document types for the `indexing` index metric + # + # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html # def node_stats(arguments={}) + arguments = arguments.clone + valid_params = [ - :all, - :clear, + :metric, + :index_metric, + :node_id, + :completion_fields, + :fielddata_fields, :fields, - :fs, - :http, - :indices, - :jvm, - :network, - :os, - :process, - :thread_pool, - :transport ] + :groups, + :human, + :level, + :types ] method = 'GET' - case - # Field data metric for the `indices` metric family - when arguments[:indices] && arguments[:metric] == 'fielddata' - path = Utils.__pathify '_nodes', Utils.__listify(arguments[:node_id]), 'stats/indices/fielddata' - params = { :fields => Utils.__listify(arguments[:fields]) } - - # `indices` metric family incl. a metric - when arguments[:indices] && arguments[:metric] - path = Utils.__pathify( '_nodes', Utils.__listify(arguments[:node_id]), 'stats/indices', arguments[:metric] ) - params = {} + path = Utils.__pathify '_nodes', + Utils.__listify(arguments[:node_id]), + 'stats', + Utils.__listify(arguments.delete(:metric)), + Utils.__listify(arguments.delete(:index_metric)) - else - path = Utils.__pathify( '_nodes', Utils.__listify(arguments[:node_id]), 'stats' ) + params = Utils.__validate_and_extract_params arguments, valid_params - params = Utils.__validate_and_extract_params arguments, valid_params - params[:fields] = Utils.__listify(params[:fields]) if params[:fields] + [:completion_fields, :fielddata_fields, :fields, :groups, :types].each do |key| + params[key] = Utils.__listify(params[key]) if params[key] end - body = nil + body = nil perform_request(method, path, params, body).body end diff --git a/elasticsearch-api/lib/elasticsearch/api/utils.rb b/elasticsearch-api/lib/elasticsearch/api/utils.rb index 97d0ab1b8d..6c16a0352b 100644 --- a/elasticsearch-api/lib/elasticsearch/api/utils.rb +++ b/elasticsearch-api/lib/elasticsearch/api/utils.rb @@ -30,8 +30,6 @@ def __escape(string) # # @api private def __listify(*list) - # require 'pry' - # binding.pry Array(list).flatten. map { |e| e.respond_to?(:split) ? e.split(',') : e }. flatten. diff --git a/elasticsearch-api/test/unit/cluster/node_stats_test.rb b/elasticsearch-api/test/unit/cluster/node_stats_test.rb index e2586c1a31..bb166cb370 100644 --- a/elasticsearch-api/test/unit/cluster/node_stats_test.rb +++ b/elasticsearch-api/test/unit/cluster/node_stats_test.rb @@ -30,12 +30,12 @@ class ClusterNodeStatsTest < ::Test::Unit::TestCase should "get specific metric families" do subject.expects(:perform_request).with do |method, url, params, body| - assert_equal '_nodes/stats', url - assert_equal( {:http => true, :fs => true}, params ) + assert_equal '_nodes/stats/http,fs', url + assert_equal( {}, params ) true end.returns(FakeResponse.new) - subject.cluster.node_stats :http => true, :fs => true + subject.cluster.node_stats :metric => [:http, :fs] end should "get specific metric for the indices family" do @@ -44,7 +44,7 @@ class ClusterNodeStatsTest < ::Test::Unit::TestCase true end.returns(FakeResponse.new) - subject.cluster.node_stats :indices => true, :metric => 'filter_cache' + subject.cluster.node_stats :metric => :indices, :index_metric => 'filter_cache' end should "get fielddata statistics for the indices family" do @@ -54,8 +54,8 @@ class ClusterNodeStatsTest < ::Test::Unit::TestCase true end.returns(FakeResponse.new).twice - subject.cluster.node_stats :indices => true, :metric => 'fielddata', :fields => 'foo,bar' - subject.cluster.node_stats :indices => true, :metric => 'fielddata', :fields => ['foo','bar'] + subject.cluster.node_stats :metric => 'indices', :index_metric => 'fielddata', :fields => 'foo,bar' + subject.cluster.node_stats :metric => 'indices', :index_metric => 'fielddata', :fields => ['foo','bar'] end end