elasticsearch-transport 7.11.2 → 7.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07e3f02a3b166d00bcee76a0a39731ef5cc2c1aab442d4f6af2b4300a85661d6
4
- data.tar.gz: 149090dcf60ef7f09637a42e23e33bcc78245872ff470bf064194fad59f2a19c
3
+ metadata.gz: a045f07e51e54095cdd4d050a786070b35eadc7356b5167c99da881738cf5607
4
+ data.tar.gz: 854f2d899cdbbb184ce945a6b6dfa0a1f7f463bcf3d818c4e7f66a28ca81a504
5
5
  SHA512:
6
- metadata.gz: a4919e34440ab8a91c2feafb2383e44b518b6b1f122ef59ddf26e35a93c2d1e23ef49f3b7f267eff7a51fd57de671cc66742358b1265ab5211362865ae40127f
7
- data.tar.gz: b7b9f51e9232c29203cb110bf9e7b1002cffcaac4c583051795e83e590dc4c7a6ea3fd887d0a617f4ed0cb36e0d0e8593ed64c802894990b9c5dbf7eed657773
6
+ metadata.gz: 89c3b0674a119afb4aa397bacf6282bd301862ca4a5aa107b0789c93493644f678414587dd695e3210fdbe8afaed6bf9db8a10ee1a3597767211afb2fb4d4da4
7
+ data.tar.gz: 6706d0c3441f9eed32b7e930e2cd808774bb8de1083109a6681a1433929dc407f324e97bdbaf1bf3dce9c452fc527abc3cbd7ccd071cfbff46977a93af31ba5d
@@ -145,14 +145,15 @@ module Elasticsearch
145
145
  @options[:http] ||= {}
146
146
 
147
147
  set_api_key if (@api_key = @arguments[:api_key])
148
+ set_compatibility_header if ENV['ELASTIC_CLIENT_APIVERSIONING']
148
149
 
149
150
  @seeds = extract_cloud_creds(@arguments)
150
151
  @seeds ||= __extract_hosts(@arguments[:hosts] ||
151
- @arguments[:host] ||
152
- @arguments[:url] ||
153
- @arguments[:urls] ||
154
- ENV['ELASTICSEARCH_URL'] ||
155
- DEFAULT_HOST)
152
+ @arguments[:host] ||
153
+ @arguments[:url] ||
154
+ @arguments[:urls] ||
155
+ ENV['ELASTICSEARCH_URL'] ||
156
+ DEFAULT_HOST)
156
157
 
157
158
  @send_get_body_as = @arguments[:send_get_body_as] || 'GET'
158
159
  @opaque_id_prefix = @arguments[:opaque_id_prefix] || nil
@@ -200,6 +201,17 @@ module Elasticsearch
200
201
  @arguments.delete(:password)
201
202
  end
202
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
+
203
215
  def add_header(header)
204
216
  headers = @arguments[:transport_options]&.[](:headers) || {}
205
217
  headers.merge!(header)
@@ -19,7 +19,6 @@ require 'base64'
19
19
 
20
20
  module Elasticsearch
21
21
  module Transport
22
-
23
22
  # Methods for the Elastic meta header used by Cloud.
24
23
  # X-Elastic-Client-Meta HTTP header which is used by Elastic Cloud and can be disabled when
25
24
  # instantiating the Client with the :enable_meta_header parameter set to `false`.
@@ -42,8 +41,10 @@ module Elasticsearch
42
41
  end
43
42
 
44
43
  def meta_header_service_version
45
- if defined?(Elastic::META_HEADER_SERVICE_VERSION)
46
- Elastic::META_HEADER_SERVICE_VERSION
44
+ if enterprise_search?
45
+ Elastic::ENTERPRISE_SERVICE_VERSION
46
+ elsif elasticsearch?
47
+ Elastic::ELASTICSEARCH_SERVICE_VERSION
47
48
  elsif defined?(Elasticsearch::VERSION)
48
49
  [:es, client_meta_version(Elasticsearch::VERSION)]
49
50
  else
@@ -51,6 +52,20 @@ module Elasticsearch
51
52
  end
52
53
  end
53
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
+
54
69
  # We return the current version if it's a release, but if it's a pre/alpha/beta release we
55
70
  # return <VERSION_NUMBER>p
56
71
  #
@@ -78,16 +78,13 @@ module Elasticsearch
78
78
 
79
79
  # Returns a connection.
80
80
  #
81
- # If there are no alive connections, resurrects a connection with least failures.
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
- if connections.empty? && dead_connection = dead.sort { |a,b| a.failures <=> b.failures }.first
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)
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Transport
20
- VERSION = '7.11.2'.freeze
20
+ VERSION = '7.13.3'.freeze
21
21
  end
22
22
  end
@@ -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
 
@@ -251,7 +251,7 @@ describe Elasticsearch::Transport::Client do
251
251
 
252
252
  context 'when using a different service version' do
253
253
  before do
254
- stub_const("Elastic::META_HEADER_SERVICE_VERSION", [:ent, '8.0.0'])
254
+ stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
255
255
  end
256
256
 
257
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 /host: x/, c.to_s
68
- assert_match /alive/, c.to_s
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 /http:\/\/user:\*{1,15}@localhost\:9200/, message
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 /\?format=yaml/, url
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 /\?format=json/, url
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, options|
149
- assert_equal 'myapp-0.0', options[:headers]['User-Agent']
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.11.2
4
+ version: 7.13.3
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-25 00:00:00.000000000 Z
11
+ date: 2021-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -429,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
429
429
  - !ruby/object:Gem::Version
430
430
  version: '0'
431
431
  requirements: []
432
- rubygems_version: 3.1.4
432
+ rubygems_version: 3.2.15
433
433
  signing_key:
434
434
  specification_version: 4
435
435
  summary: Ruby client for Elasticsearch.