elasticsearch-transport 7.8.1 → 7.9.0.pre
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/lib/elasticsearch/transport/transport/base.rb +9 -8
- data/lib/elasticsearch/transport/transport/connections/connection.rb +3 -2
- data/lib/elasticsearch/transport/transport/sniffer.rb +19 -12
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/transport/sniffer_spec.rb +0 -13
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e172f03d64feff3991f8ef723219c1f3f26824d624cfaee35195168c2224361
|
4
|
+
data.tar.gz: d8039d3a4e5a5f406aae9ff94a56ef0c1068dd985b71c36a4d21d553b3404775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ae8684bffd3b1c1badd932702491266d93dafbe63cc7b02de814601bd120c0955914ff6e3f3220e7cfafe0654f87ecca3fea652c6df4783d106b9749b69eaca
|
7
|
+
data.tar.gz: 8607504cde6a896a5c11d2e7ab753829dddb9c1d7c2ae960e3cdb3a9bfff2f3d46e9bec0790222e7d34f8309ea86d5c096e9646fdadd51cfae6b0891defed73d
|
@@ -47,7 +47,7 @@ module Elasticsearch
|
|
47
47
|
#
|
48
48
|
# @see Client#initialize
|
49
49
|
#
|
50
|
-
def initialize(arguments={}, &block)
|
50
|
+
def initialize(arguments = {}, &block)
|
51
51
|
@state_mutex = Mutex.new
|
52
52
|
|
53
53
|
@hosts = arguments[:hosts] || []
|
@@ -234,9 +234,9 @@ module Elasticsearch
|
|
234
234
|
def __full_url(host)
|
235
235
|
url = "#{host[:protocol]}://"
|
236
236
|
url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user]
|
237
|
-
url +=
|
237
|
+
url += host[:host]
|
238
238
|
url += ":#{host[:port]}" if host[:port]
|
239
|
-
url +=
|
239
|
+
url += host[:path] if host[:path]
|
240
240
|
url
|
241
241
|
end
|
242
242
|
|
@@ -258,8 +258,9 @@ module Elasticsearch
|
|
258
258
|
# @raise [ServerError] If request failed on server
|
259
259
|
# @raise [Error] If no connection is available
|
260
260
|
#
|
261
|
-
def perform_request(method, path, params={}, body=nil, headers=nil, opts={}, &block)
|
262
|
-
raise NoMethodError,
|
261
|
+
def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {}, &block)
|
262
|
+
raise NoMethodError, 'Implement this method in your transport class' unless block_given?
|
263
|
+
|
263
264
|
start = Time.now
|
264
265
|
tries = 0
|
265
266
|
reload_on_failure = opts.fetch(:reload_on_failure, @options[:reload_on_failure])
|
@@ -276,15 +277,15 @@ module Elasticsearch
|
|
276
277
|
|
277
278
|
begin
|
278
279
|
tries += 1
|
279
|
-
connection = get_connection or raise Error.new(
|
280
|
+
connection = get_connection or raise Error.new('Cannot get new connection from pool.')
|
280
281
|
|
281
282
|
if connection.connection.respond_to?(:params) && connection.connection.params.respond_to?(:to_hash)
|
282
283
|
params = connection.connection.params.merge(params.to_hash)
|
283
284
|
end
|
284
285
|
|
285
|
-
url
|
286
|
+
url = connection.full_url(path, params)
|
286
287
|
|
287
|
-
response
|
288
|
+
response = block.call(connection, url)
|
288
289
|
|
289
290
|
connection.healthy! if connection.failures > 0
|
290
291
|
|
@@ -135,14 +135,15 @@ module Elasticsearch
|
|
135
135
|
}
|
136
136
|
end
|
137
137
|
|
138
|
-
# Equality operator based on connection protocol, host and
|
138
|
+
# Equality operator based on connection protocol, host, port and attributes
|
139
139
|
#
|
140
140
|
# @return [Boolean]
|
141
141
|
#
|
142
142
|
def ==(other)
|
143
143
|
self.host[:protocol] == other.host[:protocol] && \
|
144
144
|
self.host[:host] == other.host[:host] && \
|
145
|
-
self.host[:port].to_i == other.host[:port].to_i
|
145
|
+
self.host[:port].to_i == other.host[:port].to_i && \
|
146
|
+
self.host[:attributes] == other.host[:attributes]
|
146
147
|
end
|
147
148
|
|
148
149
|
# @return [String]
|
@@ -45,21 +45,21 @@ module Elasticsearch
|
|
45
45
|
#
|
46
46
|
def hosts
|
47
47
|
Timeout::timeout(timeout, SnifferTimeoutError) do
|
48
|
-
nodes =
|
49
|
-
reload_on_failure: false).body
|
48
|
+
nodes = perform_sniff_request.body
|
50
49
|
|
51
50
|
hosts = nodes['nodes'].map do |id, info|
|
52
|
-
|
53
|
-
|
51
|
+
next unless info[PROTOCOL]
|
52
|
+
host, port = parse_publish_address(info[PROTOCOL]['publish_address'])
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
{
|
55
|
+
id: id,
|
56
|
+
name: info['name'],
|
57
|
+
version: info['version'],
|
58
|
+
host: host,
|
59
|
+
port: port,
|
60
|
+
roles: info['roles'],
|
61
|
+
attributes: info['attributes']
|
62
|
+
}
|
63
63
|
end.compact
|
64
64
|
|
65
65
|
hosts.shuffle! if transport.options[:randomize_hosts]
|
@@ -69,6 +69,13 @@ module Elasticsearch
|
|
69
69
|
|
70
70
|
private
|
71
71
|
|
72
|
+
def perform_sniff_request
|
73
|
+
transport.perform_request(
|
74
|
+
'GET', '_nodes/http', {}, nil, nil,
|
75
|
+
reload_on_failure: false
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
72
79
|
def parse_publish_address(publish_address)
|
73
80
|
# publish_address is in the format hostname/ip:port
|
74
81
|
if publish_address =~ /\//
|
@@ -18,7 +18,6 @@
|
|
18
18
|
require 'spec_helper'
|
19
19
|
|
20
20
|
describe Elasticsearch::Transport::Transport::Sniffer do
|
21
|
-
|
22
21
|
let(:transport) do
|
23
22
|
double('transport').tap do |t|
|
24
23
|
allow(t).to receive(:perform_request).and_return(response)
|
@@ -45,7 +44,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
45
44
|
end
|
46
45
|
|
47
46
|
describe '#initialize' do
|
48
|
-
|
49
47
|
it 'has a transport instance' do
|
50
48
|
expect(sniffer.transport).to be(transport)
|
51
49
|
end
|
@@ -56,7 +54,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
56
54
|
end
|
57
55
|
|
58
56
|
describe '#timeout' do
|
59
|
-
|
60
57
|
let(:sniffer) do
|
61
58
|
described_class.new(double('transport', options: {}))
|
62
59
|
end
|
@@ -71,13 +68,11 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
71
68
|
end
|
72
69
|
|
73
70
|
describe '#hosts' do
|
74
|
-
|
75
71
|
let(:hosts) do
|
76
72
|
sniffer.hosts
|
77
73
|
end
|
78
74
|
|
79
75
|
context 'when the entire response is parsed' do
|
80
|
-
|
81
76
|
let(:raw_response) do
|
82
77
|
{
|
83
78
|
"cluster_name" => "elasticsearch_test",
|
@@ -142,7 +137,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
142
137
|
end
|
143
138
|
|
144
139
|
context 'when the transport protocol does not match' do
|
145
|
-
|
146
140
|
let(:raw_response) do
|
147
141
|
{ 'nodes' => { 'n1' => { 'foo' => { 'publish_address' => '127.0.0.1:9250' } } } }
|
148
142
|
end
|
@@ -153,7 +147,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
153
147
|
end
|
154
148
|
|
155
149
|
context 'when a list of nodes is returned' do
|
156
|
-
|
157
150
|
let(:raw_response) do
|
158
151
|
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
159
152
|
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
@@ -175,7 +168,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
175
168
|
end
|
176
169
|
|
177
170
|
context 'when the host and port are an ip address and port' do
|
178
|
-
|
179
171
|
it 'parses the response' do
|
180
172
|
expect(hosts.size).to eq(1)
|
181
173
|
end
|
@@ -190,7 +182,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
190
182
|
end
|
191
183
|
|
192
184
|
context 'when the host and port are a hostname and port' do
|
193
|
-
|
194
185
|
let(:publish_address) do
|
195
186
|
'testhost1.com:9250'
|
196
187
|
end
|
@@ -213,7 +204,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
213
204
|
end
|
214
205
|
|
215
206
|
context 'when the host and port are in the format: hostname/ip:port' do
|
216
|
-
|
217
207
|
let(:publish_address) do
|
218
208
|
'example.com/127.0.0.1:9250'
|
219
209
|
end
|
@@ -231,7 +221,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
231
221
|
end
|
232
222
|
|
233
223
|
context 'when the address is IPv6' do
|
234
|
-
|
235
224
|
let(:publish_address) do
|
236
225
|
'example.com/[::1]:9250'
|
237
226
|
end
|
@@ -251,7 +240,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
251
240
|
end
|
252
241
|
|
253
242
|
context 'when the address is IPv6' do
|
254
|
-
|
255
243
|
let(:publish_address) do
|
256
244
|
'[::1]:9250'
|
257
245
|
end
|
@@ -270,7 +258,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
270
258
|
end
|
271
259
|
|
272
260
|
context 'when the transport has :randomize_hosts option' do
|
273
|
-
|
274
261
|
let(:raw_response) do
|
275
262
|
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
276
263
|
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
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.9.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -423,9 +423,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
423
423
|
version: '2.4'
|
424
424
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
425
425
|
requirements:
|
426
|
-
- - "
|
426
|
+
- - ">"
|
427
427
|
- !ruby/object:Gem::Version
|
428
|
-
version:
|
428
|
+
version: 1.3.1
|
429
429
|
requirements: []
|
430
430
|
rubygems_version: 3.1.4
|
431
431
|
signing_key:
|