elasticsearch-transport 7.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36ace24392e6a2cf83d15d58aa8ffe9463fd6e61e56ef642f8a87d4ad7d3adba
4
- data.tar.gz: 742a303a48051ca970b7ce13b7dff21a5365e81de9dcd99657e694e7618724f7
3
+ metadata.gz: 271a43455912981268da637666dddf8d9201752ba7b88787284dfc79039ac0e7
4
+ data.tar.gz: 92f3307366179b9eb868b2224e94b87570ffee878a9013d9419f10271731aa6e
5
5
  SHA512:
6
- metadata.gz: bc842fc1fbf9bede1f63c3c820cb67369917e218023dea672e562c0fe643896bca68a6f2adbec8acf4bea158dd736c1133ccee8d2340524502442d97a2ad6b4a
7
- data.tar.gz: 1cb6bb3df3d7ec67223c6ca6ed6084d18dab53fbe189a1d320b6a3e4a721423a738ea30944e8669ef30ae299ad76aff266d22e014f6923b3b69a999abc258a5f
6
+ metadata.gz: 1ead63661251f6b672a28f3bd759b86049f159225bebf2c053fbaaf5a03d3d974082131595980a2e44ef928fdcc640ce85e271398d5e3ac13cd0daaf5daf84a9
7
+ data.tar.gz: 9e99b4a07e919000b06864741380293eb073b0a3ad71e227edf3a9a443b12a4ca26cbe573d33429748561059bec51b4a315345e52d15538e6dab0d84230b8aa2
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.required_ruby_version = '>= 1.9'
28
28
 
29
29
  s.add_dependency "multi_json"
30
- s.add_dependency "faraday"
30
+ s.add_dependency "faraday", '>= 0.14', "< 1"
31
31
 
32
32
  if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
33
33
  s.add_dependency "system_timer"
@@ -68,7 +68,7 @@ Gem::Specification.new do |s|
68
68
  s.add_development_dependency "elasticsearch-extensions"
69
69
  s.add_development_dependency "ruby-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
70
70
  s.add_development_dependency "require-prof" unless defined?(JRUBY_VERSION) || defined?(Rubinius)
71
- s.add_development_dependency "simplecov"
71
+ s.add_development_dependency "simplecov", '~> 0.17', '< 0.18'
72
72
  s.add_development_dependency "simplecov-rcov"
73
73
  s.add_development_dependency "cane"
74
74
  end
@@ -112,7 +112,7 @@ module Elasticsearch
112
112
  @arguments[:randomize_hosts] ||= false
113
113
  @arguments[:transport_options] ||= {}
114
114
  @arguments[:http] ||= {}
115
- @options[:http] ||= {}
115
+ @options[:http] ||= {}
116
116
 
117
117
  @seeds = extract_cloud_creds(@arguments)
118
118
  @seeds ||= __extract_hosts(@arguments[:hosts] ||
@@ -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.5.0"
8
8
  end
9
9
  end
@@ -5,11 +5,8 @@
5
5
  require 'spec_helper'
6
6
 
7
7
  describe Elasticsearch::Transport::Transport::Base do
8
-
9
8
  context 'when a host is printed in a logged message' do
10
-
11
9
  shared_examples_for 'a redacted string' do
12
-
13
10
  let(:client) do
14
11
  Elasticsearch::Transport::Client.new(arguments)
15
12
  end
@@ -20,6 +17,7 @@ describe Elasticsearch::Transport::Transport::Base do
20
17
 
21
18
  it 'does not include the password in the logged string' do
22
19
  expect(logger).not_to receive(:error).with(/secret_password/)
20
+
23
21
  expect {
24
22
  client.cluster.stats
25
23
  }.to raise_exception(Faraday::ConnectionFailed)
@@ -34,7 +32,6 @@ describe Elasticsearch::Transport::Transport::Base do
34
32
  end
35
33
 
36
34
  context 'when the user and password are provided as separate arguments' do
37
-
38
35
  let(:arguments) do
39
36
  { hosts: 'fake',
40
37
  logger: logger,
@@ -46,9 +43,8 @@ describe Elasticsearch::Transport::Transport::Base do
46
43
  end
47
44
 
48
45
  context 'when the user and password are provided in the string URI' do
49
-
50
46
  let(:arguments) do
51
- { hosts: 'http://test:secret_password@fake.com',
47
+ { hosts: 'https://test:secret_password@fake_local_elasticsearch',
52
48
  logger: logger }
53
49
  end
54
50
 
@@ -56,13 +52,192 @@ describe Elasticsearch::Transport::Transport::Base do
56
52
  end
57
53
 
58
54
  context 'when the user and password are provided in the URI object' do
59
-
60
55
  let(:arguments) do
61
- { hosts: URI.parse('http://test:secret_password@fake.com'),
56
+ { hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
62
57
  logger: logger }
63
58
  end
64
59
 
65
60
  it_behaves_like 'a redacted string'
66
61
  end
67
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
68
243
  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.5.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: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -30,14 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.14'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '1'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
- version: '0'
43
+ version: '0.14'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '1'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -294,16 +300,22 @@ dependencies:
294
300
  name: simplecov
295
301
  requirement: !ruby/object:Gem::Requirement
296
302
  requirements:
297
- - - ">="
303
+ - - "~>"
298
304
  - !ruby/object:Gem::Version
299
- version: '0'
305
+ version: '0.17'
306
+ - - "<"
307
+ - !ruby/object:Gem::Version
308
+ version: '0.18'
300
309
  type: :development
301
310
  prerelease: false
302
311
  version_requirements: !ruby/object:Gem::Requirement
303
312
  requirements:
304
- - - ">="
313
+ - - "~>"
305
314
  - !ruby/object:Gem::Version
306
- version: '0'
315
+ version: '0.17'
316
+ - - "<"
317
+ - !ruby/object:Gem::Version
318
+ version: '0.18'
307
319
  - !ruby/object:Gem::Dependency
308
320
  name: simplecov-rcov
309
321
  requirement: !ruby/object:Gem::Requirement
@@ -349,7 +361,7 @@ dependencies:
349
361
  description: 'Ruby client for Elasticsearch. See the `elasticsearch` gem for full
350
362
  integration.
351
363
 
352
- '
364
+ '
353
365
  email:
354
366
  - karel.minarik@elasticsearch.org
355
367
  executables: []
@@ -417,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
417
429
  - !ruby/object:Gem::Version
418
430
  version: '0'
419
431
  requirements: []
420
- rubygems_version: 3.0.3
432
+ rubygems_version: 3.0.6
421
433
  signing_key:
422
434
  specification_version: 4
423
435
  summary: Ruby client for Elasticsearch.