elasticsearch-transport 7.3.0 → 7.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36ace24392e6a2cf83d15d58aa8ffe9463fd6e61e56ef642f8a87d4ad7d3adba
4
- data.tar.gz: 742a303a48051ca970b7ce13b7dff21a5365e81de9dcd99657e694e7618724f7
3
+ metadata.gz: f792f084ecb5b37684ed211a3ffc92db1bda2f7bf86bc6e24502d11eb4c3d01f
4
+ data.tar.gz: 3816c9f77491b8984b5041d4b83afb8a2fc64212f6fa3e3f9ea05058fe3d3910
5
5
  SHA512:
6
- metadata.gz: bc842fc1fbf9bede1f63c3c820cb67369917e218023dea672e562c0fe643896bca68a6f2adbec8acf4bea158dd736c1133ccee8d2340524502442d97a2ad6b4a
7
- data.tar.gz: 1cb6bb3df3d7ec67223c6ca6ed6084d18dab53fbe189a1d320b6a3e4a721423a738ea30944e8669ef30ae299ad76aff266d22e014f6923b3b69a999abc258a5f
6
+ metadata.gz: 83232686c134cfb686d8ab8e9103da88f8b08a64661c103aeecede0c7cbfacdd80b668dfa67ad93b2b5f035865ce7ae125db0ce1e1ce6bd6a32ff7c9133d5c83
7
+ data.tar.gz: 59f44c2691078611f06b01593a74c61bbab87f055c4d7f3ae5249a7dfebd581fb37660babffb352c88db1d8bd6ffcefe6f73519019474e6d64037c09e42e421f
@@ -22,7 +22,7 @@ module Elasticsearch
22
22
  attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol
23
23
  attr_accessor :serializer, :sniffer, :logger, :tracer,
24
24
  :reload_connections, :reload_after,
25
- :resurrect_after, :max_retries
25
+ :resurrect_after
26
26
 
27
27
  # Creates a new transport object
28
28
  #
@@ -59,7 +59,6 @@ module Elasticsearch
59
59
  @reload_connections = options[:reload_connections]
60
60
  @reload_after = options[:reload_connections].is_a?(Integer) ? options[:reload_connections] : DEFAULT_RELOAD_AFTER
61
61
  @resurrect_after = options[:resurrect_after] || DEFAULT_RESURRECT_AFTER
62
- @max_retries = options[:retry_on_failure].is_a?(Integer) ? options[:retry_on_failure] : DEFAULT_MAX_RETRIES
63
62
  @retry_on_status = Array(options[:retry_on_status]).map { |d| d.to_i }
64
63
  end
65
64
 
@@ -246,10 +245,17 @@ module Elasticsearch
246
245
  # @raise [ServerError] If request failed on server
247
246
  # @raise [Error] If no connection is available
248
247
  #
249
- def perform_request(method, path, params={}, body=nil, headers=nil, &block)
248
+ def perform_request(method, path, params={}, body=nil, headers=nil, opts={}, &block)
250
249
  raise NoMethodError, "Implement this method in your transport class" unless block_given?
251
250
  start = Time.now
252
251
  tries = 0
252
+ reload_on_failure = opts.fetch(:reload_on_failure, @options[:reload_on_failure])
253
+
254
+ max_retries = if opts.key?(:retry_on_failure)
255
+ opts[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : opts[:retry_on_failure]
256
+ elsif options.key?(:retry_on_failure)
257
+ options[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : options[:retry_on_failure]
258
+ end
253
259
 
254
260
  params = params.clone
255
261
 
@@ -275,7 +281,7 @@ module Elasticsearch
275
281
  rescue Elasticsearch::Transport::Transport::ServerError => e
276
282
  if response && @retry_on_status.include?(response.status)
277
283
  log_warn "[#{e.class}] Attempt #{tries} to get response from #{url}"
278
- if tries <= max_retries
284
+ if tries <= (max_retries || DEFAULT_MAX_RETRIES)
279
285
  retry
280
286
  else
281
287
  log_fatal "[#{e.class}] Cannot get response from #{url} after #{tries} tries"
@@ -290,12 +296,12 @@ module Elasticsearch
290
296
 
291
297
  connection.dead!
292
298
 
293
- if @options[:reload_on_failure] and tries < connections.all.size
299
+ if reload_on_failure and tries < connections.all.size
294
300
  log_warn "[#{e.class}] Reloading connections (attempt #{tries} of #{connections.all.size})"
295
301
  reload_connections! and retry
296
302
  end
297
303
 
298
- if @options[:retry_on_failure]
304
+ if max_retries
299
305
  log_warn "[#{e.class}] Attempt #{tries} connecting to #{connection.host.inspect}"
300
306
  if tries <= max_retries
301
307
  retry
@@ -19,7 +19,7 @@ module Elasticsearch
19
19
  # @return [Response]
20
20
  # @see Transport::Base#perform_request
21
21
  #
22
- def perform_request(method, path, params={}, body=nil, headers=nil)
22
+ def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
23
23
  super do |connection, url|
24
24
  connection.connection.url = connection.full_url(path, params)
25
25
 
@@ -20,7 +20,7 @@ module Elasticsearch
20
20
  # @return [Response]
21
21
  # @see Transport::Base#perform_request
22
22
  #
23
- def perform_request(method, path, params={}, body=nil, headers=nil)
23
+ def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
24
24
  super do |connection, url|
25
25
  headers = headers || connection.connection.headers
26
26
 
@@ -67,7 +67,7 @@ module Elasticsearch
67
67
  # @return [Response]
68
68
  # @see Transport::Base#perform_request
69
69
  #
70
- def perform_request(method, path, params={}, body=nil, headers=nil)
70
+ def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
71
71
  super do |connection, url|
72
72
  params[:body] = __convert_to_json(body) if body
73
73
  params[:headers] = headers if headers
@@ -32,7 +32,8 @@ module Elasticsearch
32
32
  #
33
33
  def hosts
34
34
  Timeout::timeout(timeout, SnifferTimeoutError) do
35
- nodes = transport.perform_request('GET', '_nodes/http').body
35
+ nodes = transport.perform_request('GET', '_nodes/http', {}, nil, nil,
36
+ reload_on_failure: false).body
36
37
 
37
38
  hosts = nodes['nodes'].map do |id, info|
38
39
  if info[PROTOCOL]
@@ -4,6 +4,6 @@
4
4
 
5
5
  module Elasticsearch
6
6
  module Transport
7
- VERSION = "7.3.0"
7
+ VERSION = "7.4.0"
8
8
  end
9
9
  end
@@ -65,4 +65,184 @@ describe Elasticsearch::Transport::Transport::Base do
65
65
  it_behaves_like 'a redacted string'
66
66
  end
67
67
  end
68
+
69
+ context 'when reload_on_failure is true and and hosts are unreachable' do
70
+
71
+ let(:client) do
72
+ Elasticsearch::Transport::Client.new(arguments)
73
+ end
74
+
75
+ let(:arguments) do
76
+ {
77
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
78
+ reload_on_failure: true,
79
+ sniffer_timeout: 5
80
+ }
81
+ end
82
+
83
+ it 'raises an exception' do
84
+ expect {
85
+ client.info
86
+ }.to raise_exception(Faraday::ConnectionFailed)
87
+ end
88
+ end
89
+
90
+ context 'when the client has `retry_on_failure` set to an integer' do
91
+
92
+ let(:client) do
93
+ Elasticsearch::Transport::Client.new(arguments)
94
+ end
95
+
96
+ let(:arguments) do
97
+ {
98
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
99
+ retry_on_failure: 2
100
+ }
101
+ end
102
+
103
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
104
+
105
+ before do
106
+ expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
107
+ end
108
+
109
+ it 'uses the client `retry_on_failure` value' do
110
+ expect {
111
+ client.transport.perform_request('GET', '/info')
112
+ }.to raise_exception(Faraday::ConnectionFailed)
113
+ end
114
+ end
115
+
116
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
117
+
118
+ before do
119
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
120
+ end
121
+
122
+ it 'uses the option `retry_on_failure` value' do
123
+ expect {
124
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
125
+ }.to raise_exception(Faraday::ConnectionFailed)
126
+ end
127
+ end
128
+ end
129
+
130
+ context 'when the client has `retry_on_failure` set to true' do
131
+
132
+ let(:client) do
133
+ Elasticsearch::Transport::Client.new(arguments)
134
+ end
135
+
136
+ let(:arguments) do
137
+ {
138
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
139
+ retry_on_failure: true
140
+ }
141
+ end
142
+
143
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
144
+
145
+ before do
146
+ expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
147
+ end
148
+
149
+ it 'uses the default `MAX_RETRIES` value' do
150
+ expect {
151
+ client.transport.perform_request('GET', '/info')
152
+ }.to raise_exception(Faraday::ConnectionFailed)
153
+ end
154
+ end
155
+
156
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
157
+
158
+ before do
159
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
160
+ end
161
+
162
+ it 'uses the option `retry_on_failure` value' do
163
+ expect {
164
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
165
+ }.to raise_exception(Faraday::ConnectionFailed)
166
+ end
167
+ end
168
+ end
169
+
170
+ context 'when the client has `retry_on_failure` set to false' do
171
+
172
+ let(:client) do
173
+ Elasticsearch::Transport::Client.new(arguments)
174
+ end
175
+
176
+ let(:arguments) do
177
+ {
178
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
179
+ retry_on_failure: false
180
+ }
181
+ end
182
+
183
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
184
+
185
+ before do
186
+ expect(client.transport).to receive(:get_connection).once.and_call_original
187
+ end
188
+
189
+ it 'does not retry' do
190
+ expect {
191
+ client.transport.perform_request('GET', '/info')
192
+ }.to raise_exception(Faraday::ConnectionFailed)
193
+ end
194
+ end
195
+
196
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
197
+
198
+ before do
199
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
200
+ end
201
+
202
+ it 'uses the option `retry_on_failure` value' do
203
+ expect {
204
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
205
+ }.to raise_exception(Faraday::ConnectionFailed)
206
+ end
207
+ end
208
+ end
209
+
210
+ context 'when the client has no `retry_on_failure` set' do
211
+
212
+ let(:client) do
213
+ Elasticsearch::Transport::Client.new(arguments)
214
+ end
215
+
216
+ let(:arguments) do
217
+ {
218
+ hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
219
+ }
220
+ end
221
+
222
+ context 'when `perform_request` is called without a `retry_on_failure` option value' do
223
+
224
+ before do
225
+ expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
226
+ end
227
+
228
+ it 'does not retry' do
229
+ expect {
230
+ client.transport.perform_request('GET', '/info')
231
+ }.to raise_exception(Faraday::ConnectionFailed)
232
+ end
233
+ end
234
+
235
+ context 'when `perform_request` is called with a `retry_on_failure` option value' do
236
+
237
+ before do
238
+ expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
239
+ end
240
+
241
+ it 'uses the option `retry_on_failure` value' do
242
+ expect {
243
+ client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
244
+ }.to raise_exception(Faraday::ConnectionFailed)
245
+ end
246
+ end
247
+ end
68
248
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.0
4
+ version: 7.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-01 00:00:00.000000000 Z
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -417,7 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
417
417
  - !ruby/object:Gem::Version
418
418
  version: '0'
419
419
  requirements: []
420
- rubygems_version: 3.0.3
420
+ rubygems_version: 3.0.6
421
421
  signing_key:
422
422
  specification_version: 4
423
423
  summary: Ruby client for Elasticsearch.