Class: NewRelic::ElasticsearchOperationResolver
- Inherits:
-
Object
- Object
- NewRelic::ElasticsearchOperationResolver
- Defined in:
- lib/newrelic/elasticsearch/operation_resolver.rb
Defined Under Namespace
Modules: Inflector
Constant Summary collapse
- ELASTICSEARCH_OPERATION_NAMES =
{ [ "PUT", nil ] => :ambiguous_put_resolver, [ "POST", nil ] => :ambiguous_post_resolver, [ "HEAD", nil ] => :ambiguous_head_resolver, [ "GET", nil ] => :ambiguous_get_resolver, [ "DELETE", nil ] => :ambiguous_delete_resolver, [ "HEAD", "_alias" ] => "AliasesExist", [ "PUT", "_alias" ] => "IndexPutAlias", [ "DELETE", "_alias" ] => "IndexDeleteAliases", [ "GET", "_alias" ] => "GetAliases", [ "GET", "_aliases" ] => "GetIndicesAliases", [ "POST", "_aliases" ] => "IndicesAliases", [ "GET", "_analyze" ] => "Analyze", [ "POST", "_analyze" ] => "Analyze", [ "POST", "_bulk" ] => "Bulk", [ "PUT", "_bulk" ] => "Bulk", [ "GET", "_cache" ] => "ClearIndicesCache", [ "POST", "_cache" ] => "ClearIndicesCache", [ "GET", "_cat" ] => :ambiguous_cat_resolver, [ "POST", "_close" ] => "CloseIndex", [ "POST", "_cluster" ] => "ClusterReroute", [ "GET", "_cluster" ] => :ambiguous_cluster_resolver, [ "PUT", "_cluster" ] => "ClusterUpdateSettings", [ "GET", "_count" ] => "Count", [ "POST", "_count" ] => "Count", [ "POST", "_create" ] => "CreateDocument", [ "PUT", "_create" ] => "CreateDocument", [ "GET", "_explain" ] => "Explain", [ "POST", "_explain" ] => "Explain", [ "GET", "_flush" ] => "Flush", [ "POST", "_flush" ] => "Flush", [ "POST", "_gateway" ] => "GatewaySnapshot", [ "GET", "_id" ] => "SearchScroll", [ "DELETE", "_id" ] => "ClearScroll", [ "POST", "_id" ] => "SearchScroll", [ "POST", "_mapping" ] => "PutMapping", [ "PUT", "_mapping" ] => "PutMapping", [ "GET", "_mapping" ] => "GetMapping", [ "DELETE", "_mapping" ] => "DeleteMapping", [ "POST", "_mget" ] => "MultiGet", [ "GET", "_mget" ] => "MultiGet", [ "GET", "_mlt" ] => "MoreLikeThis", [ "POST", "_mlt" ] => "MoreLikeThis", [ "POST", "_mpercolate" ] => "MultiPercolate", [ "POST", "_msearch" ] => "MultiSearch", [ "GET", "_msearch" ] => "MultiSearch", [ "POST", "_mtermvectors" ] => "MultiTermVectors", [ "GET", "_mtermvectors" ] => "MultiTermVectors", [ "GET", "_nodes" ] => :ambiguous_nodes_resolver, [ "POST", "_open" ] => "OpenIndex", [ "POST", "_optimize" ] => "Optimize", [ "GET", "_optimize" ] => "Optimize", [ "GET", "_percolate" ] => :ambiguous_percolate_resolver, [ "POST", "_percolate" ] => :ambiguous_percolate_resolver, [ "DELETE", "_query" ] => "DeleteByQuery", [ "GET", "_refresh" ] => "Refresh", [ "POST", "_refresh" ] => "Refresh", [ "POST", "_reindex" ] => "Reindex", [ "POST", "_restart" ] => "NodesRestart", [ "GET", "_search" ] => :ambiguous_search_resolver, [ "POST", "_search" ] => :ambiguous_search_resolver, [ "DELETE", "_search" ] => "ClearScroll", [ "GET", "_segments" ] => "IndicesSegments", [ "PUT", "_settings" ] => "UpdateSettings", [ "GET", "_settings" ] => "GetSettings", [ "GET", "_search_shards" ] => "ClusterSearchShards", [ "POST", "_search__shards" ] => "ClusterSearchShards", [ "POST", "_shutdown" ] => "NodesShutdown", [ "HEAD", "_source" ] => "HeadSource", [ "GET", "_source" ] => "GetSource", [ "GET", "_stats" ] => :ambiguous_stats_resolver, [ "GET", "_status" ] => "IndicesStatus", [ "GET", "_suggest" ] => "Suggest", [ "POST", "_suggest" ] => "Suggest", [ "POST", "_template" ] => "PutIndexTemplate", [ "PUT", "_template" ] => "PutIndexTemplate", [ "DELETE", "_template" ] => "DeleteIndexTemplate", [ "GET", "_template" ] => "GetIndexTemplate", [ "HEAD", "_template" ] => "HeadIndexTemplate", [ "GET", "_termvector" ] => "TermVector", [ "POST", "_termvector" ] => "TermVector", [ "GET", "_threads" ] => "NodesHotThreads", [ "POST", "_update" ] => "Update", [ "GET", "_validate" ] => "ValidateQuery", [ "POST", "_validate" ] => "ValidateQuery", [ "GET", "_warmer" ] => "GetWarmer", [ "PUT", "_warmer" ] => "PutWarmer", [ "DELETE", "_warmer" ] => "DeleteWarmer" }
- AMBIGUOUS_API_OPS =
{ 0 => 'Server', 1 => 'Index', 2 => 'Type', 3 => 'Document' }
- AMBIGOUS_CAT_OPS =
{ "indices" => "Indices", "master" => "Cluster", "nodes" => "Nodes", "shards" => "Shards", "aliases" => "Aliases" }
Instance Attribute Summary collapse
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #ambiguous_cat_resolver ⇒ Object
- #ambiguous_cluster_resolver ⇒ Object
- #ambiguous_delete_resolver ⇒ Object
- #ambiguous_get_resolver ⇒ Object
- #ambiguous_head_resolver ⇒ Object
- #ambiguous_nodes_resolver ⇒ Object
- #ambiguous_percolate_resolver ⇒ Object
- #ambiguous_put_resolver ⇒ Object (also: #ambiguous_post_resolver)
- #ambiguous_search_resolver ⇒ Object
- #ambiguous_stats_resolver ⇒ Object
- #api_name ⇒ Object
- #id ⇒ Object
- #index ⇒ Object
-
#initialize(http_method, path) ⇒ ElasticsearchOperationResolver
constructor
A new instance of ElasticsearchOperationResolver.
- #op_index ⇒ Object
- #operands ⇒ Object
- #operation_name ⇒ Object
- #path_components ⇒ Object
- #scope ⇒ Object
- #scope_path ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(http_method, path) ⇒ ElasticsearchOperationResolver
Returns a new instance of ElasticsearchOperationResolver.
125 126 127 128 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 125 def initialize(http_method, path) @http_method = http_method @path = path end |
Instance Attribute Details
#http_method ⇒ Object
Returns the value of attribute http_method.
121 122 123 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 121 def http_method @http_method end |
#path ⇒ Object
Returns the value of attribute path.
121 122 123 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 121 def path @path end |
Instance Method Details
#ambiguous_cat_resolver ⇒ Object
205 206 207 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 205 def ambiguous_cat_resolver "Cat" + AMBIGOUS_CAT_OPS[operands.first] end |
#ambiguous_cluster_resolver ⇒ Object
225 226 227 228 229 230 231 232 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 225 def ambiguous_cluster_resolver case operands.join('/') when /pending_tasks/ then "ClusterPendingTasks" when /nodes\/_restart/ then "NodesRestart" when /nodes\/(.*?)\/_restart/ then "NodesRestart" when /nodes\/(>*?)\/_shutdown/ then "NodesShutdown" end end |
#ambiguous_delete_resolver ⇒ Object
201 202 203 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 201 def ambiguous_delete_resolver AMBIGUOUS_API_OPS[scope.count] + "Delete" end |
#ambiguous_get_resolver ⇒ Object
197 198 199 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 197 def ambiguous_get_resolver AMBIGUOUS_API_OPS[scope.count] + "Get" end |
#ambiguous_head_resolver ⇒ Object
193 194 195 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 193 def ambiguous_head_resolver AMBIGUOUS_API_OPS[scope.count] + "Exists" end |
#ambiguous_nodes_resolver ⇒ Object
209 210 211 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 209 def ambiguous_nodes_resolver "Node" + operands[1..-1].map{ |s| s.legalize }.join end |
#ambiguous_percolate_resolver ⇒ Object
213 214 215 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 213 def ambiguous_percolate_resolver "Percolate" + operands.first.to_s end |
#ambiguous_put_resolver ⇒ Object Also known as: ambiguous_post_resolver
187 188 189 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 187 def ambiguous_put_resolver AMBIGUOUS_API_OPS[scope.count] + "Create" end |
#ambiguous_search_resolver ⇒ Object
217 218 219 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 217 def ambiguous_search_resolver "Search" + operands.first.to_s end |
#ambiguous_stats_resolver ⇒ Object
221 222 223 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 221 def ambiguous_stats_resolver "Indicies" + operands.map { |s| s.legalize }.join end |
#api_name ⇒ Object
152 153 154 155 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 152 def api_name return nil if op_index.nil? path_components[op_index] end |
#id ⇒ Object
179 180 181 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 179 def id scope[2] end |
#index ⇒ Object
169 170 171 172 173 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 169 def index index = scope[0] return nil unless index index.legalize unless index.start_with?('_') end |
#op_index ⇒ Object
183 184 185 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 183 def op_index @op_index ||= path_components.index { |c| c.start_with?('_') } end |
#operands ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 144 def operands if api_name.nil? [] else path_components[op_index + 1 .. -1] end end |
#operation_name ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 130 def operation_name resolved = ELASTICSEARCH_OPERATION_NAMES[[http_method, api_name]] case resolved when Symbol send(resolved) else resolved end end |
#path_components ⇒ Object
140 141 142 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 140 def path_components @path_components ||= CGI::unescape(path).split('/').reject { |s| s.empty? } end |
#scope ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 157 def scope if api_name.nil? path_components else path_components[0 .. (op_index - 1)] end end |
#scope_path ⇒ Object
165 166 167 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 165 def scope_path scope.join("_") end |
#type ⇒ Object
175 176 177 |
# File 'lib/newrelic/elasticsearch/operation_resolver.rb', line 175 def type scope[1].legalize end |