elasticsearch-transport 6.8.3 → 7.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +17 -0
  3. data/LICENSE.txt +199 -10
  4. data/README.md +32 -86
  5. data/Rakefile +23 -4
  6. data/elasticsearch-transport.gemspec +78 -45
  7. data/lib/elasticsearch-transport.rb +16 -3
  8. data/lib/elasticsearch/transport.rb +17 -3
  9. data/lib/elasticsearch/transport/client.rb +70 -174
  10. data/lib/elasticsearch/transport/redacted.rb +5 -9
  11. data/lib/elasticsearch/transport/transport/base.rb +63 -55
  12. data/lib/elasticsearch/transport/transport/connections/collection.rb +16 -3
  13. data/lib/elasticsearch/transport/transport/connections/connection.rb +16 -3
  14. data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
  15. data/lib/elasticsearch/transport/transport/errors.rb +16 -3
  16. data/lib/elasticsearch/transport/transport/http/curb.rb +18 -5
  17. data/lib/elasticsearch/transport/transport/http/faraday.rb +18 -5
  18. data/lib/elasticsearch/transport/transport/http/manticore.rb +17 -4
  19. data/lib/elasticsearch/transport/transport/loggable.rb +85 -0
  20. data/lib/elasticsearch/transport/transport/response.rb +16 -3
  21. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
  22. data/lib/elasticsearch/transport/transport/sniffer.rb +17 -5
  23. data/lib/elasticsearch/transport/version.rb +17 -4
  24. data/spec/elasticsearch/transport/base_spec.rb +8 -187
  25. data/spec/elasticsearch/transport/client_spec.rb +29 -163
  26. data/spec/elasticsearch/transport/sniffer_spec.rb +19 -0
  27. data/spec/spec_helper.rb +2 -11
  28. data/test/integration/transport_test.rb +18 -5
  29. data/test/profile/client_benchmark_test.rb +16 -3
  30. data/test/test_helper.rb +63 -14
  31. data/test/unit/connection_collection_test.rb +17 -4
  32. data/test/unit/connection_selector_test.rb +17 -4
  33. data/test/unit/connection_test.rb +17 -4
  34. data/test/unit/response_test.rb +18 -5
  35. data/test/unit/serializer_test.rb +17 -4
  36. data/test/unit/transport_base_test.rb +21 -8
  37. data/test/unit/transport_curb_test.rb +17 -4
  38. data/test/unit/transport_faraday_test.rb +17 -4
  39. data/test/unit/transport_manticore_test.rb +24 -6
  40. metadata +61 -86
  41. data/spec/elasticsearch/transport/meta_header_spec.rb +0 -214
@@ -1,6 +1,19 @@
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
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
4
17
 
5
18
  require 'manticore'
6
19
 
@@ -67,7 +80,7 @@ module Elasticsearch
67
80
  # @return [Response]
68
81
  # @see Transport::Base#perform_request
69
82
  #
70
- def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
83
+ def perform_request(method, path, params={}, body=nil, headers=nil)
71
84
  super do |connection, url|
72
85
  params[:body] = __convert_to_json(body) if body
73
86
  params[:headers] = headers if headers
@@ -0,0 +1,85 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Elasticsearch
19
+
20
+ # Module to encapsulate all logging functionality.
21
+ #
22
+ # @since 7.0.0
23
+ module Loggable
24
+
25
+ # Log a debug message.
26
+ #
27
+ # @example Log a debug message.
28
+ # log_debug('Message')
29
+ #
30
+ # @param [ String ] message The message to log.
31
+ #
32
+ # @since 7.0.0
33
+ def log_debug(message)
34
+ logger.debug(message) if logger && logger.debug?
35
+ end
36
+
37
+ # Log an error message.
38
+ #
39
+ # @example Log an error message.
40
+ # log_error('Message')
41
+ #
42
+ # @param [ String ] message The message to log.
43
+ #
44
+ # @since 7.0.0
45
+ def log_error(message)
46
+ logger.error(message) if logger && logger.error?
47
+ end
48
+
49
+ # Log a fatal message.
50
+ #
51
+ # @example Log a fatal message.
52
+ # log_fatal('Message')
53
+ #
54
+ # @param [ String ] message The message to log.
55
+ #
56
+ # @since 7.0.0
57
+ def log_fatal(message)
58
+ logger.fatal(message) if logger && logger.fatal?
59
+ end
60
+
61
+ # Log an info message.
62
+ #
63
+ # @example Log an info message.
64
+ # log_info('Message')
65
+ #
66
+ # @param [ String ] message The message to log.
67
+ #
68
+ # @since 7.0.0
69
+ def log_info(message)
70
+ logger.info(message) if logger && logger.info?
71
+ end
72
+
73
+ # Log a warn message.
74
+ #
75
+ # @example Log a warn message.
76
+ # log_warn('Message')
77
+ #
78
+ # @param [ String ] message The message to log.
79
+ #
80
+ # @since 7.0.0
81
+ def log_warn(message)
82
+ logger.warn(message) if logger && logger.warn?
83
+ end
84
+ end
85
+ end
@@ -1,6 +1,19 @@
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
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
4
17
 
5
18
  module Elasticsearch
6
19
  module Transport
@@ -1,6 +1,19 @@
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
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
4
17
 
5
18
  module Elasticsearch
6
19
  module Transport
@@ -1,6 +1,19 @@
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
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
4
17
 
5
18
  module Elasticsearch
6
19
  module Transport
@@ -32,8 +45,7 @@ module Elasticsearch
32
45
  #
33
46
  def hosts
34
47
  Timeout::timeout(timeout, SnifferTimeoutError) do
35
- nodes = transport.perform_request('GET', '_nodes/http', {}, nil, nil,
36
- reload_on_failure: false).body
48
+ nodes = transport.perform_request('GET', '_nodes/http').body
37
49
 
38
50
  hosts = nodes['nodes'].map do |id, info|
39
51
  if info[PROTOCOL]
@@ -1,9 +1,22 @@
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
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
4
17
 
5
18
  module Elasticsearch
6
19
  module Transport
7
- VERSION = '6.8.3'
20
+ VERSION = "7.0.0.pre"
8
21
  end
9
22
  end
@@ -1,7 +1,3 @@
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
1
  # Licensed to Elasticsearch B.V. under one or more contributor
6
2
  # license agreements. See the NOTICE file distributed with
7
3
  # this work for additional information regarding copyright
@@ -22,8 +18,11 @@
22
18
  require 'spec_helper'
23
19
 
24
20
  describe Elasticsearch::Transport::Transport::Base do
21
+
25
22
  context 'when a host is printed in a logged message' do
23
+
26
24
  shared_examples_for 'a redacted string' do
25
+
27
26
  let(:client) do
28
27
  Elasticsearch::Transport::Client.new(arguments)
29
28
  end
@@ -34,7 +33,6 @@ describe Elasticsearch::Transport::Transport::Base do
34
33
 
35
34
  it 'does not include the password in the logged string' do
36
35
  expect(logger).not_to receive(:error).with(/secret_password/)
37
-
38
36
  expect {
39
37
  client.cluster.stats
40
38
  }.to raise_exception(Faraday::ConnectionFailed)
@@ -49,6 +47,7 @@ describe Elasticsearch::Transport::Transport::Base do
49
47
  end
50
48
 
51
49
  context 'when the user and password are provided as separate arguments' do
50
+
52
51
  let(:arguments) do
53
52
  { hosts: 'fake',
54
53
  logger: logger,
@@ -60,8 +59,9 @@ describe Elasticsearch::Transport::Transport::Base do
60
59
  end
61
60
 
62
61
  context 'when the user and password are provided in the string URI' do
62
+
63
63
  let(:arguments) do
64
- { hosts: 'https://test:secret_password@fake_local_elasticsearch',
64
+ { hosts: 'http://test:secret_password@fake.com',
65
65
  logger: logger }
66
66
  end
67
67
 
@@ -69,192 +69,13 @@ describe Elasticsearch::Transport::Transport::Base do
69
69
  end
70
70
 
71
71
  context 'when the user and password are provided in the URI object' do
72
+
72
73
  let(:arguments) do
73
- { hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
74
+ { hosts: URI.parse('http://test:secret_password@fake.com'),
74
75
  logger: logger }
75
76
  end
76
77
 
77
78
  it_behaves_like 'a redacted string'
78
79
  end
79
80
  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
81
  end