elasticsearch-transport 7.0.0 → 7.1.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/README.md +17 -14
- data/lib/elasticsearch/transport/client.rb +6 -3
- data/lib/elasticsearch/transport/transport/base.rb +1 -1
- data/lib/elasticsearch/transport/transport/http/faraday.rb +1 -1
- data/lib/elasticsearch/transport/transport/sniffer.rb +1 -1
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/transport/client_spec.rb +257 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14188a454b64314c13f7c9279741fc8df5f9f03ff9813f45aeca96abc8da7e39
|
4
|
+
data.tar.gz: dfcd7ac5fb8e0b2a0450b2939272f88a329581648c47b130d62e1fcead705b44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e9583f541ec75994cb27479c16f4624d7ea6a9e6f33360d7cac69541fe10a5c2ee2d7f20b2c1231b5fd07ab85cd32baefb236d6ab77ff11635bb23b1d9d801
|
7
|
+
data.tar.gz: 95faf1016519c04dcafcd6580356dcfb00c8eeb9ef3301bf2ff3c66a90cfcc8ebf676b638ec18f92f708acb5ef01ee2f7ee137f23ed6532774b371e47b02e11f
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ please refer to it, unless you want to use this library standalone.**
|
|
6
6
|
----
|
7
7
|
|
8
8
|
The `elasticsearch-transport` library provides a low-level Ruby client for connecting
|
9
|
-
to an [Elasticsearch](http://elasticsearch.
|
9
|
+
to an [Elasticsearch](http://elasticsearch.com) cluster.
|
10
10
|
|
11
11
|
It handles connecting to multiple nodes in the cluster, rotating across connections,
|
12
12
|
logging and tracing requests and responses, maintaining failed connections,
|
@@ -194,7 +194,7 @@ Elasticsearch by default dynamically discovers new nodes in the cluster. You can
|
|
194
194
|
in the client, and periodically check for new nodes to spread the load.
|
195
195
|
|
196
196
|
To retrieve and use the information from the
|
197
|
-
[_Nodes Info API_](http://www.
|
197
|
+
[_Nodes Info API_](http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-info.html)
|
198
198
|
on every 10,000th request:
|
199
199
|
|
200
200
|
Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], reload_connections: true
|
@@ -460,16 +460,19 @@ can use Ruby 2.x syntax and features.
|
|
460
460
|
|
461
461
|
This software is licensed under the Apache 2 license, quoted below.
|
462
462
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
463
|
+
Licensed to Elasticsearch B.V. under one or more contributor
|
464
|
+
license agreements. See the NOTICE file distributed with
|
465
|
+
this work for additional information regarding copyright
|
466
|
+
ownership. Elasticsearch B.V. licenses this file to you under
|
467
|
+
the Apache License, Version 2.0 (the "License"); you may
|
468
|
+
not use this file except in compliance with the License.
|
467
469
|
You may obtain a copy of the License at
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
Unless required by applicable law or agreed to in writing,
|
472
|
-
distributed under the License is distributed on an
|
473
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
474
|
-
See the License for the
|
475
|
-
|
470
|
+
|
471
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
472
|
+
|
473
|
+
Unless required by applicable law or agreed to in writing,
|
474
|
+
software distributed under the License is distributed on an
|
475
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
476
|
+
KIND, either express or implied. See the License for the
|
477
|
+
specific language governing permissions and limitations
|
478
|
+
under the License.
|
@@ -105,8 +105,8 @@ module Elasticsearch
|
|
105
105
|
# @yield [faraday] Access and configure the `Faraday::Connection` instance directly with a block
|
106
106
|
#
|
107
107
|
def initialize(arguments={}, &block)
|
108
|
-
@options = arguments
|
109
|
-
@arguments =
|
108
|
+
@options = arguments.each_with_object({}){ |(k,v), args| args[k.to_sym] = v }
|
109
|
+
@arguments = @options
|
110
110
|
@arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call() : nil
|
111
111
|
@arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call() : nil
|
112
112
|
@arguments[:reload_connections] ||= false
|
@@ -194,7 +194,10 @@ module Elasticsearch
|
|
194
194
|
host_parts = case host
|
195
195
|
when String
|
196
196
|
if host =~ /^[a-z]+\:\/\//
|
197
|
-
|
197
|
+
# Construct a new `URI::Generic` directly from the array returned by URI::split.
|
198
|
+
# This avoids `URI::HTTP` and `URI::HTTPS`, which supply default ports.
|
199
|
+
uri = URI::Generic.new(*URI.split(host))
|
200
|
+
|
198
201
|
{ :scheme => uri.scheme,
|
199
202
|
:user => uri.user,
|
200
203
|
:password => uri.password,
|
@@ -284,7 +284,7 @@ module Elasticsearch
|
|
284
284
|
__raise_transport_error(response) if response.status.to_i >= 300 && @retry_on_status.include?(response.status.to_i)
|
285
285
|
|
286
286
|
rescue Elasticsearch::Transport::Transport::ServerError => e
|
287
|
-
if @retry_on_status.include?(response.status)
|
287
|
+
if response && @retry_on_status.include?(response.status)
|
288
288
|
log_warn "[#{e.class}] Attempt #{tries} to get response from #{url}"
|
289
289
|
if tries <= max_retries
|
290
290
|
retry
|
@@ -51,7 +51,7 @@ module Elasticsearch
|
|
51
51
|
# @return [Connections::Connection]
|
52
52
|
#
|
53
53
|
def __build_connection(host, options={}, block=nil)
|
54
|
-
client = ::Faraday
|
54
|
+
client = ::Faraday.new(__full_url(host), options, &block)
|
55
55
|
Connections::Connection.new :host => host, :connection => client
|
56
56
|
end
|
57
57
|
|
@@ -35,7 +35,7 @@ module Elasticsearch
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Retrieves the node list from the Elasticsearch's
|
38
|
-
# [_Nodes Info API_](
|
38
|
+
# [_Nodes Info API_](https://www.elastic.co/guide/reference/api/admin-cluster-nodes-info/)
|
39
39
|
# and returns a normalized Array of information suitable for passing to transport.
|
40
40
|
#
|
41
41
|
# Shuffles the collection before returning it when the `randomize_hosts` option is set for transport.
|
@@ -68,7 +68,22 @@ describe Elasticsearch::Transport::Client do
|
|
68
68
|
described_class.new(adapter: :typhoeus)
|
69
69
|
end
|
70
70
|
|
71
|
-
it 'uses Faraday' do
|
71
|
+
it 'uses Faraday with the adapter' do
|
72
|
+
expect(adapter).to include(Faraday::Adapter::Typhoeus)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when the adapter is specified as a string key' do
|
77
|
+
|
78
|
+
let(:adapter) do
|
79
|
+
client.transport.connections.all.first.connection.builder.handlers
|
80
|
+
end
|
81
|
+
|
82
|
+
let(:client) do
|
83
|
+
described_class.new('adapter' => :typhoeus)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'uses Faraday with the adapter' do
|
72
87
|
expect(adapter).to include(Faraday::Adapter::Typhoeus)
|
73
88
|
end
|
74
89
|
end
|
@@ -126,6 +141,30 @@ describe Elasticsearch::Transport::Client do
|
|
126
141
|
expect(hosts[0][:port]).to be(9200)
|
127
142
|
end
|
128
143
|
|
144
|
+
context 'when IPv6 format is used' do
|
145
|
+
|
146
|
+
around do |example|
|
147
|
+
original_setting = Faraday.ignore_env_proxy
|
148
|
+
Faraday.ignore_env_proxy = true
|
149
|
+
example.run
|
150
|
+
Faraday.ignore_env_proxy = original_setting
|
151
|
+
end
|
152
|
+
|
153
|
+
let(:host) do
|
154
|
+
'https://[2090:db8:85a3:9811::1f]:8080'
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'extracts the host' do
|
158
|
+
expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]')
|
159
|
+
expect(hosts[0][:scheme]).to eq('https')
|
160
|
+
expect(hosts[0][:port]).to be(8080)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'creates the correct full url' do
|
164
|
+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:8080')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
129
168
|
context 'when a path is specified' do
|
130
169
|
|
131
170
|
let(:host) do
|
@@ -207,6 +246,53 @@ describe Elasticsearch::Transport::Client do
|
|
207
246
|
expect(hosts[0][:port]).to be(9200)
|
208
247
|
end
|
209
248
|
|
249
|
+
context 'when IPv6 format is used' do
|
250
|
+
|
251
|
+
around do |example|
|
252
|
+
original_setting = Faraday.ignore_env_proxy
|
253
|
+
Faraday.ignore_env_proxy = true
|
254
|
+
example.run
|
255
|
+
Faraday.ignore_env_proxy = original_setting
|
256
|
+
end
|
257
|
+
|
258
|
+
let(:host) do
|
259
|
+
{ host: '[2090:db8:85a3:9811::1f]', scheme: 'https', port: '443' }
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'extracts the host' do
|
263
|
+
expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]')
|
264
|
+
expect(hosts[0][:scheme]).to eq('https')
|
265
|
+
expect(hosts[0][:port]).to be(443)
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'creates the correct full url' do
|
269
|
+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:443')
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context 'when the host is localhost as a IPv6 address' do
|
274
|
+
|
275
|
+
around do |example|
|
276
|
+
original_setting = Faraday.ignore_env_proxy
|
277
|
+
Faraday.ignore_env_proxy = true
|
278
|
+
example.run
|
279
|
+
Faraday.ignore_env_proxy = original_setting
|
280
|
+
end
|
281
|
+
|
282
|
+
let(:host) do
|
283
|
+
{ host: '[::1]' }
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'extracts the host' do
|
287
|
+
expect(hosts[0][:host]).to eq('[::1]')
|
288
|
+
expect(hosts[0][:port]).to be(9200)
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'creates the correct full url' do
|
292
|
+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('http://[::1]:9200')
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
210
296
|
context 'when the port is specified as a String' do
|
211
297
|
|
212
298
|
let(:host) do
|
@@ -288,6 +374,79 @@ describe Elasticsearch::Transport::Client do
|
|
288
374
|
end
|
289
375
|
end
|
290
376
|
|
377
|
+
context 'when there is one host with a protocol and no port' do
|
378
|
+
|
379
|
+
let(:host) do
|
380
|
+
['http://myhost']
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'extracts the host' do
|
384
|
+
expect(hosts[0][:host]).to eq('myhost')
|
385
|
+
expect(hosts[0][:protocol]).to eq('http')
|
386
|
+
expect(hosts[0][:port]).to be(9200)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
context 'when there is one host with a protocol and no port' do
|
391
|
+
|
392
|
+
let(:host) do
|
393
|
+
['http://myhost']
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'extracts the host' do
|
397
|
+
expect(hosts[0][:host]).to eq('myhost')
|
398
|
+
expect(hosts[0][:protocol]).to eq('http')
|
399
|
+
expect(hosts[0][:port]).to be(9200)
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
context 'when there is one host with a protocol and the default http port explicitly provided' do
|
404
|
+
let(:host) do
|
405
|
+
['http://myhost:80']
|
406
|
+
end
|
407
|
+
|
408
|
+
it 'respects the explicit port' do
|
409
|
+
expect(hosts[0][:port]).to be(80)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
context 'when there is one host with a protocol and the default https port explicitly provided' do
|
414
|
+
let(:host) do
|
415
|
+
['https://myhost:443']
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'respects the explicit port' do
|
419
|
+
expect(hosts[0][:port]).to be(443)
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
context 'when there is one host with a scheme, protocol and no port' do
|
424
|
+
|
425
|
+
let(:host) do
|
426
|
+
['https://myhost']
|
427
|
+
end
|
428
|
+
|
429
|
+
it 'extracts the host' do
|
430
|
+
expect(hosts[0][:host]).to eq('myhost')
|
431
|
+
expect(hosts[0][:protocol]).to eq('https')
|
432
|
+
expect(hosts[0][:port]).to be(9200)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
context 'when there is one host with a scheme, protocol, path, and no port' do
|
437
|
+
|
438
|
+
let(:host) do
|
439
|
+
['http://myhost/foo/bar']
|
440
|
+
end
|
441
|
+
|
442
|
+
it 'extracts the host' do
|
443
|
+
expect(hosts[0][:host]).to eq('myhost')
|
444
|
+
expect(hosts[0][:protocol]).to eq('http')
|
445
|
+
expect(hosts[0][:port]).to be(9200)
|
446
|
+
expect(hosts[0][:path]).to eq("/foo/bar")
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
291
450
|
context 'when there is more than one host' do
|
292
451
|
|
293
452
|
let(:host) do
|
@@ -353,7 +512,7 @@ describe Elasticsearch::Transport::Client do
|
|
353
512
|
context 'when hosts are specified with the \'host\' key' do
|
354
513
|
|
355
514
|
let(:client) do
|
356
|
-
described_class.new(
|
515
|
+
described_class.new(host: ['host1', 'host2', 'host3', 'host4'], randomize_hosts: true)
|
357
516
|
end
|
358
517
|
|
359
518
|
let(:hosts) do
|
@@ -365,23 +524,38 @@ describe Elasticsearch::Transport::Client do
|
|
365
524
|
end
|
366
525
|
end
|
367
526
|
|
368
|
-
context 'when hosts are specified with the \'host\' key' do
|
527
|
+
context 'when hosts are specified with the \'host\' key as a String' do
|
369
528
|
|
370
529
|
let(:client) do
|
371
|
-
described_class.new(host
|
530
|
+
described_class.new('host' => ['host1', 'host2', 'host3', 'host4'], 'randomize_hosts' => true)
|
372
531
|
end
|
373
532
|
|
374
533
|
let(:hosts) do
|
375
534
|
client.transport.hosts
|
376
535
|
end
|
377
536
|
|
378
|
-
|
537
|
+
it 'sets the hosts in random order' do
|
538
|
+
expect(hosts.all? { |host| client.transport.hosts.include?(host) }).to be(true)
|
539
|
+
end
|
379
540
|
end
|
380
541
|
|
381
542
|
context 'when hosts are specified with the \'hosts\' key' do
|
382
543
|
|
383
544
|
let(:client) do
|
384
|
-
described_class.new(
|
545
|
+
described_class.new(hosts: host)
|
546
|
+
end
|
547
|
+
|
548
|
+
let(:hosts) do
|
549
|
+
client.transport.hosts
|
550
|
+
end
|
551
|
+
|
552
|
+
it_behaves_like 'a client that extracts hosts'
|
553
|
+
end
|
554
|
+
|
555
|
+
context 'when hosts are specified with the \'hosts\' key as a String' do
|
556
|
+
|
557
|
+
let(:client) do
|
558
|
+
described_class.new('hosts' => host)
|
385
559
|
end
|
386
560
|
|
387
561
|
let(:hosts) do
|
@@ -394,7 +568,20 @@ describe Elasticsearch::Transport::Client do
|
|
394
568
|
context 'when hosts are specified with the \'url\' key' do
|
395
569
|
|
396
570
|
let(:client) do
|
397
|
-
described_class.new(
|
571
|
+
described_class.new(url: host)
|
572
|
+
end
|
573
|
+
|
574
|
+
let(:hosts) do
|
575
|
+
client.transport.hosts
|
576
|
+
end
|
577
|
+
|
578
|
+
it_behaves_like 'a client that extracts hosts'
|
579
|
+
end
|
580
|
+
|
581
|
+
context 'when hosts are specified with the \'url\' key as a String' do
|
582
|
+
|
583
|
+
let(:client) do
|
584
|
+
described_class.new('url' => host)
|
398
585
|
end
|
399
586
|
|
400
587
|
let(:hosts) do
|
@@ -407,7 +594,20 @@ describe Elasticsearch::Transport::Client do
|
|
407
594
|
context 'when hosts are specified with the \'urls\' key' do
|
408
595
|
|
409
596
|
let(:client) do
|
410
|
-
described_class.new(
|
597
|
+
described_class.new(urls: host)
|
598
|
+
end
|
599
|
+
|
600
|
+
let(:hosts) do
|
601
|
+
client.transport.hosts
|
602
|
+
end
|
603
|
+
|
604
|
+
it_behaves_like 'a client that extracts hosts'
|
605
|
+
end
|
606
|
+
|
607
|
+
context 'when hosts are specified with the \'urls\' key as a String' do
|
608
|
+
|
609
|
+
let(:client) do
|
610
|
+
described_class.new('urls' => host)
|
411
611
|
end
|
412
612
|
|
413
613
|
let(:hosts) do
|
@@ -464,6 +664,17 @@ describe Elasticsearch::Transport::Client do
|
|
464
664
|
end
|
465
665
|
end
|
466
666
|
|
667
|
+
context 'when scheme is specified as a String key' do
|
668
|
+
|
669
|
+
let(:client) do
|
670
|
+
described_class.new('scheme' => 'https')
|
671
|
+
end
|
672
|
+
|
673
|
+
it 'sets the scheme' do
|
674
|
+
expect(client.transport.connections[0].full_url('')).to match(/https/)
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
467
678
|
context 'when user and password are specified' do
|
468
679
|
|
469
680
|
let(:client) do
|
@@ -490,6 +701,32 @@ describe Elasticsearch::Transport::Client do
|
|
490
701
|
end
|
491
702
|
end
|
492
703
|
|
704
|
+
context 'when user and password are specified as String keys' do
|
705
|
+
|
706
|
+
let(:client) do
|
707
|
+
described_class.new('user' => 'USERNAME', 'password' => 'PASSWORD')
|
708
|
+
end
|
709
|
+
|
710
|
+
it 'sets the user and password' do
|
711
|
+
expect(client.transport.connections[0].full_url('')).to match(/USERNAME/)
|
712
|
+
expect(client.transport.connections[0].full_url('')).to match(/PASSWORD/)
|
713
|
+
end
|
714
|
+
|
715
|
+
context 'when the connections are reloaded' do
|
716
|
+
|
717
|
+
before do
|
718
|
+
allow(client.transport.sniffer).to receive(:hosts).and_return([{ host: 'foobar', port: 4567, id: 'foobar4567' }])
|
719
|
+
client.transport.reload_connections!
|
720
|
+
end
|
721
|
+
|
722
|
+
it 'sets keeps user and password' do
|
723
|
+
expect(client.transport.connections[0].full_url('')).to match(/USERNAME/)
|
724
|
+
expect(client.transport.connections[0].full_url('')).to match(/PASSWORD/)
|
725
|
+
expect(client.transport.connections[0].full_url('')).to match(/foobar/)
|
726
|
+
end
|
727
|
+
end
|
728
|
+
end
|
729
|
+
|
493
730
|
context 'when port is specified' do
|
494
731
|
|
495
732
|
let(:client) do
|
@@ -574,6 +811,17 @@ describe Elasticsearch::Transport::Client do
|
|
574
811
|
expect(client.transport.options[:transport_options][:request]).to eq(timeout: 120)
|
575
812
|
end
|
576
813
|
end
|
814
|
+
|
815
|
+
context 'when \'request_timeout\' is defined as a String key' do
|
816
|
+
|
817
|
+
let(:client) do
|
818
|
+
described_class.new('request_timeout' => 120)
|
819
|
+
end
|
820
|
+
|
821
|
+
it 'sets the options on the transport' do
|
822
|
+
expect(client.transport.options[:transport_options][:request]).to eq(timeout: 120)
|
823
|
+
end
|
824
|
+
end
|
577
825
|
end
|
578
826
|
|
579
827
|
describe '#perform_request' do
|
@@ -926,4 +1174,4 @@ describe Elasticsearch::Transport::Client do
|
|
926
1174
|
end
|
927
1175
|
end
|
928
1176
|
end
|
929
|
-
end
|
1177
|
+
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.
|
4
|
+
version: 7.1.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-
|
11
|
+
date: 2019-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|