elasticsearch-transport 7.5.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.
- checksums.yaml +4 -4
- data/Gemfile +30 -13
- data/Gemfile-faraday1.gemfile +47 -0
- data/README.md +159 -64
- data/Rakefile +63 -13
- data/elasticsearch-transport.gemspec +55 -63
- data/lib/elasticsearch/transport/client.rb +183 -58
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/redacted.rb +16 -3
- data/lib/elasticsearch/transport/transport/base.rb +69 -30
- data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
- data/lib/elasticsearch/transport/transport/connections/connection.rb +25 -9
- data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
- data/lib/elasticsearch/transport/transport/errors.rb +17 -3
- data/lib/elasticsearch/transport/transport/http/curb.rb +60 -35
- data/lib/elasticsearch/transport/transport/http/faraday.rb +32 -9
- data/lib/elasticsearch/transport/transport/http/manticore.rb +57 -32
- data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
- data/lib/elasticsearch/transport/transport/response.rb +17 -5
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
- data/lib/elasticsearch/transport/transport/sniffer.rb +35 -15
- data/lib/elasticsearch/transport/version.rb +17 -4
- data/lib/elasticsearch/transport.rb +35 -33
- data/lib/elasticsearch-transport.rb +16 -3
- data/spec/elasticsearch/connections/collection_spec.rb +28 -3
- data/spec/elasticsearch/connections/selector_spec.rb +16 -3
- data/spec/elasticsearch/transport/base_spec.rb +106 -43
- data/spec/elasticsearch/transport/client_spec.rb +734 -164
- data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
- data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
- data/spec/elasticsearch/transport/http/manticore_spec.rb +161 -0
- data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
- data/spec/spec_helper.rb +32 -6
- data/test/integration/jruby_test.rb +43 -0
- data/test/integration/transport_test.rb +109 -46
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +26 -25
- data/test/unit/adapters_test.rb +88 -0
- data/test/unit/connection_test.rb +23 -5
- data/test/unit/response_test.rb +18 -5
- data/test/unit/serializer_test.rb +16 -3
- data/test/unit/transport_base_test.rb +33 -11
- data/test/unit/transport_curb_test.rb +16 -4
- data/test/unit/transport_faraday_test.rb +18 -5
- data/test/unit/transport_manticore_test.rb +258 -158
- metadata +65 -89
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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
|
|
@@ -19,24 +32,26 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
19
32
|
expect(logger).not_to receive(:error).with(/secret_password/)
|
20
33
|
|
21
34
|
expect {
|
22
|
-
client.
|
35
|
+
client.perform_request('GET', '_cluster/stats')
|
23
36
|
}.to raise_exception(Faraday::ConnectionFailed)
|
24
37
|
end
|
25
38
|
|
26
39
|
it 'replaces the password with the string \'REDACTED\'' do
|
27
40
|
expect(logger).to receive(:error).with(/REDACTED/)
|
28
41
|
expect {
|
29
|
-
client.
|
42
|
+
client.perform_request('GET', '_cluster/stats')
|
30
43
|
}.to raise_exception(Faraday::ConnectionFailed)
|
31
44
|
end
|
32
45
|
end
|
33
46
|
|
34
47
|
context 'when the user and password are provided as separate arguments' do
|
35
48
|
let(:arguments) do
|
36
|
-
{
|
49
|
+
{
|
50
|
+
hosts: 'fake',
|
37
51
|
logger: logger,
|
38
52
|
password: 'secret_password',
|
39
|
-
user: 'test'
|
53
|
+
user: 'test'
|
54
|
+
}
|
40
55
|
end
|
41
56
|
|
42
57
|
it_behaves_like 'a redacted string'
|
@@ -44,59 +59,98 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
44
59
|
|
45
60
|
context 'when the user and password are provided in the string URI' do
|
46
61
|
let(:arguments) do
|
47
|
-
{
|
48
|
-
|
62
|
+
{
|
63
|
+
hosts: 'https://test:secret_password@fake_local_elasticsearch',
|
64
|
+
logger: logger
|
65
|
+
}
|
49
66
|
end
|
50
67
|
|
51
|
-
|
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
|
52
89
|
end
|
53
90
|
|
54
91
|
context 'when the user and password are provided in the URI object' do
|
55
92
|
let(:arguments) do
|
56
|
-
{
|
57
|
-
|
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'
|
58
118
|
end
|
59
|
-
|
60
|
-
it_behaves_like 'a redacted string'
|
61
119
|
end
|
62
120
|
end
|
63
121
|
|
64
122
|
context 'when reload_on_failure is true and and hosts are unreachable' do
|
65
|
-
|
66
123
|
let(:client) do
|
67
124
|
Elasticsearch::Transport::Client.new(arguments)
|
68
125
|
end
|
69
126
|
|
70
127
|
let(:arguments) do
|
71
128
|
{
|
72
|
-
|
73
|
-
|
74
|
-
|
129
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
130
|
+
reload_on_failure: true,
|
131
|
+
sniffer_timeout: 5
|
75
132
|
}
|
76
133
|
end
|
77
134
|
|
78
135
|
it 'raises an exception' do
|
79
|
-
expect {
|
80
|
-
client.info
|
81
|
-
}.to raise_exception(Faraday::ConnectionFailed)
|
136
|
+
expect { client.perform_request('GET', '/') }.to raise_exception(Faraday::ConnectionFailed)
|
82
137
|
end
|
83
138
|
end
|
84
139
|
|
85
140
|
context 'when the client has `retry_on_failure` set to an integer' do
|
86
|
-
|
87
141
|
let(:client) do
|
88
142
|
Elasticsearch::Transport::Client.new(arguments)
|
89
143
|
end
|
90
144
|
|
91
145
|
let(:arguments) do
|
92
146
|
{
|
93
|
-
|
94
|
-
|
147
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
148
|
+
retry_on_failure: 2,
|
149
|
+
adapter: :net_http
|
95
150
|
}
|
96
151
|
end
|
97
152
|
|
98
153
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
99
|
-
|
100
154
|
before do
|
101
155
|
expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
|
102
156
|
end
|
@@ -108,22 +162,40 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
108
162
|
end
|
109
163
|
end
|
110
164
|
|
111
|
-
context 'when `perform_request` is called with a `
|
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
|
112
184
|
|
185
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
113
186
|
before do
|
114
187
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
115
188
|
end
|
116
189
|
|
117
190
|
it 'uses the option `retry_on_failure` value' do
|
118
|
-
expect
|
191
|
+
expect do
|
119
192
|
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
120
|
-
|
193
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
121
194
|
end
|
122
195
|
end
|
123
196
|
end
|
124
197
|
|
125
198
|
context 'when the client has `retry_on_failure` set to true' do
|
126
|
-
|
127
199
|
let(:client) do
|
128
200
|
Elasticsearch::Transport::Client.new(arguments)
|
129
201
|
end
|
@@ -136,7 +208,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
136
208
|
end
|
137
209
|
|
138
210
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
139
|
-
|
140
211
|
before do
|
141
212
|
expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
|
142
213
|
end
|
@@ -149,7 +220,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
149
220
|
end
|
150
221
|
|
151
222
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
152
|
-
|
153
223
|
before do
|
154
224
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
155
225
|
end
|
@@ -163,7 +233,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
163
233
|
end
|
164
234
|
|
165
235
|
context 'when the client has `retry_on_failure` set to false' do
|
166
|
-
|
167
236
|
let(:client) do
|
168
237
|
Elasticsearch::Transport::Client.new(arguments)
|
169
238
|
end
|
@@ -176,7 +245,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
176
245
|
end
|
177
246
|
|
178
247
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
179
|
-
|
180
248
|
before do
|
181
249
|
expect(client.transport).to receive(:get_connection).once.and_call_original
|
182
250
|
end
|
@@ -203,40 +271,35 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
203
271
|
end
|
204
272
|
|
205
273
|
context 'when the client has no `retry_on_failure` set' do
|
206
|
-
|
207
274
|
let(:client) do
|
208
275
|
Elasticsearch::Transport::Client.new(arguments)
|
209
276
|
end
|
210
277
|
|
211
278
|
let(:arguments) do
|
212
|
-
{
|
213
|
-
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
214
|
-
}
|
279
|
+
{ hosts: ['http://unavailable:9200', 'http://unavailable:9201'] }
|
215
280
|
end
|
216
281
|
|
217
282
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
218
|
-
|
219
283
|
before do
|
220
284
|
expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
|
221
285
|
end
|
222
286
|
|
223
287
|
it 'does not retry' do
|
224
|
-
expect
|
288
|
+
expect do
|
225
289
|
client.transport.perform_request('GET', '/info')
|
226
|
-
|
290
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
227
291
|
end
|
228
292
|
end
|
229
293
|
|
230
294
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
231
|
-
|
232
295
|
before do
|
233
296
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
234
297
|
end
|
235
298
|
|
236
299
|
it 'uses the option `retry_on_failure` value' do
|
237
|
-
expect
|
300
|
+
expect do
|
238
301
|
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
239
|
-
|
302
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
240
303
|
end
|
241
304
|
end
|
242
305
|
end
|