elasticsearch-transport 7.11.1 → 7.13.1
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/client.rb +21 -79
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/transport/connections/collection.rb +2 -5
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/connections/collection_spec.rb +12 -0
- data/spec/elasticsearch/transport/client_spec.rb +42 -2
- data/spec/elasticsearch/transport/meta_header_spec.rb +43 -3
- data/test/integration/transport_test.rb +14 -1
- data/test/unit/connection_test.rb +2 -2
- data/test/unit/transport_base_test.rb +1 -1
- data/test/unit/transport_faraday_test.rb +2 -2
- data/test/unit/transport_manticore_test.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae324619e058030508ffb4a2f69577c3ba49e7cb526afaf258c502739829cb33
|
4
|
+
data.tar.gz: 5e9ea4dd558023c2ae3153e69cda25a8de11d6bf559d7d38ed9f4a50f2218084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5960e2df76af2158c217847c794ffe2cf331feb9e531fc71d4ca9bbd5b79275c83bf3e6dacd7b9d4310f49ec7e146d246eea61c01df43048dbe418ef6ecf24c
|
7
|
+
data.tar.gz: 9325ff41a6cbb4f3a3bf1e3d5b1ffd6c8bcb6bb10b2724ae52a07f879cc5d6347efad13166bbcd08534887e91be6f63fc8d7d0449575e080679f435afa3008f0
|
@@ -16,6 +16,7 @@
|
|
16
16
|
# under the License.
|
17
17
|
|
18
18
|
require 'base64'
|
19
|
+
require 'elasticsearch/transport/meta_header'
|
19
20
|
|
20
21
|
module Elasticsearch
|
21
22
|
module Transport
|
@@ -25,6 +26,7 @@ module Elasticsearch
|
|
25
26
|
# See {file:README.md README} for usage and code examples.
|
26
27
|
#
|
27
28
|
class Client
|
29
|
+
include MetaHeader
|
28
30
|
DEFAULT_TRANSPORT_CLASS = Transport::HTTP::Faraday
|
29
31
|
|
30
32
|
DEFAULT_LOGGER = lambda do
|
@@ -143,14 +145,15 @@ module Elasticsearch
|
|
143
145
|
@options[:http] ||= {}
|
144
146
|
|
145
147
|
set_api_key if (@api_key = @arguments[:api_key])
|
148
|
+
set_compatibility_header if ENV['ELASTIC_CLIENT_APIVERSIONING']
|
146
149
|
|
147
150
|
@seeds = extract_cloud_creds(@arguments)
|
148
151
|
@seeds ||= __extract_hosts(@arguments[:hosts] ||
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
152
|
+
@arguments[:host] ||
|
153
|
+
@arguments[:url] ||
|
154
|
+
@arguments[:urls] ||
|
155
|
+
ENV['ELASTICSEARCH_URL'] ||
|
156
|
+
DEFAULT_HOST)
|
154
157
|
|
155
158
|
@send_get_body_as = @arguments[:send_get_body_as] || 'GET'
|
156
159
|
@opaque_id_prefix = @arguments[:opaque_id_prefix] || nil
|
@@ -165,13 +168,13 @@ module Elasticsearch
|
|
165
168
|
@transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
|
166
169
|
@transport = if @transport_class == Transport::HTTP::Faraday
|
167
170
|
@arguments[:adapter] ||= __auto_detect_adapter
|
168
|
-
set_meta_header
|
171
|
+
set_meta_header # from include MetaHeader
|
169
172
|
@transport_class.new(hosts: @seeds, options: @arguments) do |faraday|
|
170
173
|
faraday.adapter(@arguments[:adapter])
|
171
174
|
block&.call faraday
|
172
175
|
end
|
173
176
|
else
|
174
|
-
set_meta_header
|
177
|
+
set_meta_header # from include MetaHeader
|
175
178
|
@transport_class.new(hosts: @seeds, options: @arguments)
|
176
179
|
end
|
177
180
|
end
|
@@ -198,6 +201,17 @@ module Elasticsearch
|
|
198
201
|
@arguments.delete(:password)
|
199
202
|
end
|
200
203
|
|
204
|
+
def set_compatibility_header
|
205
|
+
return unless ['1', 'true'].include?(ENV['ELASTIC_CLIENT_APIVERSIONING'])
|
206
|
+
|
207
|
+
add_header(
|
208
|
+
{
|
209
|
+
'Accept' => 'application/vnd.elasticsearch+json;compatible-with=7',
|
210
|
+
'Content-Type' => 'application/vnd.elasticsearch+json; compatible-with=7'
|
211
|
+
}
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
201
215
|
def add_header(header)
|
202
216
|
headers = @arguments[:transport_options]&.[](:headers) || {}
|
203
217
|
headers.merge!(header)
|
@@ -206,78 +220,6 @@ module Elasticsearch
|
|
206
220
|
)
|
207
221
|
end
|
208
222
|
|
209
|
-
def set_meta_header
|
210
|
-
return if @arguments[:enable_meta_header] == false
|
211
|
-
|
212
|
-
service, version = meta_header_service_version
|
213
|
-
|
214
|
-
meta_headers = {
|
215
|
-
service.to_sym => version,
|
216
|
-
rb: RUBY_VERSION,
|
217
|
-
t: Elasticsearch::Transport::VERSION
|
218
|
-
}
|
219
|
-
meta_headers.merge!(meta_header_engine) if meta_header_engine
|
220
|
-
meta_headers.merge!(meta_header_adapter) if meta_header_adapter
|
221
|
-
|
222
|
-
add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
|
223
|
-
end
|
224
|
-
|
225
|
-
def meta_header_service_version
|
226
|
-
if defined?(Elastic::META_HEADER_SERVICE_VERSION)
|
227
|
-
Elastic::META_HEADER_SERVICE_VERSION
|
228
|
-
elsif defined?(Elasticsearch::VERSION)
|
229
|
-
[:es, client_meta_version(Elasticsearch::VERSION)]
|
230
|
-
else
|
231
|
-
[:es, client_meta_version(Elasticsearch::Transport::VERSION)]
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
def client_meta_version(version)
|
236
|
-
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
|
237
|
-
match = version.match(regexp)
|
238
|
-
return "#{match[1]}p" if (match[2])
|
239
|
-
|
240
|
-
version
|
241
|
-
end
|
242
|
-
|
243
|
-
def meta_header_engine
|
244
|
-
case RUBY_ENGINE
|
245
|
-
when 'ruby'
|
246
|
-
{}
|
247
|
-
when 'jruby'
|
248
|
-
{ jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
|
249
|
-
when 'rbx'
|
250
|
-
{ rbx: RUBY_VERSION }
|
251
|
-
else
|
252
|
-
{ RUBY_ENGINE.to_sym => RUBY_VERSION }
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def meta_header_adapter
|
257
|
-
if @transport_class == Transport::HTTP::Faraday
|
258
|
-
{fd: Faraday::VERSION}.merge(
|
259
|
-
case @arguments[:adapter]
|
260
|
-
when :patron
|
261
|
-
{pt: Patron::VERSION}
|
262
|
-
when :net_http
|
263
|
-
{nh: defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}
|
264
|
-
when :typhoeus
|
265
|
-
{ty: Typhoeus::VERSION}
|
266
|
-
when :httpclient
|
267
|
-
{hc: HTTPClient::VERSION}
|
268
|
-
when :net_http_persistent
|
269
|
-
{np: Net::HTTP::Persistent::VERSION}
|
270
|
-
else
|
271
|
-
{}
|
272
|
-
end
|
273
|
-
)
|
274
|
-
elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
|
275
|
-
{cl: Curl::CURB_VERSION}
|
276
|
-
elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
|
277
|
-
{mc: Manticore::VERSION}
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
223
|
def extract_cloud_creds(arguments)
|
282
224
|
return unless arguments[:cloud_id] && !arguments[:cloud_id].empty?
|
283
225
|
|
@@ -0,0 +1,135 @@
|
|
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
|
+
require 'base64'
|
19
|
+
|
20
|
+
module Elasticsearch
|
21
|
+
module Transport
|
22
|
+
# Methods for the Elastic meta header used by Cloud.
|
23
|
+
# X-Elastic-Client-Meta HTTP header which is used by Elastic Cloud and can be disabled when
|
24
|
+
# instantiating the Client with the :enable_meta_header parameter set to `false`.
|
25
|
+
#
|
26
|
+
module MetaHeader
|
27
|
+
def set_meta_header
|
28
|
+
return if @arguments[:enable_meta_header] == false
|
29
|
+
|
30
|
+
service, version = meta_header_service_version
|
31
|
+
|
32
|
+
meta_headers = {
|
33
|
+
service.to_sym => version,
|
34
|
+
rb: RUBY_VERSION,
|
35
|
+
t: Elasticsearch::Transport::VERSION
|
36
|
+
}
|
37
|
+
meta_headers.merge!(meta_header_engine) if meta_header_engine
|
38
|
+
meta_headers.merge!(meta_header_adapter) if meta_header_adapter
|
39
|
+
|
40
|
+
add_header({ 'x-elastic-client-meta' => meta_headers.map { |k, v| "#{k}=#{v}" }.join(',') })
|
41
|
+
end
|
42
|
+
|
43
|
+
def meta_header_service_version
|
44
|
+
if enterprise_search?
|
45
|
+
Elastic::ENTERPRISE_SERVICE_VERSION
|
46
|
+
elsif elasticsearch?
|
47
|
+
Elastic::ELASTICSEARCH_SERVICE_VERSION
|
48
|
+
elsif defined?(Elasticsearch::VERSION)
|
49
|
+
[:es, client_meta_version(Elasticsearch::VERSION)]
|
50
|
+
else
|
51
|
+
[:es, client_meta_version(Elasticsearch::Transport::VERSION)]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def enterprise_search?
|
56
|
+
defined?(Elastic::ENTERPRISE_SERVICE_VERSION) &&
|
57
|
+
called_from?('enterprise-search-ruby')
|
58
|
+
end
|
59
|
+
|
60
|
+
def elasticsearch?
|
61
|
+
defined?(Elastic::ELASTICSEARCH_SERVICE_VERSION) &&
|
62
|
+
called_from?('elasticsearch')
|
63
|
+
end
|
64
|
+
|
65
|
+
def called_from?(service)
|
66
|
+
!caller.select { |c| c.match?(service) }.empty?
|
67
|
+
end
|
68
|
+
|
69
|
+
# We return the current version if it's a release, but if it's a pre/alpha/beta release we
|
70
|
+
# return <VERSION_NUMBER>p
|
71
|
+
#
|
72
|
+
def client_meta_version(version)
|
73
|
+
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
|
74
|
+
match = version.match(regexp)
|
75
|
+
return "#{match[1]}p" if (match[2])
|
76
|
+
|
77
|
+
version
|
78
|
+
end
|
79
|
+
|
80
|
+
def meta_header_engine
|
81
|
+
case RUBY_ENGINE
|
82
|
+
when 'ruby'
|
83
|
+
{}
|
84
|
+
when 'jruby'
|
85
|
+
{ jv: ENV_JAVA['java.version'], jr: JRUBY_VERSION }
|
86
|
+
when 'rbx'
|
87
|
+
{ rbx: RUBY_VERSION }
|
88
|
+
else
|
89
|
+
{ RUBY_ENGINE.to_sym => RUBY_VERSION }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# This function tries to define the version for the Faraday adapter. If it hasn't been loaded
|
94
|
+
# by the time we're calling this method, it's going to report the adapter (if we know it) but
|
95
|
+
# return 0 as the version. It won't report anything when using a custom adapter we don't
|
96
|
+
# identify.
|
97
|
+
#
|
98
|
+
# Returns a Hash<adapter_alias, version>
|
99
|
+
#
|
100
|
+
def meta_header_adapter
|
101
|
+
if @transport_class == Transport::HTTP::Faraday
|
102
|
+
version = '0'
|
103
|
+
adapter_version = case @arguments[:adapter]
|
104
|
+
when :patron
|
105
|
+
version = Patron::VERSION if defined?(::Patron::VERSION)
|
106
|
+
{pt: version}
|
107
|
+
when :net_http
|
108
|
+
version = if defined?(Net::HTTP::VERSION)
|
109
|
+
Net::HTTP::VERSION
|
110
|
+
elsif defined?(Net::HTTP::HTTPVersion)
|
111
|
+
Net::HTTP::HTTPVersion
|
112
|
+
end
|
113
|
+
{nh: version}
|
114
|
+
when :typhoeus
|
115
|
+
version = Typhoeus::VERSION if defined?(::Typhoeus::VERSION)
|
116
|
+
{ty: version}
|
117
|
+
when :httpclient
|
118
|
+
version = HTTPClient::VERSION if defined?(HTTPClient::VERSION)
|
119
|
+
{hc: version}
|
120
|
+
when :net_http_persistent
|
121
|
+
version = Net::HTTP::Persistent::VERSION if defined?(Net::HTTP::Persistent::VERSION)
|
122
|
+
{np: version}
|
123
|
+
else
|
124
|
+
{}
|
125
|
+
end
|
126
|
+
{fd: Faraday::VERSION}.merge(adapter_version)
|
127
|
+
elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
|
128
|
+
{cl: Curl::CURB_VERSION}
|
129
|
+
elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
|
130
|
+
{mc: Manticore::VERSION}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -78,16 +78,13 @@ module Elasticsearch
|
|
78
78
|
|
79
79
|
# Returns a connection.
|
80
80
|
#
|
81
|
-
# If there are no alive connections,
|
81
|
+
# If there are no alive connections, returns a connection with least failures.
|
82
82
|
# Delegates to selector's `#select` method to get the connection.
|
83
83
|
#
|
84
84
|
# @return [Connection]
|
85
85
|
#
|
86
86
|
def get_connection(options={})
|
87
|
-
|
88
|
-
dead_connection.alive!
|
89
|
-
end
|
90
|
-
selector.select(options)
|
87
|
+
selector.select(options) || @connections.min_by(&:failures)
|
91
88
|
end
|
92
89
|
|
93
90
|
def each(&block)
|
@@ -249,6 +249,18 @@ describe Elasticsearch::Transport::Transport::Connections::Collection do
|
|
249
249
|
collection.get_connection.host[:host]
|
250
250
|
end).to eq((0..9).to_a)
|
251
251
|
end
|
252
|
+
|
253
|
+
it 'always returns a connection' do
|
254
|
+
threads = 20.times.map do
|
255
|
+
Thread.new do
|
256
|
+
20.times.map do
|
257
|
+
collection.get_connection.dead!
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
expect(threads.flat_map(&:value).size).to eq(400)
|
263
|
+
end
|
252
264
|
end
|
253
265
|
end
|
254
266
|
end
|
@@ -266,7 +266,7 @@ describe Elasticsearch::Transport::Client do
|
|
266
266
|
it 'uses Faraday with the adapter' do
|
267
267
|
expect(adapter).to eq Faraday::Adapter::Typhoeus
|
268
268
|
end
|
269
|
-
end
|
269
|
+
end unless jruby?
|
270
270
|
|
271
271
|
context 'when the adapter is specified as a string key' do
|
272
272
|
let(:adapter) do
|
@@ -1428,6 +1428,46 @@ describe Elasticsearch::Transport::Client do
|
|
1428
1428
|
end
|
1429
1429
|
end
|
1430
1430
|
|
1431
|
+
context 'when using the API Compatibility Header' do
|
1432
|
+
it 'sets the API compatibility headers' do
|
1433
|
+
ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'true'
|
1434
|
+
client = described_class.new(host: hosts)
|
1435
|
+
headers = client.transport.connections.first.connection.headers
|
1436
|
+
|
1437
|
+
expect(headers['Content-Type']).to eq('application/vnd.elasticsearch+json; compatible-with=7')
|
1438
|
+
expect(headers['Accept']).to eq('application/vnd.elasticsearch+json;compatible-with=7')
|
1439
|
+
|
1440
|
+
response = client.perform_request('GET', '/')
|
1441
|
+
expect(response.headers['content-type']).to eq('application/json; charset=UTF-8')
|
1442
|
+
|
1443
|
+
ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
|
1444
|
+
end
|
1445
|
+
|
1446
|
+
it 'does not use API compatibility headers' do
|
1447
|
+
val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
|
1448
|
+
client = described_class.new(host: hosts)
|
1449
|
+
expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
|
1450
|
+
ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
|
1451
|
+
end
|
1452
|
+
|
1453
|
+
it 'does not use API compatibility headers when it is set to unsupported values' do
|
1454
|
+
val = ENV.delete('ELASTIC_CLIENT_APIVERSIONING')
|
1455
|
+
|
1456
|
+
ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'test'
|
1457
|
+
client = described_class.new(host: hosts)
|
1458
|
+
expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
|
1459
|
+
|
1460
|
+
ENV['ELASTIC_CLIENT_APIVERSIONING'] = 'false'
|
1461
|
+
client = described_class.new(host: hosts)
|
1462
|
+
expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
|
1463
|
+
|
1464
|
+
ENV['ELASTIC_CLIENT_APIVERSIONING'] = '3'
|
1465
|
+
client = described_class.new(host: hosts)
|
1466
|
+
expect(client.transport.connections.first.connection.headers['Content-Type']).to eq('application/json')
|
1467
|
+
ENV['ELASTIC_CLIENT_APIVERSIONING'] = val
|
1468
|
+
end
|
1469
|
+
end
|
1470
|
+
|
1431
1471
|
context 'when Elasticsearch response includes a warning header' do
|
1432
1472
|
let(:client) do
|
1433
1473
|
Elasticsearch::Transport::Client.new(hosts: hosts)
|
@@ -1776,7 +1816,7 @@ describe Elasticsearch::Transport::Client do
|
|
1776
1816
|
it 'preserves the other headers' do
|
1777
1817
|
expect(client.transport.connections[0].connection.headers['User-Agent'])
|
1778
1818
|
end
|
1779
|
-
end
|
1819
|
+
end unless jruby?
|
1780
1820
|
end
|
1781
1821
|
end
|
1782
1822
|
|
@@ -32,7 +32,7 @@ describe Elasticsearch::Transport::Client do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context '
|
35
|
+
context 'client_meta_version' do
|
36
36
|
let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
|
37
37
|
|
38
38
|
it 'converts the version to X.X.Xp' do
|
@@ -108,6 +108,14 @@ describe Elasticsearch::Transport::Client do
|
|
108
108
|
context 'using net/http/persistent' do
|
109
109
|
let(:adapter) { :net_http_persistent }
|
110
110
|
|
111
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
112
|
+
fork {
|
113
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
114
|
+
meta = "#{meta_header},np=0"
|
115
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
116
|
+
}
|
117
|
+
end unless jruby?
|
118
|
+
|
111
119
|
it 'sets adapter in the meta header' do
|
112
120
|
require 'net/http/persistent'
|
113
121
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -119,6 +127,14 @@ describe Elasticsearch::Transport::Client do
|
|
119
127
|
context 'using httpclient' do
|
120
128
|
let(:adapter) { :httpclient }
|
121
129
|
|
130
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
131
|
+
fork {
|
132
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
133
|
+
meta = "#{meta_header},hc=0"
|
134
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
135
|
+
}
|
136
|
+
end unless jruby?
|
137
|
+
|
122
138
|
it 'sets adapter in the meta header' do
|
123
139
|
require 'httpclient'
|
124
140
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -130,6 +146,14 @@ describe Elasticsearch::Transport::Client do
|
|
130
146
|
context 'using typhoeus' do
|
131
147
|
let(:adapter) { :typhoeus }
|
132
148
|
|
149
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
150
|
+
fork {
|
151
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
152
|
+
meta = "#{meta_header},ty=0"
|
153
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
154
|
+
}
|
155
|
+
end unless jruby?
|
156
|
+
|
133
157
|
it 'sets adapter in the meta header' do
|
134
158
|
require 'typhoeus'
|
135
159
|
expect(headers['x-elastic-client-meta']).to match(regexp)
|
@@ -138,9 +162,19 @@ describe Elasticsearch::Transport::Client do
|
|
138
162
|
end
|
139
163
|
end
|
140
164
|
|
141
|
-
unless
|
165
|
+
unless jruby?
|
142
166
|
let(:adapter) { :patron }
|
143
167
|
|
168
|
+
context 'using patron without requiring it' do
|
169
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
170
|
+
fork {
|
171
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
172
|
+
meta = "#{meta_header},pt=0"
|
173
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
174
|
+
}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
144
178
|
context 'using patron' do
|
145
179
|
it 'sets adapter in the meta header' do
|
146
180
|
require 'patron'
|
@@ -154,6 +188,12 @@ describe Elasticsearch::Transport::Client do
|
|
154
188
|
context 'using other' do
|
155
189
|
let(:adapter) { :some_other_adapter }
|
156
190
|
|
191
|
+
it 'sets adapter in the meta header without requiring' do
|
192
|
+
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
193
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
194
|
+
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
195
|
+
end
|
196
|
+
|
157
197
|
it 'sets adapter in the meta header' do
|
158
198
|
require 'net/http/persistent'
|
159
199
|
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
@@ -211,7 +251,7 @@ describe Elasticsearch::Transport::Client do
|
|
211
251
|
|
212
252
|
context 'when using a different service version' do
|
213
253
|
before do
|
214
|
-
stub_const(
|
254
|
+
stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
|
215
255
|
end
|
216
256
|
|
217
257
|
let(:client) { Elasticsearch::Client.new }
|
@@ -32,7 +32,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
32
32
|
begin; Object.send(:remove_const, :Patron); rescue NameError; end
|
33
33
|
end
|
34
34
|
|
35
|
-
should "allow to customize the Faraday adapter" do
|
35
|
+
should "allow to customize the Faraday adapter to Typhoeus" do
|
36
36
|
require 'typhoeus'
|
37
37
|
require 'typhoeus/adapters/faraday'
|
38
38
|
|
@@ -42,6 +42,19 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
42
42
|
f.adapter :typhoeus
|
43
43
|
end
|
44
44
|
|
45
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
46
|
+
client.perform_request 'GET', ''
|
47
|
+
end unless jruby?
|
48
|
+
|
49
|
+
should "allow to customize the Faraday adapter to NetHttpPersistent" do
|
50
|
+
require 'net/http/persistent'
|
51
|
+
|
52
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
|
53
|
+
:hosts => [ { host: @host, port: @port } ] do |f|
|
54
|
+
f.response :logger
|
55
|
+
f.adapter :net_http_persistent
|
56
|
+
end
|
57
|
+
|
45
58
|
client = Elasticsearch::Transport::Client.new transport: transport
|
46
59
|
client.perform_request 'GET', ''
|
47
60
|
end
|
@@ -64,8 +64,8 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Minites
|
|
64
64
|
|
65
65
|
should "have a string representation" do
|
66
66
|
c = Connection.new :host => 'x'
|
67
|
-
assert_match
|
68
|
-
assert_match
|
67
|
+
assert_match(/host: x/, c.to_s)
|
68
|
+
assert_match(/alive/, c.to_s)
|
69
69
|
end
|
70
70
|
|
71
71
|
should "not be dead by default" do
|
@@ -429,7 +429,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
429
429
|
@transport.stubs(:get_connection).returns(fake_connection)
|
430
430
|
|
431
431
|
@transport.logger.expects(:info).with do |message|
|
432
|
-
assert_match
|
432
|
+
assert_match(/http:\/\/user:\*{1,15}@localhost\:9200/, message)
|
433
433
|
true
|
434
434
|
end
|
435
435
|
|
@@ -149,7 +149,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
|
|
149
149
|
|
150
150
|
transport.connections.first.connection.expects(:run_request).
|
151
151
|
with do |method, url, params, body|
|
152
|
-
assert_match
|
152
|
+
assert_match(/\?format=yaml/, url)
|
153
153
|
true
|
154
154
|
end.
|
155
155
|
returns(stub_everything)
|
@@ -167,7 +167,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
|
|
167
167
|
|
168
168
|
transport.connections.first.connection.expects(:run_request).
|
169
169
|
with do |method, url, params, body|
|
170
|
-
assert_match
|
170
|
+
assert_match(/\?format=json/, url)
|
171
171
|
true
|
172
172
|
end.
|
173
173
|
returns(stub_everything)
|
@@ -145,8 +145,8 @@ else
|
|
145
145
|
transport = Manticore.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => options
|
146
146
|
transport.connections.first.connection
|
147
147
|
.expects(:get)
|
148
|
-
.with do |host,
|
149
|
-
assert_equal 'myapp-0.0',
|
148
|
+
.with do |host, _options|
|
149
|
+
assert_equal 'myapp-0.0', _options[:headers]['User-Agent']
|
150
150
|
true
|
151
151
|
end
|
152
152
|
.returns(stub_everything)
|
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.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -373,6 +373,7 @@ files:
|
|
373
373
|
- lib/elasticsearch-transport.rb
|
374
374
|
- lib/elasticsearch/transport.rb
|
375
375
|
- lib/elasticsearch/transport/client.rb
|
376
|
+
- lib/elasticsearch/transport/meta_header.rb
|
376
377
|
- lib/elasticsearch/transport/redacted.rb
|
377
378
|
- lib/elasticsearch/transport/transport/base.rb
|
378
379
|
- lib/elasticsearch/transport/transport/connections/collection.rb
|
@@ -428,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
428
429
|
- !ruby/object:Gem::Version
|
429
430
|
version: '0'
|
430
431
|
requirements: []
|
431
|
-
rubygems_version: 3.
|
432
|
+
rubygems_version: 3.2.15
|
432
433
|
signing_key:
|
433
434
|
specification_version: 4
|
434
435
|
summary: Ruby client for Elasticsearch.
|