Skip to content

Commit 9228b1e

Browse files
[8.17] Upgrade elasticsearch-ruby client. (backport #17161) (backport #17306) (#17339)
* [8.x] Upgrade elasticsearch-ruby client. (backport #17161) (#17306) * Upgrade elasticsearch-ruby client. (#17161) * Fix Faraday removed basic auth option and apply the ES client module name change. (cherry picked from commit e748488) * Apply the required changes in elasticsearch_client.rb after upgrading the elasticsearch-ruby client to 8.x * Swallow the exception and make non-connectable client when ES client raises connection refuses exception. --------- Co-authored-by: Mashhur <[email protected]> Co-authored-by: Mashhur <[email protected]> (cherry picked from commit 7f74ce3) * Update Gemfile lock to reflect elasticsearch-ruby changes. * Upgrade faraday to v2 in Gemfile lock. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Mashhur <[email protected]>
1 parent 7c46a7d commit 9228b1e

File tree

10 files changed

+36
-51
lines changed

10 files changed

+36
-51
lines changed

Gemfile.jruby-3.1.lock.release

+15-34
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PATH
1111
clamp (~> 1)
1212
concurrent-ruby (~> 1, < 1.1.10)
1313
down (~> 5.2.0)
14-
elasticsearch (~> 7)
14+
elasticsearch (~> 8)
1515
filesize (~> 0.2)
1616
gems (~> 1)
1717
i18n (~> 1)
@@ -112,44 +112,23 @@ GEM
112112
elastic-enterprise-search (8.9.0)
113113
elastic-transport (~> 8.1)
114114
jwt (>= 1.5, < 3.0)
115-
elastic-transport (8.3.5)
115+
elastic-transport (8.4.0)
116116
faraday (< 3)
117117
multi_json
118-
elasticsearch (7.17.11)
119-
elasticsearch-api (= 7.17.11)
120-
elasticsearch-transport (= 7.17.11)
121-
elasticsearch-api (7.17.11)
122-
multi_json
123-
elasticsearch-transport (7.17.11)
124-
base64
125-
faraday (>= 1, < 3)
118+
elasticsearch (8.17.1)
119+
elastic-transport (~> 8.3)
120+
elasticsearch-api (= 8.17.1)
121+
elasticsearch-api (8.17.1)
126122
multi_json
127123
equalizer (0.0.11)
128124
et-orbi (1.2.11)
129125
tzinfo
130-
faraday (1.10.4)
131-
faraday-em_http (~> 1.0)
132-
faraday-em_synchrony (~> 1.0)
133-
faraday-excon (~> 1.1)
134-
faraday-httpclient (~> 1.0)
135-
faraday-multipart (~> 1.0)
136-
faraday-net_http (~> 1.0)
137-
faraday-net_http_persistent (~> 1.0)
138-
faraday-patron (~> 1.0)
139-
faraday-rack (~> 1.0)
140-
faraday-retry (~> 1.0)
141-
ruby2_keywords (>= 0.0.4)
142-
faraday-em_http (1.0.0)
143-
faraday-em_synchrony (1.0.0)
144-
faraday-excon (1.1.0)
145-
faraday-httpclient (1.0.1)
146-
faraday-multipart (1.0.4)
147-
multipart-post (~> 2)
148-
faraday-net_http (1.0.2)
149-
faraday-net_http_persistent (1.2.0)
150-
faraday-patron (1.0.0)
151-
faraday-rack (1.0.0)
152-
faraday-retry (1.0.3)
126+
faraday (2.12.2)
127+
faraday-net_http (>= 2.0, < 3.5)
128+
json
129+
logger
130+
faraday-net_http (3.4.0)
131+
net-http (>= 0.5.0)
153132
ffi (1.17.1-java)
154133
filesize (0.2.0)
155134
fileutils (1.7.3)
@@ -728,6 +707,8 @@ GEM
728707
mustermann (3.0.3)
729708
ruby2_keywords (~> 0.0.1)
730709
naught (1.1.0)
710+
net-http (0.6.0)
711+
uri
731712
net-imap (0.5.6)
732713
date
733714
net-protocol
@@ -866,6 +847,7 @@ GEM
866847
tzinfo-data (1.2024.2)
867848
tzinfo (>= 1.0.0)
868849
unicode-display_width (2.6.0)
850+
uri (1.0.3)
869851
webhdfs (0.11.0)
870852
addressable
871853
webmock (3.24.0)
@@ -886,7 +868,6 @@ DEPENDENCIES
886868
childprocess (~> 4)
887869
ci_reporter_rspec (~> 1)
888870
date (= 3.3.3)
889-
faraday (~> 1)
890871
fileutils (~> 1.7)
891872
flores (~> 0.0.8)
892873
fpm (~> 1, >= 1.14.1)

Gemfile.template

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ gem "ruby-maven-libs", "~> 3", ">= 3.9.6.1"
1313
gem "logstash-output-elasticsearch", ">= 11.14.0"
1414
gem "polyglot", require: false
1515
gem "treetop", require: false
16-
gem "faraday", "~> 1", :require => false # due elasticsearch-transport (elastic-transport) depending faraday '~> 1'
1716
gem "minitar", "~> 1", :group => :build
1817
gem "childprocess", "~> 4", :group => :build
1918
gem "fpm", "~> 1", ">= 1.14.1", :group => :build # compound due to bugfix https://github.com/jordansissel/fpm/pull/1856

logstash-core/lib/logstash/elasticsearch_client.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
# under the License.
1717

1818
require "elasticsearch"
19-
require "elasticsearch/transport/transport/http/manticore"
19+
require "elastic/transport/transport/http/manticore"
2020
require 'logstash/util/manticore_ssl_config_helper'
2121
require 'logstash/util/password'
2222

2323
module LogStash class ElasticsearchClient
2424
include LogStash::Util::Loggable
2525

2626
class Response
27-
# duplicated here from Elasticsearch::Transport::Transport::Response
27+
# duplicated here from Elastic::Transport::Transport::Response
2828
# to create a normalised response across different client IMPL
2929
attr_reader :status, :body, :headers
3030

@@ -65,8 +65,13 @@ def initialize(settings, logger)
6565
def can_connect?
6666
begin
6767
head(SecureRandom.hex(32).prepend('_'))
68-
rescue Elasticsearch::Transport::Transport::Errors::BadRequest
68+
rescue Elastic::Transport::Transport::Errors::BadRequest
6969
true
70+
rescue Elastic::Transport::Transport::Errors::Unauthorized
71+
true
72+
rescue Exception => e
73+
return true if e.message.include?('Connection refused')
74+
raise e
7075
rescue Manticore::SocketException
7176
false
7277
end
@@ -116,7 +121,7 @@ def normalize_response(response)
116121

117122
def client_args
118123
{
119-
:transport_class => Elasticsearch::Transport::Transport::HTTP::Manticore,
124+
:transport_class => Elastic::Transport::Transport::HTTP::Manticore,
120125
:hosts => [*unpack_hosts],
121126
# :logger => @logger, # silence the client logging
122127
}

logstash-core/logstash-core.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Gem::Specification.new do |gem|
3939
gem.email = ["[email protected]"]
4040
gem.description = %q{The core components of logstash, the scalable log and event management tool}
4141
gem.summary = %q{logstash-core - The core components of logstash}
42-
gem.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
42+
gem.homepage = "https://www.elastic.co/logstash"
4343
gem.license = "Apache-2.0"
4444

4545
gem.files = Dir.glob(
@@ -78,7 +78,7 @@ Gem::Specification.new do |gem|
7878

7979
gem.add_runtime_dependency "jrjackson", "= #{ALL_VERSIONS.fetch('jrjackson')}" #(Apache 2.0 license)
8080

81-
gem.add_runtime_dependency "elasticsearch", '~> 7'
81+
gem.add_runtime_dependency "elasticsearch", '~> 8'
8282
gem.add_runtime_dependency "manticore", '~> 0.6'
8383

8484
# xpack geoip database service

logstash-core/spec/logstash/webserver_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def free_ports(servers)
189189
context "and invalid basic auth is provided" do
190190
it 'emits an HTTP 401 with WWW-Authenticate header' do
191191
response = Faraday.new("http://#{api_host}:#{webserver.port}") do |conn|
192-
conn.request :basic_auth, 'john-doe', 'open-sesame'
192+
conn.request :authorization, :basic, 'john-doe', 'open-sesame'
193193
end.get('/')
194194
aggregate_failures do
195195
expect(response.status).to eq(401)
@@ -200,7 +200,7 @@ def free_ports(servers)
200200
context "and valid auth is provided" do
201201
it "returns a relevant response" do
202202
response = Faraday.new("http://#{api_host}:#{webserver.port}") do |conn|
203-
conn.request :basic_auth, 'a-user', 's3cur3dPas!'
203+
conn.request :authorization, :basic, 'a-user', 's3cur3dPas!'
204204
end.get('/')
205205
aggregate_failures do
206206
expect(response.status).to eq(200)

qa/integration/specs/dlq_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@
8383
try(60) do
8484
begin
8585
result = es_client.search(index: 'test-index', size: 0, q: '*')
86-
rescue Elasticsearch::Transport::Transport::Errors::ServiceUnavailable => e
86+
rescue Elastic::Transport::Transport::Errors::ServiceUnavailable => e
8787
puts "Elasticsearch unavailable #{e.inspect}"
8888
hits = 0
89-
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
89+
rescue Elastic::Transport::Transport::Errors::NotFound => e
9090
puts "Index not found"
9191
hits = 0
9292
end

x-pack/qa/integration/management/multiple_pipelines_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def count_hashes(pipelines)
137137

138138
begin
139139
res = elasticsearch_client.search(index: '.monitoring-logstash-*', body: query)
140-
rescue Elasticsearch::Transport::Transport::Errors::ServiceUnavailable
140+
rescue Elastic::Transport::Transport::Errors::ServiceUnavailable
141141
return nil
142142
end
143143

x-pack/qa/integration/monitoring/es_documents_structure_validation_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
let(:retryable_errors) do
2020
[NoMethodError,
2121
RSpec::Expectations::ExpectationNotMetError,
22-
Elasticsearch::Transport::Transport::Errors::ServiceUnavailable,
23-
Elasticsearch::Transport::Transport::Errors::NotFound]
22+
Elastic::Transport::Transport::Errors::ServiceUnavailable,
23+
Elastic::Transport::Transport::Errors::NotFound]
2424
end
2525

2626
describe "metrics" do

x-pack/qa/integration/support/helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def cleanup_system_indices(pipeline_ids)
124124
pipeline_ids.each do |id|
125125
begin
126126
elasticsearch_client.perform_request(:delete, "_logstash/pipeline/#{id}")
127-
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
127+
rescue Elastic::Transport::Transport::Errors::NotFound => e
128128
puts ".logstash can be empty #{e.message}"
129129
end
130130
end

x-pack/qa/integration/support/shared_examples.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
let(:retryable_errors) do
1010
[NoMethodError,
1111
RSpec::Expectations::ExpectationNotMetError,
12-
Elasticsearch::Transport::Transport::Errors::ServiceUnavailable,
13-
Elasticsearch::Transport::Transport::Errors::NotFound]
12+
Elastic::Transport::Transport::Errors::ServiceUnavailable,
13+
Elastic::Transport::Transport::Errors::NotFound]
1414
end
1515

1616
describe "metrics" do

0 commit comments

Comments
 (0)