Skip to content

Commit 7b76df7

Browse files
authored
Merge pull request #225 from mashhurs/elastic-transport-support-4.x
Merge pull request #223 from mashhurs/support-elastic-transport-client
2 parents 4380219 + de38377 commit 7b76df7

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.21.2
2+
- Add elastic-transport client support used in elasticsearch-ruby 8.x [#225](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/225)
3+
14
## 4.21.1
25
- Fix: prevent plugin crash when hits contain illegal structure [#183](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/183)
36
- When a hit cannot be converted to an event, the input now emits an event tagged with `_elasticsearch_input_failure` with an `[event][original]` containing a JSON-encoded string representation of the entire hit.

lib/logstash/inputs/elasticsearch.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
require "base64"
1414

1515
require "elasticsearch"
16-
require "elasticsearch/transport/transport/http/manticore"
17-
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
18-
require_relative "elasticsearch/patches/_elasticsearch_transport_connections_selector"
16+
require "manticore"
1917

2018
# .Compatibility Note
2119
# [NOTE]
@@ -323,7 +321,7 @@ def register
323321
@client_options = {
324322
:hosts => hosts,
325323
:transport_options => transport_options,
326-
:transport_class => ::Elasticsearch::Transport::Transport::HTTP::Manticore,
324+
:transport_class => get_transport_client_class,
327325
:ssl => ssl_options
328326
}
329327

@@ -678,6 +676,20 @@ def setup_query_executor
678676
end
679677
end
680678

679+
def get_transport_client_class
680+
# LS-core includes `elasticsearch` gem. The gem is composed of two separate gems: `elasticsearch-api` and `elasticsearch-transport`
681+
# And now `elasticsearch-transport` is old, instead we have `elastic-transport`.
682+
# LS-core updated `elasticsearch` > 8: https://github.com/elastic/logstash/pull/17161
683+
# Following source bits are for the compatibility to support both `elasticsearch-transport` and `elastic-transport` gems
684+
require "elasticsearch/transport/transport/http/manticore"
685+
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
686+
require_relative "elasticsearch/patches/_elasticsearch_transport_connections_selector"
687+
::Elasticsearch::Transport::Transport::HTTP::Manticore
688+
rescue ::LoadError
689+
require "elastic/transport/transport/http/manticore"
690+
::Elastic::Transport::Transport::HTTP::Manticore
691+
end
692+
681693
module URIOrEmptyValidator
682694
##
683695
# @override to provide :uri_or_empty validator

logstash-input-elasticsearch.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-input-elasticsearch'
4-
s.version = '4.21.1'
4+
s.version = '4.21.2'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Reads query results from an Elasticsearch cluster"
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
88
s.authors = ["Elastic"]
99
s.email = '[email protected]'
10-
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10+
s.homepage = "https://elastic.co/logstash"
1111
s.require_paths = ["lib"]
1212

1313
# Files
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
2626
s.add_runtime_dependency "logstash-mixin-validator_support", '~> 1.0'
2727
s.add_runtime_dependency "logstash-mixin-scheduler", '~> 1.0'
2828

29-
s.add_runtime_dependency 'elasticsearch', '>= 7.17.9'
29+
s.add_runtime_dependency 'elasticsearch', '>= 7.17.9', '< 9'
3030
s.add_runtime_dependency 'logstash-mixin-ca_trusted_fingerprint_support', '~> 1.0'
3131
s.add_runtime_dependency 'logstash-mixin-normalize_config_support', '~>1.0'
3232

spec/inputs/elasticsearch_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
let(:es_version) { "7.5.0" }
2222
let(:cluster_info) { {"version" => {"number" => es_version, "build_flavor" => build_flavor}, "tagline" => "You Know, for Search"} }
2323

24+
def elastic_ruby_v8_client_available?
25+
Elasticsearch::Transport
26+
false
27+
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport if Elastic Ruby client is not available
28+
true
29+
end
30+
2431
before(:each) do
2532
Elasticsearch::Client.send(:define_method, :ping) { } # define no-action ping method
2633
allow_any_instance_of(Elasticsearch::Client).to receive(:info).and_return(cluster_info)
@@ -79,9 +86,11 @@
7986

8087
before do
8188
allow(Elasticsearch::Client).to receive(:new).and_return(es_client)
82-
allow(es_client).to receive(:info).and_raise(
83-
Elasticsearch::Transport::Transport::Errors::BadRequest.new
84-
)
89+
if elastic_ruby_v8_client_available?
90+
allow(es_client).to receive(:info).and_raise(Elastic::Transport::Transport::Errors::BadRequest.new)
91+
else
92+
allow(es_client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
93+
end
8594
end
8695

8796
it "raises an exception" do
@@ -731,8 +740,13 @@ def synchronize_method!(object, method_name)
731740
it "should set host(s)" do
732741
plugin.register
733742
client = plugin.send(:client)
734-
735-
expect( client.transport.instance_variable_get(:@seeds) ).to eql [{
743+
target_field = :@seeds
744+
begin
745+
Elasticsearch::Transport::Client
746+
rescue
747+
target_field = :@hosts
748+
end
749+
expect( client.transport.instance_variable_get(target_field) ).to eql [{
736750
:scheme => "https",
737751
:host => "ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io",
738752
:port => 9243,

0 commit comments

Comments
 (0)