Skip to content

Commit

Permalink
[API] [1.0] Update the "Nodes Stats" API to the 1.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
karmi committed Jan 29, 2014
1 parent e9c8f92 commit db00584
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 54 deletions.
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions elasticsearch-api/lib/elasticsearch/api/utils.rb
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions elasticsearch-api/test/unit/cluster/node_stats_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit db00584

Please sign in to comment.