elasticsearch-transport 5.0.5 → 6.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +5 -0
  3. data/README.md +88 -34
  4. data/Rakefile +14 -17
  5. data/elasticsearch-transport.gemspec +45 -63
  6. data/lib/elasticsearch/transport/client.rb +207 -67
  7. data/lib/elasticsearch/transport/redacted.rb +79 -0
  8. data/lib/elasticsearch/transport/transport/base.rb +28 -14
  9. data/lib/elasticsearch/transport/transport/connections/collection.rb +4 -0
  10. data/lib/elasticsearch/transport/transport/connections/connection.rb +5 -1
  11. data/lib/elasticsearch/transport/transport/connections/selector.rb +4 -0
  12. data/lib/elasticsearch/transport/transport/errors.rb +4 -0
  13. data/lib/elasticsearch/transport/transport/http/curb.rb +7 -2
  14. data/lib/elasticsearch/transport/transport/http/faraday.rb +11 -8
  15. data/lib/elasticsearch/transport/transport/http/manticore.rb +6 -1
  16. data/lib/elasticsearch/transport/transport/response.rb +4 -0
  17. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +4 -0
  18. data/lib/elasticsearch/transport/transport/sniffer.rb +31 -3
  19. data/lib/elasticsearch/transport/version.rb +5 -1
  20. data/lib/elasticsearch/transport.rb +5 -0
  21. data/lib/elasticsearch-transport.rb +4 -0
  22. data/spec/elasticsearch/transport/base_spec.rb +260 -0
  23. data/spec/elasticsearch/transport/client_spec.rb +1063 -0
  24. data/spec/elasticsearch/transport/meta_header_spec.rb +214 -0
  25. data/spec/elasticsearch/transport/sniffer_spec.rb +269 -0
  26. data/spec/spec_helper.rb +72 -0
  27. data/test/integration/transport_test.rb +9 -5
  28. data/test/profile/client_benchmark_test.rb +23 -25
  29. data/test/test_helper.rb +10 -0
  30. data/test/unit/connection_collection_test.rb +4 -0
  31. data/test/unit/connection_selector_test.rb +4 -0
  32. data/test/unit/connection_test.rb +4 -0
  33. data/test/unit/response_test.rb +5 -1
  34. data/test/unit/serializer_test.rb +4 -0
  35. data/test/unit/transport_base_test.rb +21 -1
  36. data/test/unit/transport_curb_test.rb +12 -0
  37. data/test/unit/transport_faraday_test.rb +16 -0
  38. data/test/unit/transport_manticore_test.rb +11 -0
  39. metadata +90 -76
  40. data/test/integration/client_test.rb +0 -237
  41. data/test/unit/client_test.rb +0 -366
  42. data/test/unit/sniffer_test.rb +0 -179
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9141220bdecbb5cd5fe9eef893010d24419a62a6
4
- data.tar.gz: e2a2ad61469a9398e749b4004909ec2234360262
2
+ SHA256:
3
+ metadata.gz: 84ce4d26d5dd03b5bc17d89e4ce0a873b5d57083f07cf54cf78552d7e88ff61f
4
+ data.tar.gz: 69b164ec36cd3cb2ee3355c0806a0109e21a69ca605a9f87b020f9d8476e5096
5
5
  SHA512:
6
- metadata.gz: 47916a61140347aba5eb71728587d4c611f0219e8f03d3584405fde93d10fe991f38652b5125e073ad37f16cedd72fe452faea82197f892b539c95809db5cf74
7
- data.tar.gz: 9130c01c4a9d7687f42fa57848c3dac0ae7382972e1c68776319c829b079307ccda469846f6231e2e64c783225c43a75386d35b6de8f3d5614516266d24e80c8
6
+ metadata.gz: e6a9fb8c521ffedd0faf79006e477e4360a2af6df876cee41ddd87278ddf06de34a69e9ccbdad0d83629a0cf1c52d0eefbf4facdb38a591a219c156a5d7d3fdf
7
+ data.tar.gz: 2d729907c495a2946b68a193262b14261534d6811b2ea5517248977758ed869c3c2803284ff69bc9b9f5a863a9440a9f675f53287f136e5813677b95b1d106c8
data/Gemfile CHANGED
@@ -14,3 +14,8 @@ end
14
14
  if File.exist? File.expand_path("../../elasticsearch/elasticsearch.gemspec", __FILE__)
15
15
  gem 'elasticsearch', :path => File.expand_path("../../elasticsearch", __FILE__), :require => false
16
16
  end
17
+
18
+ group :development do
19
+ gem 'rspec'
20
+ gem 'pry-nav'
21
+ end
data/README.md CHANGED
@@ -16,24 +16,28 @@ data serialization and transport.
16
16
  It does not handle calling the Elasticsearch API;
17
17
  see the [`elasticsearch-api`](https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-api) library.
18
18
 
19
- The library is compatible with Ruby 1.8.7 or higher and with all versions of Elasticsearch since 0.90.
19
+ The library is compatible with Ruby 1.9 or higher and with all versions of Elasticsearch since 0.90.
20
20
 
21
21
  Features overview:
22
22
 
23
23
  * Pluggable logging and tracing
24
- * Plugabble connection selection strategies (round-robin, random, custom)
24
+ * Pluggable connection selection strategies (round-robin, random, custom)
25
25
  * Pluggable transport implementation, customizable and extendable
26
26
  * Pluggable serializer implementation
27
27
  * Request retries and dead connections handling
28
28
  * Node reloading (based on cluster state) on errors or on demand
29
29
 
30
30
  For optimal performance, use a HTTP library which supports persistent ("keep-alive") connections,
31
- such as [Typhoeus](https://github.com/typhoeus/typhoeus).
32
- Just require the library (`require 'typhoeus'; require 'typhoeus/adapters/faraday'`) in your code,
33
- and it will be automatically used; currently these libraries will be automatically detected and used:
34
- [Patron](https://github.com/toland/patron),
35
- [HTTPClient](https://rubygems.org/gems/httpclient) and
36
- [Net::HTTP::Persistent](https://rubygems.org/gems/net-http-persistent).
31
+ such as [patron](https://github.com/toland/patron) or [Typhoeus](https://github.com/typhoeus/typhoeus).
32
+ Just require the library (`require 'patron'`) in your code, and it will be automatically used.
33
+
34
+ Currently these libraries will be automatically detected and used:
35
+ - [Patron](https://github.com/toland/patron)
36
+ - [Typhoeus](https://github.com/typhoeus/typhoeus)
37
+ - [HTTPClient](https://rubygems.org/gems/httpclient)
38
+ - [Net::HTTP::Persistent](https://rubygems.org/gems/net-http-persistent)
39
+
40
+ **Note on [Typhoeus](https://github.com/typhoeus/typhoeus)**: You need to use v1.4.0 or up since older versions are not compatible with Faraday 1.0.
37
41
 
38
42
  For detailed information, see example configurations [below](#transport-implementations).
39
43
 
@@ -69,6 +73,22 @@ Full documentation is available at <http://rubydoc.info/gems/elasticsearch-trans
69
73
 
70
74
  ## Configuration
71
75
 
76
+ * [Setting Hosts](#setting-hosts)
77
+ * [Default port](#default-port)
78
+ * [Connect using an Elastic Cloud ID](#connect-using-an-elastic-cloud-id)
79
+ * [Authentication](#authentication)
80
+ * [Logging](#logging)
81
+ * [Identifying running tasks with X-Opaque-Id](#identifying-running-tasks-with-x-opaque-id)
82
+ * [Setting Timeouts](#setting-timeouts)
83
+ * [Randomizing Hosts](#randomizing-hosts)
84
+ * [Retrying on Failures](#retrying-on-failures)
85
+ * [Reloading Hosts](#reloading-hosts)
86
+ * [Connection Selector](#connection-selector)
87
+ * [Transport Implementations](#transport-implementations)
88
+ * [Serializer implementations](#serializer-implementations)
89
+ * [Exception Handling](#exception-handling)
90
+ * [Development and Community](#development-and-community)
91
+
72
92
  The client supports many configurations options for setting up and managing connections,
73
93
  configuring logging, customizing the transport library, etc.
74
94
 
@@ -128,6 +148,26 @@ use the `transport_options` option:
128
148
  Elasticsearch::Client.new url: 'https://username:password@example.com:9200',
129
149
  transport_options: { ssl: { ca_file: '/path/to/cacert.pem' } }
130
150
 
151
+ You can also use [**API Key authentication**](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html):
152
+
153
+ ``` ruby
154
+ Elasticsearch::Client.new(
155
+ host: host,
156
+ transport_options: transport_options,
157
+ api_key: credentials
158
+ )
159
+ ```
160
+
161
+ Where credentials is either the base64 encoding of `id` and `api_key` joined by a colon or a hash with the `id` and `api_key`:
162
+
163
+ ``` ruby
164
+ Elasticsearch::Client.new(
165
+ host: host,
166
+ transport_options: transport_options,
167
+ api_key: {id: 'my_id', api_key: 'my_api_key'}
168
+ )
169
+ ```
170
+
131
171
  ### Logging
132
172
 
133
173
  To log requests and responses to standard output with the default logger (an instance of Ruby's {::Logger} class),
@@ -158,6 +198,29 @@ You can pass the client any conforming logger implementation:
158
198
 
159
199
  client = Elasticsearch::Client.new logger: log
160
200
 
201
+ ### Identifying running tasks with X-Opaque-Id
202
+
203
+ The X-Opaque-Id header allows to track certain calls, or associate certain tasks with the client that started them ([more on the Elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html#_identifying_running_tasks)). To use this feature, you need to set an id for `opaque_id` on the client on each request. Example:
204
+
205
+ ```ruby
206
+ client = Elasticsearch::Client.new
207
+ client.search(index: 'myindex', q: 'title:test', opaque_id: '123456')
208
+ ```
209
+ The search request will include the following HTTP Header:
210
+ ```
211
+ X-Opaque-Id: 123456
212
+ ```
213
+
214
+ You can also set a prefix for X-Opaque-Id when initializing the client. This will be prepended to the id you set before each request if you're using X-Opaque-Id. Example:
215
+ ```ruby
216
+ client = Elasticsearch::Client.new(opaque_id_prefix: 'eu-west1')
217
+ client.search(index: 'myindex', q: 'title:test', opaque_id: '123456')
218
+ ```
219
+ The request will include the following HTTP Header:
220
+ ```
221
+ X-Opaque-Id: eu-west1_123456
222
+ ```
223
+
161
224
  ### Setting Timeouts
162
225
 
163
226
  For many operations in Elasticsearch, the default timeouts of HTTP libraries are too low.
@@ -292,44 +355,35 @@ constructor, use the `transport_options` key:
292
355
 
293
356
  To configure the _Faraday_ instance directly, use a block:
294
357
 
295
- require 'typhoeus'
296
- require 'typhoeus/adapters/faraday'
358
+ require 'patron'
297
359
 
298
360
  client = Elasticsearch::Client.new(host: 'localhost', port: '9200') do |f|
299
361
  f.response :logger
300
- f.adapter :typhoeus
362
+ f.adapter :patron
301
363
  end
302
364
 
303
- You can use any standard Faraday middleware and plugins in the configuration block,
304
- for example sign the requests for the [AWS Elasticsearch service](https://aws.amazon.com/elasticsearch-service/):
305
-
306
- require 'faraday_middleware/aws_signers_v4'
307
-
308
- client = Elasticsearch::Client.new url: 'https://search-my-cluster-abc123....es.amazonaws.com' do |f|
309
- f.request :aws_signers_v4,
310
- credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET_ACCESS_KEY']),
311
- service_name: 'es',
312
- region: 'us-east-1'
313
- end
365
+ You can use any standard Faraday middleware and plugins in the configuration block, for example sign the requests for the [AWS Elasticsearch service](https://aws.amazon.com/elasticsearch-service/). See [the AWS documentation](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html#es-request-signing-ruby) for an example.
314
366
 
315
367
  You can also initialize the transport class yourself, and pass it to the client constructor
316
368
  as the `transport` argument:
317
369
 
318
- require 'typhoeus'
319
- require 'typhoeus/adapters/faraday'
370
+ ```ruby
371
+ require 'patron'
320
372
 
321
- transport_configuration = lambda do |f|
322
- f.response :logger
323
- f.adapter :typhoeus
324
- end
373
+ transport_configuration = lambda do |f|
374
+ f.response :logger
375
+ f.adapter :patron
376
+ end
325
377
 
326
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
327
- hosts: [ { host: 'localhost', port: '9200' } ],
328
- &transport_configuration
378
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
379
+ hosts: [ { host: 'localhost', port: '9200' } ],
380
+ &transport_configuration
381
+
382
+ # Pass the transport to the client
383
+ #
384
+ client = Elasticsearch::Client.new transport: transport
385
+ ```
329
386
 
330
- # Pass the transport to the client
331
- #
332
- client = Elasticsearch::Client.new transport: transport
333
387
 
334
388
  Instead of passing the transport to the constructor, you can inject it at run time:
335
389
 
data/Rakefile CHANGED
@@ -7,40 +7,37 @@ task :test => 'test:unit'
7
7
  # ----- Test tasks ------------------------------------------------------------
8
8
 
9
9
  require 'rake/testtask'
10
+ require 'rspec/core/rake_task'
11
+
10
12
  namespace :test do
11
- task :ci_reporter do
12
- ENV['CI_REPORTS'] ||= 'tmp/reports'
13
- if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
14
- require 'ci/reporter/rake/test_unit'
15
- Rake::Task['ci:setup:testunit'].invoke
16
- else
17
- require 'ci/reporter/rake/minitest'
18
- Rake::Task['ci:setup:minitest'].invoke
19
- end
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ desc "Wait for Elasticsearch to be in a green state"
17
+ task :wait_for_green do
18
+ sh '../scripts/wait-cluster.sh'
20
19
  end
21
20
 
22
21
  Rake::TestTask.new(:unit) do |test|
23
- Rake::Task['test:ci_reporter'].invoke if ENV['CI']
24
22
  test.libs << 'lib' << 'test'
25
23
  test.test_files = FileList["test/unit/**/*_test.rb"]
26
- # test.verbose = true
27
- # test.warning = true
24
+ test.verbose = false
25
+ test.warning = false
28
26
  end
29
27
 
30
28
  Rake::TestTask.new(:integration) do |test|
31
- Rake::Task['test:ci_reporter'].invoke if ENV['CI']
32
29
  test.libs << 'lib' << 'test'
33
30
  test.test_files = FileList["test/integration/**/*_test.rb"]
31
+ test.deps = [ :wait_for_green, :spec ]
32
+ test.verbose = false
33
+ test.warning = false
34
34
  end
35
35
 
36
36
  Rake::TestTask.new(:all) do |test|
37
- Rake::Task['test:ci_reporter'].invoke if ENV['CI']
38
- test.libs << 'lib' << 'test'
39
- test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
37
+ test.deps = [ :unit, :integration ]
40
38
  end
41
39
 
42
40
  Rake::TestTask.new(:profile) do |test|
43
- Rake::Task['test:ci_reporter'].invoke if ENV['CI']
44
41
  test.libs << 'lib' << 'test'
45
42
  test.test_files = FileList["test/profile/**/*_test.rb"]
46
43
  end
@@ -4,74 +4,56 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'elasticsearch/transport/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "elasticsearch-transport"
7
+ s.name = 'elasticsearch-transport'
8
8
  s.version = Elasticsearch::Transport::VERSION
9
- s.authors = ["Karel Minarik"]
10
- s.email = ["karel.minarik@elasticsearch.org"]
11
- s.summary = "Ruby client for Elasticsearch."
12
- s.homepage = "https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport"
13
- s.license = "Apache 2"
14
-
9
+ s.authors = ['Karel Minarik']
10
+ s.email = ['karel.minarik@elasticsearch.org']
11
+ s.summary = 'Ruby client for Elasticsearch.'
12
+ s.homepage = 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html'
13
+ s.license = 'Apache-2.0'
14
+ s.metadata = {
15
+ 'homepage_uri' => 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/index.html',
16
+ 'changelog_uri' => 'https://github.com/elastic/elasticsearch-ruby/blob/6.x/CHANGELOG.md',
17
+ 'source_code_uri' => 'https://github.com/elastic/elasticsearch-ruby/tree/6.x/elasticsearch-transport',
18
+ 'bug_tracker_uri' => 'https://github.com/elastic/elasticsearch-ruby/issues'
19
+ }
15
20
  s.files = `git ls-files`.split($/)
16
21
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
22
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
- s.require_paths = ["lib"]
19
-
20
- s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ]
21
- s.rdoc_options = [ "--charset=UTF-8" ]
22
-
23
- s.add_dependency "multi_json"
24
- s.add_dependency "faraday"
25
-
26
- if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
27
- s.add_dependency "system_timer"
28
- end
29
-
30
- s.add_development_dependency "bundler", "> 1"
31
-
32
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
33
- s.add_development_dependency "rake", "~> 11.1"
34
- else
35
- s.add_development_dependency "rake", "< 11.0"
36
- end
37
-
38
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
39
- s.add_development_dependency "elasticsearch-extensions"
40
- end
41
-
42
- s.add_development_dependency "ansi"
43
- s.add_development_dependency "shoulda-context"
44
- s.add_development_dependency "mocha"
45
- s.add_development_dependency "turn"
46
- s.add_development_dependency "yard"
47
- s.add_development_dependency "pry"
48
- s.add_development_dependency "ci_reporter", "~> 1.9"
49
-
23
+ s.require_paths = ['lib']
24
+
25
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
26
+ s.rdoc_options = ['--charset=UTF-8']
27
+
28
+ s.required_ruby_version = '>= 2.4'
29
+
30
+ s.add_dependency 'multi_json'
31
+ s.add_dependency 'faraday', '~> 1'
32
+ s.add_development_dependency 'ansi'
33
+ s.add_development_dependency 'bundler'
34
+ s.add_development_dependency 'elasticsearch-extensions'
35
+ s.add_development_dependency 'mocha'
36
+ s.add_development_dependency 'pry'
37
+ s.add_development_dependency 'rake', '~> 13'
38
+ s.add_development_dependency 'shoulda-context'
39
+ s.add_development_dependency 'turn'
40
+ s.add_development_dependency 'yard'
50
41
  # Gems for testing integrations
51
- s.add_development_dependency "curb" unless defined? JRUBY_VERSION
52
- s.add_development_dependency "patron" unless defined? JRUBY_VERSION
53
- s.add_development_dependency "typhoeus", '~> 0.6'
54
- s.add_development_dependency "net-http-persistent"
55
- s.add_development_dependency "manticore", '~> 0.5.2' if defined? JRUBY_VERSION
56
- s.add_development_dependency "hashie"
57
-
58
- # Prevent unit test failures on Ruby 1.8
59
- if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
60
- s.add_development_dependency "test-unit", '~> 2'
61
- s.add_development_dependency "json", '~> 1.8'
62
- end
63
-
64
- if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
65
- s.add_development_dependency "minitest", "~> 4.0"
66
- s.add_development_dependency "ruby-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
67
- s.add_development_dependency "require-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
68
- s.add_development_dependency "simplecov"
69
- s.add_development_dependency "simplecov-rcov"
70
- s.add_development_dependency "cane"
71
- end
72
-
73
- if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
74
- s.add_development_dependency "test-unit", '~> 2'
42
+ s.add_development_dependency 'cane'
43
+ s.add_development_dependency 'hashie'
44
+ s.add_development_dependency 'httpclient'
45
+ s.add_development_dependency 'manticore', '~> 0.5.2' if defined? JRUBY_VERSION
46
+ s.add_development_dependency 'minitest', '~> 4.0'
47
+ s.add_development_dependency 'net-http-persistent'
48
+ s.add_development_dependency 'simplecov', '~> 0.17', '< 0.18'
49
+ s.add_development_dependency 'simplecov-rcov'
50
+ s.add_development_dependency 'test-unit', '~> 2'
51
+ s.add_development_dependency 'typhoeus', '~> 1.4'
52
+ unless defined?(JRUBY_VERSION) || defined?(Rubinius)
53
+ s.add_development_dependency 'curb'
54
+ s.add_development_dependency 'patron'
55
+ s.add_development_dependency 'require-prof'
56
+ s.add_development_dependency 'ruby-prof'
75
57
  end
76
58
 
77
59
  s.description = <<-DESC.gsub(/^ /, '')