elasticsearch-transport 5.0.5 → 6.8.3
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 +5 -5
- data/Gemfile +5 -0
- data/README.md +88 -34
- data/Rakefile +14 -17
- data/elasticsearch-transport.gemspec +45 -63
- data/lib/elasticsearch/transport/client.rb +207 -67
- data/lib/elasticsearch/transport/redacted.rb +79 -0
- data/lib/elasticsearch/transport/transport/base.rb +28 -14
- data/lib/elasticsearch/transport/transport/connections/collection.rb +4 -0
- data/lib/elasticsearch/transport/transport/connections/connection.rb +5 -1
- data/lib/elasticsearch/transport/transport/connections/selector.rb +4 -0
- data/lib/elasticsearch/transport/transport/errors.rb +4 -0
- data/lib/elasticsearch/transport/transport/http/curb.rb +7 -2
- data/lib/elasticsearch/transport/transport/http/faraday.rb +11 -8
- data/lib/elasticsearch/transport/transport/http/manticore.rb +6 -1
- data/lib/elasticsearch/transport/transport/response.rb +4 -0
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +4 -0
- data/lib/elasticsearch/transport/transport/sniffer.rb +31 -3
- data/lib/elasticsearch/transport/version.rb +5 -1
- data/lib/elasticsearch/transport.rb +5 -0
- data/lib/elasticsearch-transport.rb +4 -0
- data/spec/elasticsearch/transport/base_spec.rb +260 -0
- data/spec/elasticsearch/transport/client_spec.rb +1063 -0
- data/spec/elasticsearch/transport/meta_header_spec.rb +214 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +269 -0
- data/spec/spec_helper.rb +72 -0
- data/test/integration/transport_test.rb +9 -5
- data/test/profile/client_benchmark_test.rb +23 -25
- data/test/test_helper.rb +10 -0
- data/test/unit/connection_collection_test.rb +4 -0
- data/test/unit/connection_selector_test.rb +4 -0
- data/test/unit/connection_test.rb +4 -0
- data/test/unit/response_test.rb +5 -1
- data/test/unit/serializer_test.rb +4 -0
- data/test/unit/transport_base_test.rb +21 -1
- data/test/unit/transport_curb_test.rb +12 -0
- data/test/unit/transport_faraday_test.rb +16 -0
- data/test/unit/transport_manticore_test.rb +11 -0
- metadata +90 -76
- data/test/integration/client_test.rb +0 -237
- data/test/unit/client_test.rb +0 -366
- data/test/unit/sniffer_test.rb +0 -179
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
require 'manticore'
|
2
6
|
|
3
7
|
module Elasticsearch
|
@@ -63,9 +67,10 @@ module Elasticsearch
|
|
63
67
|
# @return [Response]
|
64
68
|
# @see Transport::Base#perform_request
|
65
69
|
#
|
66
|
-
def perform_request(method, path, params={}, body=nil)
|
70
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
67
71
|
super do |connection, url|
|
68
72
|
params[:body] = __convert_to_json(body) if body
|
73
|
+
params[:headers] = headers if headers
|
69
74
|
params = params.merge @request_options
|
70
75
|
case method
|
71
76
|
when "GET"
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -28,11 +32,12 @@ module Elasticsearch
|
|
28
32
|
#
|
29
33
|
def hosts
|
30
34
|
Timeout::timeout(timeout, SnifferTimeoutError) do
|
31
|
-
nodes = transport.perform_request('GET', '_nodes/http'
|
35
|
+
nodes = transport.perform_request('GET', '_nodes/http', {}, nil, nil,
|
36
|
+
reload_on_failure: false).body
|
32
37
|
|
33
|
-
hosts = nodes['nodes'].map do |id,info|
|
38
|
+
hosts = nodes['nodes'].map do |id, info|
|
34
39
|
if info[PROTOCOL]
|
35
|
-
host, port = info[PROTOCOL]['publish_address']
|
40
|
+
host, port = parse_publish_address(info[PROTOCOL]['publish_address'])
|
36
41
|
|
37
42
|
{ :id => id,
|
38
43
|
:name => info['name'],
|
@@ -48,6 +53,29 @@ module Elasticsearch
|
|
48
53
|
hosts
|
49
54
|
end
|
50
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def parse_publish_address(publish_address)
|
60
|
+
# publish_address is in the format hostname/ip:port
|
61
|
+
if publish_address =~ /\//
|
62
|
+
parts = publish_address.partition('/')
|
63
|
+
[ parts[0], parse_address_port(parts[2])[1] ]
|
64
|
+
else
|
65
|
+
parse_address_port(publish_address)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def parse_address_port(publish_address)
|
70
|
+
# address is ipv6
|
71
|
+
if publish_address =~ /[\[\]]/
|
72
|
+
if parts = publish_address.match(/\A\[(.+)\](?::(\d+))?\z/)
|
73
|
+
[ parts[1], parts[2] ]
|
74
|
+
end
|
75
|
+
else
|
76
|
+
publish_address.split(':')
|
77
|
+
end
|
78
|
+
end
|
51
79
|
end
|
52
80
|
end
|
53
81
|
end
|
@@ -1,5 +1,9 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
|
-
VERSION =
|
7
|
+
VERSION = '6.8.3'
|
4
8
|
end
|
5
9
|
end
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
require "uri"
|
2
6
|
require "time"
|
3
7
|
require "timeout"
|
@@ -14,6 +18,7 @@ require "elasticsearch/transport/transport/connections/connection"
|
|
14
18
|
require "elasticsearch/transport/transport/connections/collection"
|
15
19
|
require "elasticsearch/transport/transport/http/faraday"
|
16
20
|
require "elasticsearch/transport/client"
|
21
|
+
require "elasticsearch/transport/redacted"
|
17
22
|
|
18
23
|
require "elasticsearch/transport/version"
|
19
24
|
|
@@ -0,0 +1,260 @@
|
|
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
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
6
|
+
# license agreements. See the NOTICE file distributed with
|
7
|
+
# this work for additional information regarding copyright
|
8
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
9
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
10
|
+
# not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing,
|
16
|
+
# software distributed under the License is distributed on an
|
17
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
18
|
+
# KIND, either express or implied. See the License for the
|
19
|
+
# specific language governing permissions and limitations
|
20
|
+
# under the License.
|
21
|
+
|
22
|
+
require 'spec_helper'
|
23
|
+
|
24
|
+
describe Elasticsearch::Transport::Transport::Base do
|
25
|
+
context 'when a host is printed in a logged message' do
|
26
|
+
shared_examples_for 'a redacted string' do
|
27
|
+
let(:client) do
|
28
|
+
Elasticsearch::Transport::Client.new(arguments)
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:logger) do
|
32
|
+
double('logger', error?: true, error: '')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not include the password in the logged string' do
|
36
|
+
expect(logger).not_to receive(:error).with(/secret_password/)
|
37
|
+
|
38
|
+
expect {
|
39
|
+
client.cluster.stats
|
40
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'replaces the password with the string \'REDACTED\'' do
|
44
|
+
expect(logger).to receive(:error).with(/REDACTED/)
|
45
|
+
expect {
|
46
|
+
client.cluster.stats
|
47
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when the user and password are provided as separate arguments' do
|
52
|
+
let(:arguments) do
|
53
|
+
{ hosts: 'fake',
|
54
|
+
logger: logger,
|
55
|
+
password: 'secret_password',
|
56
|
+
user: 'test' }
|
57
|
+
end
|
58
|
+
|
59
|
+
it_behaves_like 'a redacted string'
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when the user and password are provided in the string URI' do
|
63
|
+
let(:arguments) do
|
64
|
+
{ hosts: 'https://test:secret_password@fake_local_elasticsearch',
|
65
|
+
logger: logger }
|
66
|
+
end
|
67
|
+
|
68
|
+
it_behaves_like 'a redacted string'
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when the user and password are provided in the URI object' do
|
72
|
+
let(:arguments) do
|
73
|
+
{ hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
|
74
|
+
logger: logger }
|
75
|
+
end
|
76
|
+
|
77
|
+
it_behaves_like 'a redacted string'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when reload_on_failure is true and and hosts are unreachable' do
|
82
|
+
|
83
|
+
let(:client) do
|
84
|
+
Elasticsearch::Transport::Client.new(arguments)
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:arguments) do
|
88
|
+
{
|
89
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
90
|
+
reload_on_failure: true,
|
91
|
+
sniffer_timeout: 5
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'raises an exception' do
|
96
|
+
expect {
|
97
|
+
client.info
|
98
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when the client has `retry_on_failure` set to an integer' do
|
103
|
+
|
104
|
+
let(:client) do
|
105
|
+
Elasticsearch::Transport::Client.new(arguments)
|
106
|
+
end
|
107
|
+
|
108
|
+
let(:arguments) do
|
109
|
+
{
|
110
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
111
|
+
retry_on_failure: 2
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
116
|
+
|
117
|
+
before do
|
118
|
+
expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'uses the client `retry_on_failure` value' do
|
122
|
+
expect {
|
123
|
+
client.transport.perform_request('GET', '/info')
|
124
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
129
|
+
|
130
|
+
before do
|
131
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'uses the option `retry_on_failure` value' do
|
135
|
+
expect {
|
136
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
137
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when the client has `retry_on_failure` set to true' do
|
143
|
+
|
144
|
+
let(:client) do
|
145
|
+
Elasticsearch::Transport::Client.new(arguments)
|
146
|
+
end
|
147
|
+
|
148
|
+
let(:arguments) do
|
149
|
+
{
|
150
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
151
|
+
retry_on_failure: true
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
156
|
+
|
157
|
+
before do
|
158
|
+
expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'uses the default `MAX_RETRIES` value' do
|
162
|
+
expect {
|
163
|
+
client.transport.perform_request('GET', '/info')
|
164
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
169
|
+
|
170
|
+
before do
|
171
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'uses the option `retry_on_failure` value' do
|
175
|
+
expect {
|
176
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
177
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when the client has `retry_on_failure` set to false' do
|
183
|
+
|
184
|
+
let(:client) do
|
185
|
+
Elasticsearch::Transport::Client.new(arguments)
|
186
|
+
end
|
187
|
+
|
188
|
+
let(:arguments) do
|
189
|
+
{
|
190
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
191
|
+
retry_on_failure: false
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
196
|
+
|
197
|
+
before do
|
198
|
+
expect(client.transport).to receive(:get_connection).once.and_call_original
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'does not retry' do
|
202
|
+
expect {
|
203
|
+
client.transport.perform_request('GET', '/info')
|
204
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
209
|
+
|
210
|
+
before do
|
211
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'uses the option `retry_on_failure` value' do
|
215
|
+
expect {
|
216
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
217
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when the client has no `retry_on_failure` set' do
|
223
|
+
|
224
|
+
let(:client) do
|
225
|
+
Elasticsearch::Transport::Client.new(arguments)
|
226
|
+
end
|
227
|
+
|
228
|
+
let(:arguments) do
|
229
|
+
{
|
230
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
231
|
+
}
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
235
|
+
|
236
|
+
before do
|
237
|
+
expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'does not retry' do
|
241
|
+
expect {
|
242
|
+
client.transport.perform_request('GET', '/info')
|
243
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
248
|
+
|
249
|
+
before do
|
250
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'uses the option `retry_on_failure` value' do
|
254
|
+
expect {
|
255
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
256
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|