elasticsearch-transport 7.9.0 → 7.17.10

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -10
  3. data/Gemfile-faraday1.gemfile +47 -0
  4. data/README.md +23 -17
  5. data/Rakefile +47 -10
  6. data/elasticsearch-transport.gemspec +16 -18
  7. data/lib/elasticsearch/transport/client.rb +133 -56
  8. data/lib/elasticsearch/transport/meta_header.rb +135 -0
  9. data/lib/elasticsearch/transport/transport/base.rb +41 -22
  10. data/lib/elasticsearch/transport/transport/connections/collection.rb +2 -5
  11. data/lib/elasticsearch/transport/transport/connections/connection.rb +6 -4
  12. data/lib/elasticsearch/transport/transport/errors.rb +1 -0
  13. data/lib/elasticsearch/transport/transport/http/curb.rb +44 -32
  14. data/lib/elasticsearch/transport/transport/http/faraday.rb +15 -5
  15. data/lib/elasticsearch/transport/transport/http/manticore.rb +41 -29
  16. data/lib/elasticsearch/transport/transport/response.rb +1 -1
  17. data/lib/elasticsearch/transport/version.rb +1 -1
  18. data/lib/elasticsearch/transport.rb +19 -30
  19. data/spec/elasticsearch/connections/collection_spec.rb +12 -0
  20. data/spec/elasticsearch/transport/base_spec.rb +90 -33
  21. data/spec/elasticsearch/transport/client_spec.rb +569 -164
  22. data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
  23. data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
  24. data/spec/elasticsearch/transport/http/manticore_spec.rb +161 -0
  25. data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
  26. data/spec/spec_helper.rb +13 -5
  27. data/test/integration/jruby_test.rb +43 -0
  28. data/test/integration/transport_test.rb +93 -43
  29. data/test/test_helper.rb +10 -22
  30. data/test/unit/adapters_test.rb +88 -0
  31. data/test/unit/connection_test.rb +7 -2
  32. data/test/unit/response_test.rb +1 -1
  33. data/test/unit/transport_base_test.rb +17 -8
  34. data/test/unit/transport_curb_test.rb +0 -1
  35. data/test/unit/transport_faraday_test.rb +2 -2
  36. data/test/unit/transport_manticore_test.rb +242 -155
  37. metadata +62 -84
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Transport
20
- VERSION = "7.9.0"
20
+ VERSION = '7.17.10'.freeze
21
21
  end
22
22
  end
@@ -15,35 +15,24 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require "uri"
19
- require "time"
20
- require "timeout"
21
- require "multi_json"
22
- require "faraday"
18
+ require 'uri'
19
+ require 'time'
20
+ require 'timeout'
21
+ require 'zlib'
22
+ require 'multi_json'
23
+ require 'faraday'
23
24
 
24
- require "elasticsearch/transport/transport/loggable"
25
- require "elasticsearch/transport/transport/serializer/multi_json"
26
- require "elasticsearch/transport/transport/sniffer"
27
- require "elasticsearch/transport/transport/response"
28
- require "elasticsearch/transport/transport/errors"
29
- require "elasticsearch/transport/transport/base"
30
- require "elasticsearch/transport/transport/connections/selector"
31
- require "elasticsearch/transport/transport/connections/connection"
32
- require "elasticsearch/transport/transport/connections/collection"
33
- require "elasticsearch/transport/transport/http/faraday"
34
- require "elasticsearch/transport/client"
35
- require "elasticsearch/transport/redacted"
25
+ require 'elasticsearch/transport/transport/loggable'
26
+ require 'elasticsearch/transport/transport/serializer/multi_json'
27
+ require 'elasticsearch/transport/transport/sniffer'
28
+ require 'elasticsearch/transport/transport/response'
29
+ require 'elasticsearch/transport/transport/errors'
30
+ require 'elasticsearch/transport/transport/base'
31
+ require 'elasticsearch/transport/transport/connections/selector'
32
+ require 'elasticsearch/transport/transport/connections/connection'
33
+ require 'elasticsearch/transport/transport/connections/collection'
34
+ require 'elasticsearch/transport/transport/http/faraday'
35
+ require 'elasticsearch/transport/client'
36
+ require 'elasticsearch/transport/redacted'
36
37
 
37
- require "elasticsearch/transport/version"
38
-
39
- module Elasticsearch
40
- module Client
41
-
42
- # A convenience wrapper for {::Elasticsearch::Transport::Client#initialize}.
43
- #
44
- def new(arguments={}, &block)
45
- Elasticsearch::Transport::Client.new(arguments, &block)
46
- end
47
- extend self
48
- end
49
- end
38
+ require 'elasticsearch/transport/version'
@@ -249,6 +249,18 @@ describe Elasticsearch::Transport::Transport::Connections::Collection do
249
249
  collection.get_connection.host[:host]
250
250
  end).to eq((0..9).to_a)
251
251
  end
252
+
253
+ it 'always returns a connection' do
254
+ threads = 20.times.map do
255
+ Thread.new do
256
+ 20.times.map do
257
+ collection.get_connection.dead!
258
+ end
259
+ end
260
+ end
261
+
262
+ expect(threads.flat_map(&:value).size).to eq(400)
263
+ end
252
264
  end
253
265
  end
254
266
  end
@@ -32,24 +32,26 @@ describe Elasticsearch::Transport::Transport::Base do
32
32
  expect(logger).not_to receive(:error).with(/secret_password/)
33
33
 
34
34
  expect {
35
- client.cluster.stats
35
+ client.perform_request('GET', '_cluster/stats')
36
36
  }.to raise_exception(Faraday::ConnectionFailed)
37
37
  end
38
38
 
39
39
  it 'replaces the password with the string \'REDACTED\'' do
40
40
  expect(logger).to receive(:error).with(/REDACTED/)
41
41
  expect {
42
- client.cluster.stats
42
+ client.perform_request('GET', '_cluster/stats')
43
43
  }.to raise_exception(Faraday::ConnectionFailed)
44
44
  end
45
45
  end
46
46
 
47
47
  context 'when the user and password are provided as separate arguments' do
48
48
  let(:arguments) do
49
- { hosts: 'fake',
49
+ {
50
+ hosts: 'fake',
50
51
  logger: logger,
51
52
  password: 'secret_password',
52
- user: 'test' }
53
+ user: 'test'
54
+ }
53
55
  end
54
56
 
55
57
  it_behaves_like 'a redacted string'
@@ -57,54 +59,94 @@ describe Elasticsearch::Transport::Transport::Base do
57
59
 
58
60
  context 'when the user and password are provided in the string URI' do
59
61
  let(:arguments) do
60
- { hosts: 'https://test:secret_password@fake_local_elasticsearch',
61
- logger: logger }
62
+ {
63
+ hosts: 'https://test:secret_password@fake_local_elasticsearch',
64
+ logger: logger
65
+ }
62
66
  end
63
67
 
64
- it_behaves_like 'a redacted string'
68
+ if jruby?
69
+ let(:client) { Elasticsearch::Transport::Client.new(arguments) }
70
+ let(:logger) { double('logger', fatal?: true, fatal: '') }
71
+
72
+ it 'does not include the password in the logged string' do
73
+ expect(logger).not_to receive(:fatal).with(/secret_password/)
74
+
75
+ expect {
76
+ client.perform_request('GET', '_cluster/stats')
77
+ }.to raise_exception(Faraday::SSLError)
78
+ end
79
+
80
+ it 'replaces the password with the string \'REDACTED\'' do
81
+ expect(logger).to receive(:fatal).with(/REDACTED/)
82
+ expect {
83
+ client.perform_request('GET', '_cluster/stats')
84
+ }.to raise_exception(Faraday::SSLError)
85
+ end
86
+ else
87
+ it_behaves_like 'a redacted string'
88
+ end
65
89
  end
66
90
 
67
91
  context 'when the user and password are provided in the URI object' do
68
92
  let(:arguments) do
69
- { hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
70
- logger: logger }
93
+ {
94
+ hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
95
+ logger: logger
96
+ }
97
+ end
98
+ if jruby?
99
+ let(:client) { Elasticsearch::Transport::Client.new(arguments) }
100
+ let(:logger) { double('logger', fatal?: true, fatal: '') }
101
+
102
+ it 'does not include the password in the logged string' do
103
+ expect(logger).not_to receive(:fatal).with(/secret_password/)
104
+
105
+ expect {
106
+ client.perform_request('GET', '_cluster/stats')
107
+ }.to raise_exception(Faraday::SSLError)
108
+ end
109
+
110
+ it 'replaces the password with the string \'REDACTED\'' do
111
+ expect(logger).to receive(:fatal).with(/REDACTED/)
112
+ expect {
113
+ client.perform_request('GET', '_cluster/stats')
114
+ }.to raise_exception(Faraday::SSLError)
115
+ end
116
+ else
117
+ it_behaves_like 'a redacted string'
71
118
  end
72
-
73
- it_behaves_like 'a redacted string'
74
119
  end
75
120
  end
76
121
 
77
122
  context 'when reload_on_failure is true and and hosts are unreachable' do
78
-
79
123
  let(:client) do
80
124
  Elasticsearch::Transport::Client.new(arguments)
81
125
  end
82
126
 
83
127
  let(:arguments) do
84
128
  {
85
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
86
- reload_on_failure: true,
87
- sniffer_timeout: 5
129
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
130
+ reload_on_failure: true,
131
+ sniffer_timeout: 5
88
132
  }
89
133
  end
90
134
 
91
135
  it 'raises an exception' do
92
- expect {
93
- client.info
94
- }.to raise_exception(Faraday::ConnectionFailed)
136
+ expect { client.perform_request('GET', '/') }.to raise_exception(Faraday::ConnectionFailed)
95
137
  end
96
138
  end
97
139
 
98
140
  context 'when the client has `retry_on_failure` set to an integer' do
99
-
100
141
  let(:client) do
101
142
  Elasticsearch::Transport::Client.new(arguments)
102
143
  end
103
144
 
104
145
  let(:arguments) do
105
146
  {
106
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
107
- retry_on_failure: 2
147
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
148
+ retry_on_failure: 2,
149
+ adapter: :net_http
108
150
  }
109
151
  end
110
152
 
@@ -120,15 +162,35 @@ describe Elasticsearch::Transport::Transport::Base do
120
162
  end
121
163
  end
122
164
 
165
+ context 'when `perform_request` is called with a `retry_on_status` option value' do
166
+ before do
167
+ expect(client.transport).to receive(:__raise_transport_error).exactly(6).times.and_call_original
168
+ end
169
+
170
+ let(:arguments) do
171
+ {
172
+ hosts: ELASTICSEARCH_HOSTS,
173
+ retry_on_status: ['404'],
174
+ adapter: :net_http
175
+ }
176
+ end
177
+
178
+ it 'retries on 404 status the specified number of max_retries' do
179
+ expect do
180
+ client.transport.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
181
+ end.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
182
+ end
183
+ end
184
+
123
185
  context 'when `perform_request` is called with a `retry_on_failure` option value' do
124
186
  before do
125
187
  expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
126
188
  end
127
189
 
128
190
  it 'uses the option `retry_on_failure` value' do
129
- expect {
191
+ expect do
130
192
  client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
131
- }.to raise_exception(Faraday::ConnectionFailed)
193
+ end.to raise_exception(Faraday::ConnectionFailed)
132
194
  end
133
195
  end
134
196
  end
@@ -209,40 +271,35 @@ describe Elasticsearch::Transport::Transport::Base do
209
271
  end
210
272
 
211
273
  context 'when the client has no `retry_on_failure` set' do
212
-
213
274
  let(:client) do
214
275
  Elasticsearch::Transport::Client.new(arguments)
215
276
  end
216
277
 
217
278
  let(:arguments) do
218
- {
219
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
220
- }
279
+ { hosts: ['http://unavailable:9200', 'http://unavailable:9201'] }
221
280
  end
222
281
 
223
282
  context 'when `perform_request` is called without a `retry_on_failure` option value' do
224
-
225
283
  before do
226
284
  expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
227
285
  end
228
286
 
229
287
  it 'does not retry' do
230
- expect {
288
+ expect do
231
289
  client.transport.perform_request('GET', '/info')
232
- }.to raise_exception(Faraday::ConnectionFailed)
290
+ end.to raise_exception(Faraday::ConnectionFailed)
233
291
  end
234
292
  end
235
293
 
236
294
  context 'when `perform_request` is called with a `retry_on_failure` option value' do
237
-
238
295
  before do
239
296
  expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
240
297
  end
241
298
 
242
299
  it 'uses the option `retry_on_failure` value' do
243
- expect {
300
+ expect do
244
301
  client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
245
- }.to raise_exception(Faraday::ConnectionFailed)
302
+ end.to raise_exception(Faraday::ConnectionFailed)
246
303
  end
247
304
  end
248
305
  end