elasticsearch-transport 7.1.0 → 7.5.0
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 +3 -16
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +18 -19
- data/Rakefile +3 -16
- data/elasticsearch-transport.gemspec +7 -19
- data/lib/elasticsearch/transport/client.rb +27 -24
- data/lib/elasticsearch/transport/redacted.rb +3 -16
- data/lib/elasticsearch/transport/transport/base.rb +81 -26
- data/lib/elasticsearch/transport/transport/connections/collection.rb +3 -16
- data/lib/elasticsearch/transport/transport/connections/connection.rb +3 -16
- data/lib/elasticsearch/transport/transport/connections/selector.rb +20 -21
- data/lib/elasticsearch/transport/transport/errors.rb +3 -16
- data/lib/elasticsearch/transport/transport/http/curb.rb +28 -24
- data/lib/elasticsearch/transport/transport/http/faraday.rb +19 -18
- data/lib/elasticsearch/transport/transport/http/manticore.rb +27 -25
- data/lib/elasticsearch/transport/transport/loggable.rb +3 -16
- data/lib/elasticsearch/transport/transport/response.rb +3 -16
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +3 -16
- data/lib/elasticsearch/transport/transport/sniffer.rb +5 -17
- data/lib/elasticsearch/transport/version.rb +4 -17
- data/lib/elasticsearch/transport.rb +3 -16
- data/lib/elasticsearch-transport.rb +3 -16
- data/spec/elasticsearch/connections/collection_spec.rb +241 -0
- data/spec/elasticsearch/connections/selector_spec.rb +161 -0
- data/spec/elasticsearch/transport/base_spec.rb +186 -24
- data/spec/elasticsearch/transport/client_spec.rb +350 -19
- data/spec/elasticsearch/transport/sniffer_spec.rb +3 -16
- data/spec/spec_helper.rb +6 -0
- data/test/integration/transport_test.rb +3 -16
- data/test/profile/client_benchmark_test.rb +3 -16
- data/test/test_helper.rb +3 -16
- data/test/unit/connection_test.rb +3 -16
- data/test/unit/response_test.rb +3 -16
- data/test/unit/serializer_test.rb +3 -16
- data/test/unit/transport_base_test.rb +3 -16
- data/test/unit/transport_curb_test.rb +4 -17
- data/test/unit/transport_faraday_test.rb +3 -16
- data/test/unit/transport_manticore_test.rb +30 -27
- metadata +42 -16
- data/test/unit/connection_collection_test.rb +0 -147
- data/test/unit/connection_selector_test.rb +0 -81
@@ -0,0 +1,161 @@
|
|
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
|
4
|
+
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe Elasticsearch::Transport::Transport::Connections::Selector do
|
8
|
+
|
9
|
+
before do
|
10
|
+
class BackupStrategySelector
|
11
|
+
include Elasticsearch::Transport::Transport::Connections::Selector::Base
|
12
|
+
|
13
|
+
def select(options={})
|
14
|
+
connections.reject do |c|
|
15
|
+
c.host[:attributes] && c.host[:attributes][:backup]
|
16
|
+
end.sample
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
Object.send(:remove_const, :BackupStrategySelector)
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:backup_strategy_selector) do
|
26
|
+
BackupStrategySelector.new
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'the Random selector' do
|
30
|
+
|
31
|
+
let(:connections) do
|
32
|
+
[1, 2]
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:selector) do
|
36
|
+
described_class::Random.new(connections: connections)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is initialized with connections' do
|
40
|
+
expect(selector.connections).to eq(connections)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#select' do
|
44
|
+
|
45
|
+
let(:connections) do
|
46
|
+
(0..19).to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns a connection' do
|
50
|
+
expect(selector.select).to be_a(Integer)
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when multiple threads are used' do
|
54
|
+
|
55
|
+
it 'allows threads to select connections in parallel' do
|
56
|
+
expect(10.times.collect do
|
57
|
+
threads = []
|
58
|
+
20.times do
|
59
|
+
threads << Thread.new do
|
60
|
+
selector.select
|
61
|
+
end
|
62
|
+
end
|
63
|
+
threads.map { |t| t.join }
|
64
|
+
selector.select
|
65
|
+
end).to all(be_a(Integer))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'the RoundRobin selector' do
|
72
|
+
|
73
|
+
let(:connections) do
|
74
|
+
['A', 'B', 'C']
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:selector) do
|
78
|
+
described_class::RoundRobin.new(connections: connections)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'is initialized with connections' do
|
82
|
+
expect(selector.connections).to eq(connections)
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#select' do
|
86
|
+
|
87
|
+
it 'rotates over the connections' do
|
88
|
+
expect(selector.select).to eq('A')
|
89
|
+
expect(selector.select).to eq('B')
|
90
|
+
expect(selector.select).to eq('C')
|
91
|
+
expect(selector.select).to eq('A')
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when multiple threads are used' do
|
95
|
+
|
96
|
+
let(:connections) do
|
97
|
+
(0..19).to_a
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'returns a connection' do
|
101
|
+
expect(selector.select).to be_a(Integer)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'allows threads to select connections in parallel' do
|
105
|
+
expect(10.times.collect do
|
106
|
+
threads = []
|
107
|
+
20.times do
|
108
|
+
threads << Thread.new do
|
109
|
+
selector.select
|
110
|
+
end
|
111
|
+
end
|
112
|
+
threads.map { |t| t.join }
|
113
|
+
selector.select
|
114
|
+
end).to eq((0..9).to_a)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'a custom selector' do
|
121
|
+
|
122
|
+
let(:connections) do
|
123
|
+
[ double(host: { hostname: 'host1' }),
|
124
|
+
double(host: { hostname: 'host2', attributes: { backup: true } }) ]
|
125
|
+
end
|
126
|
+
|
127
|
+
let(:selector) do
|
128
|
+
BackupStrategySelector.new(connections: connections)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'is initialized with connections' do
|
132
|
+
expect(selector.connections).to eq(connections)
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#select' do
|
136
|
+
|
137
|
+
it 'applies the custom strategy' do
|
138
|
+
10.times { expect(selector.select.host[:hostname]).to eq('host1') }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when the Base module is included in a class' do
|
144
|
+
|
145
|
+
before do
|
146
|
+
class ExampleSelector
|
147
|
+
include Elasticsearch::Transport::Transport::Connections::Selector::Base
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
after do
|
152
|
+
Object.send(:remove_const, :ExampleSelector)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'requires the #select method to be redefined' do
|
156
|
+
expect {
|
157
|
+
ExampleSelector.new.select
|
158
|
+
}.to raise_exception(NoMethodError)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -1,28 +1,12 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V
|
2
|
-
#
|
3
|
-
#
|
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.
|
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
|
17
4
|
|
18
5
|
require 'spec_helper'
|
19
6
|
|
20
7
|
describe Elasticsearch::Transport::Transport::Base do
|
21
|
-
|
22
8
|
context 'when a host is printed in a logged message' do
|
23
|
-
|
24
9
|
shared_examples_for 'a redacted string' do
|
25
|
-
|
26
10
|
let(:client) do
|
27
11
|
Elasticsearch::Transport::Client.new(arguments)
|
28
12
|
end
|
@@ -33,6 +17,7 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
33
17
|
|
34
18
|
it 'does not include the password in the logged string' do
|
35
19
|
expect(logger).not_to receive(:error).with(/secret_password/)
|
20
|
+
|
36
21
|
expect {
|
37
22
|
client.cluster.stats
|
38
23
|
}.to raise_exception(Faraday::ConnectionFailed)
|
@@ -47,7 +32,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
47
32
|
end
|
48
33
|
|
49
34
|
context 'when the user and password are provided as separate arguments' do
|
50
|
-
|
51
35
|
let(:arguments) do
|
52
36
|
{ hosts: 'fake',
|
53
37
|
logger: logger,
|
@@ -59,9 +43,8 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
59
43
|
end
|
60
44
|
|
61
45
|
context 'when the user and password are provided in the string URI' do
|
62
|
-
|
63
46
|
let(:arguments) do
|
64
|
-
{ hosts: '
|
47
|
+
{ hosts: 'https://test:secret_password@fake_local_elasticsearch',
|
65
48
|
logger: logger }
|
66
49
|
end
|
67
50
|
|
@@ -69,13 +52,192 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
69
52
|
end
|
70
53
|
|
71
54
|
context 'when the user and password are provided in the URI object' do
|
72
|
-
|
73
55
|
let(:arguments) do
|
74
|
-
{ hosts: URI.parse('
|
56
|
+
{ hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
|
75
57
|
logger: logger }
|
76
58
|
end
|
77
59
|
|
78
60
|
it_behaves_like 'a redacted string'
|
79
61
|
end
|
80
62
|
end
|
63
|
+
|
64
|
+
context 'when reload_on_failure is true and and hosts are unreachable' do
|
65
|
+
|
66
|
+
let(:client) do
|
67
|
+
Elasticsearch::Transport::Client.new(arguments)
|
68
|
+
end
|
69
|
+
|
70
|
+
let(:arguments) do
|
71
|
+
{
|
72
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
73
|
+
reload_on_failure: true,
|
74
|
+
sniffer_timeout: 5
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'raises an exception' do
|
79
|
+
expect {
|
80
|
+
client.info
|
81
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when the client has `retry_on_failure` set to an integer' do
|
86
|
+
|
87
|
+
let(:client) do
|
88
|
+
Elasticsearch::Transport::Client.new(arguments)
|
89
|
+
end
|
90
|
+
|
91
|
+
let(:arguments) do
|
92
|
+
{
|
93
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
94
|
+
retry_on_failure: 2
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
99
|
+
|
100
|
+
before do
|
101
|
+
expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'uses the client `retry_on_failure` value' do
|
105
|
+
expect {
|
106
|
+
client.transport.perform_request('GET', '/info')
|
107
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
112
|
+
|
113
|
+
before do
|
114
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'uses the option `retry_on_failure` value' do
|
118
|
+
expect {
|
119
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
120
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'when the client has `retry_on_failure` set to true' do
|
126
|
+
|
127
|
+
let(:client) do
|
128
|
+
Elasticsearch::Transport::Client.new(arguments)
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:arguments) do
|
132
|
+
{
|
133
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
134
|
+
retry_on_failure: true
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
139
|
+
|
140
|
+
before do
|
141
|
+
expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'uses the default `MAX_RETRIES` value' do
|
145
|
+
expect {
|
146
|
+
client.transport.perform_request('GET', '/info')
|
147
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
152
|
+
|
153
|
+
before do
|
154
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'uses the option `retry_on_failure` value' do
|
158
|
+
expect {
|
159
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
160
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when the client has `retry_on_failure` set to false' do
|
166
|
+
|
167
|
+
let(:client) do
|
168
|
+
Elasticsearch::Transport::Client.new(arguments)
|
169
|
+
end
|
170
|
+
|
171
|
+
let(:arguments) do
|
172
|
+
{
|
173
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
174
|
+
retry_on_failure: false
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
179
|
+
|
180
|
+
before do
|
181
|
+
expect(client.transport).to receive(:get_connection).once.and_call_original
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'does not retry' do
|
185
|
+
expect {
|
186
|
+
client.transport.perform_request('GET', '/info')
|
187
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
192
|
+
|
193
|
+
before do
|
194
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'uses the option `retry_on_failure` value' do
|
198
|
+
expect {
|
199
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
200
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'when the client has no `retry_on_failure` set' do
|
206
|
+
|
207
|
+
let(:client) do
|
208
|
+
Elasticsearch::Transport::Client.new(arguments)
|
209
|
+
end
|
210
|
+
|
211
|
+
let(:arguments) do
|
212
|
+
{
|
213
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
214
|
+
}
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
218
|
+
|
219
|
+
before do
|
220
|
+
expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'does not retry' do
|
224
|
+
expect {
|
225
|
+
client.transport.perform_request('GET', '/info')
|
226
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
231
|
+
|
232
|
+
before do
|
233
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'uses the option `retry_on_failure` value' do
|
237
|
+
expect {
|
238
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
239
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
81
243
|
end
|