elasticsearch-transport 7.5.0 → 7.17.7
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 +26 -13
- data/README.md +159 -64
- data/Rakefile +25 -13
- data/elasticsearch-transport.gemspec +57 -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 +51 -31
- data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
- data/lib/elasticsearch/transport/transport/response.rb +16 -4
- 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 +104 -43
- data/spec/elasticsearch/transport/client_spec.rb +727 -163
- 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 +143 -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 +28 -6
- data/test/integration/jruby_test.rb +43 -0
- data/test/integration/transport_test.rb +46 -29
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +22 -25
- 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 +80 -71
@@ -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,97 @@ 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
|
95
149
|
}
|
96
150
|
end
|
97
151
|
|
98
152
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
99
|
-
|
100
153
|
before do
|
101
154
|
expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
|
102
155
|
end
|
@@ -108,22 +161,39 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
108
161
|
end
|
109
162
|
end
|
110
163
|
|
111
|
-
context 'when `perform_request` is called with a `
|
164
|
+
context 'when `perform_request` is called with a `retry_on_status` option value' do
|
165
|
+
before do
|
166
|
+
expect(client.transport).to receive(:__raise_transport_error).exactly(6).times.and_call_original
|
167
|
+
end
|
168
|
+
|
169
|
+
let(:arguments) do
|
170
|
+
{
|
171
|
+
hosts: ELASTICSEARCH_HOSTS,
|
172
|
+
retry_on_status: ['404']
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'retries on 404 status the specified number of max_retries' do
|
177
|
+
expect do
|
178
|
+
client.transport.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
|
179
|
+
end.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
|
180
|
+
end
|
181
|
+
end
|
112
182
|
|
183
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
113
184
|
before do
|
114
185
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
115
186
|
end
|
116
187
|
|
117
188
|
it 'uses the option `retry_on_failure` value' do
|
118
|
-
expect
|
189
|
+
expect do
|
119
190
|
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
120
|
-
|
191
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
121
192
|
end
|
122
193
|
end
|
123
194
|
end
|
124
195
|
|
125
196
|
context 'when the client has `retry_on_failure` set to true' do
|
126
|
-
|
127
197
|
let(:client) do
|
128
198
|
Elasticsearch::Transport::Client.new(arguments)
|
129
199
|
end
|
@@ -136,7 +206,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
136
206
|
end
|
137
207
|
|
138
208
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
139
|
-
|
140
209
|
before do
|
141
210
|
expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
|
142
211
|
end
|
@@ -149,7 +218,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
149
218
|
end
|
150
219
|
|
151
220
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
152
|
-
|
153
221
|
before do
|
154
222
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
155
223
|
end
|
@@ -163,7 +231,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
163
231
|
end
|
164
232
|
|
165
233
|
context 'when the client has `retry_on_failure` set to false' do
|
166
|
-
|
167
234
|
let(:client) do
|
168
235
|
Elasticsearch::Transport::Client.new(arguments)
|
169
236
|
end
|
@@ -176,7 +243,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
176
243
|
end
|
177
244
|
|
178
245
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
179
|
-
|
180
246
|
before do
|
181
247
|
expect(client.transport).to receive(:get_connection).once.and_call_original
|
182
248
|
end
|
@@ -203,40 +269,35 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
203
269
|
end
|
204
270
|
|
205
271
|
context 'when the client has no `retry_on_failure` set' do
|
206
|
-
|
207
272
|
let(:client) do
|
208
273
|
Elasticsearch::Transport::Client.new(arguments)
|
209
274
|
end
|
210
275
|
|
211
276
|
let(:arguments) do
|
212
|
-
{
|
213
|
-
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
214
|
-
}
|
277
|
+
{ hosts: ['http://unavailable:9200', 'http://unavailable:9201'] }
|
215
278
|
end
|
216
279
|
|
217
280
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
218
|
-
|
219
281
|
before do
|
220
282
|
expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
|
221
283
|
end
|
222
284
|
|
223
285
|
it 'does not retry' do
|
224
|
-
expect
|
286
|
+
expect do
|
225
287
|
client.transport.perform_request('GET', '/info')
|
226
|
-
|
288
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
227
289
|
end
|
228
290
|
end
|
229
291
|
|
230
292
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
231
|
-
|
232
293
|
before do
|
233
294
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
234
295
|
end
|
235
296
|
|
236
297
|
it 'uses the option `retry_on_failure` value' do
|
237
|
-
expect
|
298
|
+
expect do
|
238
299
|
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
239
|
-
|
300
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
240
301
|
end
|
241
302
|
end
|
242
303
|
end
|