logstash-filter-elasticsearch 3.17.0 → 3.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaf8d73f069f6550d53c38b1a27f5444f77b774bbe62d66b7b7dd276be4125fc
4
- data.tar.gz: 19b2d5030a25fd03c78baf5edb6b18a649cc0751fa02f38fdfd8a9959669b9bc
3
+ metadata.gz: a29cd8cf20b82a601cbaaae69662b4341a40dc5d7c935c0c5b13b6b36d7de236
4
+ data.tar.gz: bd1e19d8f42b8066aee89c44622d5efa193e0a800ac1951c186bcaf7ed166626
5
5
  SHA512:
6
- metadata.gz: f3792d01a260e9dcada0ddc7df7aaebbfc1280025781f4c8f2640eaba3abd0d777982f31b794cd7e37b1ce9430bd1f2a60d73dc05ddb8fc0eedd778d9574f1c6
7
- data.tar.gz: 0743bccc0a8da98dd91d697ab1b05e95fae2853fd24e8d6db6887ec7ad636de2ae970ff65e15d491388402c702d71adc2190b987a30e5ee2f30a39daf5014954
6
+ metadata.gz: 0c1374ae82f6a3b78b9192186b8dddae4a4826da2befdcf471d8a26abc3faa433f901ed76ad7e1ba0f3e0f1fd223813230125d7c588a454374315dc55935f5b4
7
+ data.tar.gz: 4555b95388fe23d825e7d5a34c1a5714dccf394b8657182c483858bef383fae17bd6bb2f818af3c21f0304d29606df9e42378058d675518ffa1a5c9904a3ac37
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.17.1
2
+ - Add elastic-transport client support used in elasticsearch-ruby 8.x [#193](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/193)
3
+
1
4
  ## 3.17.0
2
5
  - Added support for custom headers [#190](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/190)
3
6
 
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "elasticsearch"
3
3
  require "base64"
4
- require "elasticsearch/transport/transport/http/manticore"
5
4
 
6
5
 
7
6
  module LogStash
@@ -9,6 +8,7 @@ module LogStash
9
8
  class ElasticsearchClient
10
9
 
11
10
  attr_reader :client
11
+ attr_reader :es_transport_client_type
12
12
 
13
13
  BUILD_FLAVOR_SERVERLESS = 'serverless'.freeze
14
14
  DEFAULT_EAV_HEADER = { "Elastic-Api-Version" => "2023-10-31" }.freeze
@@ -44,7 +44,7 @@ module LogStash
44
44
 
45
45
  client_options = {
46
46
  hosts: hosts,
47
- transport_class: ::Elasticsearch::Transport::Transport::HTTP::Manticore,
47
+ transport_class: get_transport_client_class,
48
48
  transport_options: transport_options,
49
49
  ssl: ssl_options,
50
50
  retry_on_failure: options[:retry_on_failure],
@@ -98,6 +98,20 @@ module LogStash
98
98
  token = ::Base64.strict_encode64(api_key.value)
99
99
  { 'Authorization' => "ApiKey #{token}" }
100
100
  end
101
+
102
+ def get_transport_client_class
103
+ # LS-core includes `elasticsearch` gem. The gem is composed of two separate gems: `elasticsearch-api` and `elasticsearch-transport`
104
+ # And now `elasticsearch-transport` is old, instead we have `elastic-transport`.
105
+ # LS-core updated `elasticsearch` > 8: https://github.com/elastic/logstash/pull/17161
106
+ # Following source bits are for the compatibility to support both `elasticsearch-transport` and `elastic-transport` gems
107
+ require "elasticsearch/transport/transport/http/manticore"
108
+ es_transport_client_type = "elasticsearch_transport"
109
+ ::Elasticsearch::Transport::Transport::HTTP::Manticore
110
+ rescue ::LoadError
111
+ require "elastic/transport/transport/http/manticore"
112
+ es_transport_client_type = "elastic_transport"
113
+ ::Elastic::Transport::Transport::HTTP::Manticore
114
+ end
101
115
  end
102
116
  end
103
117
  end
@@ -7,7 +7,6 @@ require "logstash/plugin_mixins/normalize_config_support"
7
7
  require "monitor"
8
8
 
9
9
  require_relative "elasticsearch/client"
10
- require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
11
10
 
12
11
  class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
13
12
  config_name "elasticsearch"
@@ -183,6 +182,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
183
182
 
184
183
  test_connection!
185
184
  setup_serverless
185
+ if get_client.es_transport_client_type == "elasticsearch_transport"
186
+ require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
187
+ end
186
188
  end # def register
187
189
 
188
190
  def filter(event)
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-elasticsearch'
4
- s.version = '3.17.0'
4
+ s.version = '3.17.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Copies fields from previous log events in Elasticsearch to current events "
7
7
  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"
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
- s.add_runtime_dependency 'elasticsearch', ">= 7.14.9" # LS >= 6.7 and < 7.14 all used version 5.0.5
24
+ s.add_runtime_dependency 'elasticsearch', ">= 7.14.9", '< 9'
25
25
  s.add_runtime_dependency 'manticore', ">= 0.7.1"
26
26
  s.add_runtime_dependency 'logstash-mixin-ca_trusted_fingerprint_support', '~> 1.0'
27
27
  s.add_runtime_dependency 'logstash-mixin-normalize_config_support', '~>1.0'
@@ -60,9 +60,18 @@ describe LogStash::Filters::Elasticsearch do
60
60
  allow(plugin).to receive(:get_client).and_return(filter_client)
61
61
  allow(filter_client).to receive(:serverless?).and_return(true)
62
62
  allow(filter_client).to receive(:client).and_return(es_client)
63
- allow(es_client).to receive(:info).with(a_hash_including(:headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER)).and_raise(
64
- Elasticsearch::Transport::Transport::Errors::BadRequest.new
65
- )
63
+
64
+ if elastic_ruby_v8_client_available?
65
+ allow(es_client).to receive(:info)
66
+ .with(a_hash_including(
67
+ :headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER))
68
+ .and_raise(Elastic::Transport::Transport::Errors::BadRequest.new)
69
+ else
70
+ allow(es_client).to receive(:info)
71
+ .with(a_hash_including(
72
+ :headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER))
73
+ .and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
74
+ end
66
75
  end
67
76
 
68
77
  it "raises an exception when Elastic Api Version is not supported" do
@@ -103,6 +112,11 @@ describe LogStash::Filters::Elasticsearch do
103
112
 
104
113
  before(:each) do
105
114
  allow(LogStash::Filters::ElasticsearchClient).to receive(:new).and_return(client)
115
+ if elastic_ruby_v8_client_available?
116
+ allow(client).to receive(:es_transport_client_type).and_return('elastic_transport')
117
+ else
118
+ allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
119
+ end
106
120
  allow(client).to receive(:search).and_return(response)
107
121
  allow(plugin).to receive(:test_connection!)
108
122
  allow(plugin).to receive(:setup_serverless)
@@ -347,6 +361,11 @@ describe LogStash::Filters::Elasticsearch do
347
361
 
348
362
  before do
349
363
  allow(plugin).to receive(:get_client).and_return(client_double)
364
+ if elastic_ruby_v8_client_available?
365
+ allow(client_double).to receive(:es_transport_client_type).and_return('elastic_transport')
366
+ else
367
+ allow(client_double).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
368
+ end
350
369
  allow(client_double).to receive(:client).and_return(transport_double)
351
370
  end
352
371
 
@@ -506,7 +525,12 @@ describe LogStash::Filters::Elasticsearch do
506
525
  # this spec is a safeguard to trigger an assessment of thread-safety should
507
526
  # we choose a different transport adapter in the future.
508
527
  transport_class = extract_transport(client).options.fetch(:transport_class)
509
- expect(transport_class).to equal ::Elasticsearch::Transport::Transport::HTTP::Manticore
528
+ if elastic_ruby_v8_client_available?
529
+ allow(client).to receive(:es_transport_client_type).and_return("elastic_transport")
530
+ expect(transport_class).to equal ::Elastic::Transport::Transport::HTTP::Manticore
531
+ else
532
+ expect(transport_class).to equal ::Elasticsearch::Transport::Transport::HTTP::Manticore
533
+ end
510
534
  end
511
535
 
512
536
  it 'uses a client with sufficient connection pool size' do
@@ -821,6 +845,11 @@ describe LogStash::Filters::Elasticsearch do
821
845
 
822
846
  before(:each) do
823
847
  allow(LogStash::Filters::ElasticsearchClient).to receive(:new).and_return(client)
848
+ if elastic_ruby_v8_client_available?
849
+ allow(client).to receive(:es_transport_client_type).and_return('elastic_transport')
850
+ else
851
+ allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
852
+ end
824
853
  allow(plugin).to receive(:test_connection!)
825
854
  allow(plugin).to receive(:setup_serverless)
826
855
  plugin.register
@@ -835,11 +864,19 @@ describe LogStash::Filters::Elasticsearch do
835
864
  end
836
865
  end
837
866
 
838
- # @note can be removed once gem depends on elasticsearch >= 6.x
839
- def extract_transport(client) # on 7.x client.transport is a ES::Transport::Client
867
+ def extract_transport(client)
868
+ # on 7x: client.transport.transport
869
+ # on >=8.x: client.transport
840
870
  client.transport.respond_to?(:transport) ? client.transport.transport : client.transport
841
871
  end
842
872
 
873
+ def elastic_ruby_v8_client_available?
874
+ Elasticsearch::Transport
875
+ false
876
+ rescue NameError # NameError: uninitialized constant Elasticsearch::Transport if Elastic Ruby client is not available
877
+ true
878
+ end
879
+
843
880
  class MockResponse
844
881
  attr_reader :code, :headers
845
882
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.17.0
4
+ version: 3.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-29 00:00:00.000000000 Z
11
+ date: 2025-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -36,6 +36,9 @@ dependencies:
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
38
  version: 7.14.9
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: '9'
39
42
  name: elasticsearch
40
43
  type: :runtime
41
44
  prerelease: false
@@ -44,6 +47,9 @@ dependencies:
44
47
  - - ">="
45
48
  - !ruby/object:Gem::Version
46
49
  version: 7.14.9
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '9'
47
53
  - !ruby/object:Gem::Dependency
48
54
  requirement: !ruby/object:Gem::Requirement
49
55
  requirements: