Skip to content

Commit 7f74ce3

Browse files
[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]>
1 parent d45706d commit 7f74ce3

File tree

9 files changed

+21
-17
lines changed

9 files changed

+21
-17
lines changed

Gemfile.template

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ gem "ruby-progressbar", "~> 1", require: false
1212
gem "ruby-maven-libs", "~> 3", ">= 3.9.6.1"
1313
gem "polyglot", require: false
1414
gem "treetop", require: false
15-
gem "faraday", "~> 1", :require => false # due elasticsearch-transport (elastic-transport) depending faraday '~> 1'
1615
gem "minitar", "~> 1", :group => :build
1716
gem "childprocess", "~> 4", :group => :build
1817
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)