elasticsearch-transport 7.4.0 → 7.17.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +30 -13
  3. data/Gemfile-faraday1.gemfile +47 -0
  4. data/README.md +159 -64
  5. data/Rakefile +63 -13
  6. data/elasticsearch-transport.gemspec +55 -63
  7. data/lib/elasticsearch/transport/client.rb +184 -59
  8. data/lib/elasticsearch/transport/meta_header.rb +135 -0
  9. data/lib/elasticsearch/transport/redacted.rb +16 -3
  10. data/lib/elasticsearch/transport/transport/base.rb +69 -30
  11. data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
  12. data/lib/elasticsearch/transport/transport/connections/connection.rb +25 -9
  13. data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
  14. data/lib/elasticsearch/transport/transport/errors.rb +17 -3
  15. data/lib/elasticsearch/transport/transport/http/curb.rb +60 -35
  16. data/lib/elasticsearch/transport/transport/http/faraday.rb +32 -9
  17. data/lib/elasticsearch/transport/transport/http/manticore.rb +57 -32
  18. data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
  19. data/lib/elasticsearch/transport/transport/response.rb +17 -5
  20. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
  21. data/lib/elasticsearch/transport/transport/sniffer.rb +35 -15
  22. data/lib/elasticsearch/transport/version.rb +17 -4
  23. data/lib/elasticsearch/transport.rb +35 -33
  24. data/lib/elasticsearch-transport.rb +16 -3
  25. data/spec/elasticsearch/connections/collection_spec.rb +28 -3
  26. data/spec/elasticsearch/connections/selector_spec.rb +16 -3
  27. data/spec/elasticsearch/transport/base_spec.rb +107 -49
  28. data/spec/elasticsearch/transport/client_spec.rb +734 -164
  29. data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
  30. data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
  31. data/spec/elasticsearch/transport/http/manticore_spec.rb +161 -0
  32. data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
  33. data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
  34. data/spec/spec_helper.rb +32 -6
  35. data/test/integration/jruby_test.rb +43 -0
  36. data/test/integration/transport_test.rb +109 -46
  37. data/test/profile/client_benchmark_test.rb +16 -3
  38. data/test/test_helper.rb +26 -25
  39. data/test/unit/adapters_test.rb +88 -0
  40. data/test/unit/connection_test.rb +23 -5
  41. data/test/unit/response_test.rb +18 -5
  42. data/test/unit/serializer_test.rb +16 -3
  43. data/test/unit/transport_base_test.rb +33 -11
  44. data/test/unit/transport_curb_test.rb +16 -4
  45. data/test/unit/transport_faraday_test.rb +18 -5
  46. data/test/unit/transport_manticore_test.rb +258 -158
  47. metadata +64 -76
@@ -1,15 +1,25 @@
1
- # Licensed to Elasticsearch B.V under one or more agreements.
2
- # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
- # See the LICENSE file in the project root for more information
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
4
17
 
5
18
  require 'spec_helper'
6
19
 
7
20
  describe Elasticsearch::Transport::Transport::Base do
8
-
9
21
  context 'when a host is printed in a logged message' do
10
-
11
22
  shared_examples_for 'a redacted string' do
12
-
13
23
  let(:client) do
14
24
  Elasticsearch::Transport::Client.new(arguments)
15
25
  end
@@ -20,88 +30,127 @@ describe Elasticsearch::Transport::Transport::Base do
20
30
 
21
31
  it 'does not include the password in the logged string' do
22
32
  expect(logger).not_to receive(:error).with(/secret_password/)
33
+
23
34
  expect {
24
- client.cluster.stats
35
+ client.perform_request('GET', '_cluster/stats')
25
36
  }.to raise_exception(Faraday::ConnectionFailed)
26
37
  end
27
38
 
28
39
  it 'replaces the password with the string \'REDACTED\'' do
29
40
  expect(logger).to receive(:error).with(/REDACTED/)
30
41
  expect {
31
- client.cluster.stats
42
+ client.perform_request('GET', '_cluster/stats')
32
43
  }.to raise_exception(Faraday::ConnectionFailed)
33
44
  end
34
45
  end
35
46
 
36
47
  context 'when the user and password are provided as separate arguments' do
37
-
38
48
  let(:arguments) do
39
- { hosts: 'fake',
49
+ {
50
+ hosts: 'fake',
40
51
  logger: logger,
41
52
  password: 'secret_password',
42
- user: 'test' }
53
+ user: 'test'
54
+ }
43
55
  end
44
56
 
45
57
  it_behaves_like 'a redacted string'
46
58
  end
47
59
 
48
60
  context 'when the user and password are provided in the string URI' do
49
-
50
61
  let(:arguments) do
51
- { hosts: 'http://test:secret_password@fake.com',
52
- logger: logger }
62
+ {
63
+ hosts: 'https://test:secret_password@fake_local_elasticsearch',
64
+ logger: logger
65
+ }
53
66
  end
54
67
 
55
- 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
56
89
  end
57
90
 
58
91
  context 'when the user and password are provided in the URI object' do
59
-
60
92
  let(:arguments) do
61
- { hosts: URI.parse('http://test:secret_password@fake.com'),
62
- 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'
63
118
  end
64
-
65
- it_behaves_like 'a redacted string'
66
119
  end
67
120
  end
68
121
 
69
122
  context 'when reload_on_failure is true and and hosts are unreachable' do
70
-
71
123
  let(:client) do
72
124
  Elasticsearch::Transport::Client.new(arguments)
73
125
  end
74
126
 
75
127
  let(:arguments) do
76
128
  {
77
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
78
- reload_on_failure: true,
79
- sniffer_timeout: 5
129
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
130
+ reload_on_failure: true,
131
+ sniffer_timeout: 5
80
132
  }
81
133
  end
82
134
 
83
135
  it 'raises an exception' do
84
- expect {
85
- client.info
86
- }.to raise_exception(Faraday::ConnectionFailed)
136
+ expect { client.perform_request('GET', '/') }.to raise_exception(Faraday::ConnectionFailed)
87
137
  end
88
138
  end
89
139
 
90
140
  context 'when the client has `retry_on_failure` set to an integer' do
91
-
92
141
  let(:client) do
93
142
  Elasticsearch::Transport::Client.new(arguments)
94
143
  end
95
144
 
96
145
  let(:arguments) do
97
146
  {
98
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
99
- retry_on_failure: 2
147
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
148
+ retry_on_failure: 2,
149
+ adapter: :net_http
100
150
  }
101
151
  end
102
152
 
103
153
  context 'when `perform_request` is called without a `retry_on_failure` option value' do
104
-
105
154
  before do
106
155
  expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
107
156
  end
@@ -113,22 +162,40 @@ describe Elasticsearch::Transport::Transport::Base do
113
162
  end
114
163
  end
115
164
 
116
- context 'when `perform_request` is called with a `retry_on_failure` option value' do
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
117
184
 
185
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
118
186
  before do
119
187
  expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
120
188
  end
121
189
 
122
190
  it 'uses the option `retry_on_failure` value' do
123
- expect {
191
+ expect do
124
192
  client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
125
- }.to raise_exception(Faraday::ConnectionFailed)
193
+ end.to raise_exception(Faraday::ConnectionFailed)
126
194
  end
127
195
  end
128
196
  end
129
197
 
130
198
  context 'when the client has `retry_on_failure` set to true' do
131
-
132
199
  let(:client) do
133
200
  Elasticsearch::Transport::Client.new(arguments)
134
201
  end
@@ -141,7 +208,6 @@ describe Elasticsearch::Transport::Transport::Base do
141
208
  end
142
209
 
143
210
  context 'when `perform_request` is called without a `retry_on_failure` option value' do
144
-
145
211
  before do
146
212
  expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
147
213
  end
@@ -154,7 +220,6 @@ describe Elasticsearch::Transport::Transport::Base do
154
220
  end
155
221
 
156
222
  context 'when `perform_request` is called with a `retry_on_failure` option value' do
157
-
158
223
  before do
159
224
  expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
160
225
  end
@@ -168,7 +233,6 @@ describe Elasticsearch::Transport::Transport::Base do
168
233
  end
169
234
 
170
235
  context 'when the client has `retry_on_failure` set to false' do
171
-
172
236
  let(:client) do
173
237
  Elasticsearch::Transport::Client.new(arguments)
174
238
  end
@@ -181,7 +245,6 @@ describe Elasticsearch::Transport::Transport::Base do
181
245
  end
182
246
 
183
247
  context 'when `perform_request` is called without a `retry_on_failure` option value' do
184
-
185
248
  before do
186
249
  expect(client.transport).to receive(:get_connection).once.and_call_original
187
250
  end
@@ -208,40 +271,35 @@ describe Elasticsearch::Transport::Transport::Base do
208
271
  end
209
272
 
210
273
  context 'when the client has no `retry_on_failure` set' do
211
-
212
274
  let(:client) do
213
275
  Elasticsearch::Transport::Client.new(arguments)
214
276
  end
215
277
 
216
278
  let(:arguments) do
217
- {
218
- hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
219
- }
279
+ { hosts: ['http://unavailable:9200', 'http://unavailable:9201'] }
220
280
  end
221
281
 
222
282
  context 'when `perform_request` is called without a `retry_on_failure` option value' do
223
-
224
283
  before do
225
284
  expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
226
285
  end
227
286
 
228
287
  it 'does not retry' do
229
- expect {
288
+ expect do
230
289
  client.transport.perform_request('GET', '/info')
231
- }.to raise_exception(Faraday::ConnectionFailed)
290
+ end.to raise_exception(Faraday::ConnectionFailed)
232
291
  end
233
292
  end
234
293
 
235
294
  context 'when `perform_request` is called with a `retry_on_failure` option value' do
236
-
237
295
  before do
238
296
  expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
239
297
  end
240
298
 
241
299
  it 'uses the option `retry_on_failure` value' do
242
- expect {
300
+ expect do
243
301
  client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
244
- }.to raise_exception(Faraday::ConnectionFailed)
302
+ end.to raise_exception(Faraday::ConnectionFailed)
245
303
  end
246
304
  end
247
305
  end