logstash-filter-elasticsearch 3.15.1 → 3.15.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: 4a80d8c888e4c85fad00861c48191031b12827b75d4f7adf2f82d3be8023ef4c
4
- data.tar.gz: ecf9e2cf9c3d020bc5ece06d2b430bef230f60f2505847a534556fd95d72094f
3
+ metadata.gz: 7e85d9b1122e7e095666cdc3bfa1dd5fbd3ef62ce5cf15d667ffa92932e5748e
4
+ data.tar.gz: cbcf76ec5d048bb18f467520f4a646a08e5ea39a8d44ace7a3322e7fea0eee06
5
5
  SHA512:
6
- metadata.gz: c02acdc7b189b40b9d53f32374c982a0239a2be8a5e6d10f4ec62ee99771822e3a8b0345e432f5fd488eaed02e8f9207b82b4226e29f310bbbfc2f786eafd6bc
7
- data.tar.gz: 25cfab8d4069d7e30c5f1dd113857c24ce8c43ef7ed566b66230c64ead218398e28f504b7c0f5d864a8a6174cbf817e1f76faa22d996f15cfa0e298d3ed6e334
6
+ metadata.gz: 6bc45e8790eede5047013506fe8b9f8ba97ad08365f6ab99d5fd7ca120e051f916301054e23932d068823ba8f0904757de9bc0bb255d13b1967b339c600e4011
7
+ data.tar.gz: '07842227fb3c356f08012193925fe1b5ae055ead761600c029e0ea4a788b97744113e35ebf97c05e223270e14017bf1d10b66a0ca038a810ca5054c1c2ff8389'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 3.15.3
2
+ - Fixes a memory leak that occurs when a pipeline containing this filter terminates, which could become significant if the pipeline is cycled repeatedly [#173](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/173)
3
+
4
+ ## 3.15.2
5
+ - Added checking for `query` and `query_template`. [#171](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/171)
6
+
1
7
  ## 3.15.1
2
8
  - Fixes a regression introduced in 3.15.0 which could prevent a connection from being established to Elasticsearch in some SSL configurations
3
9
 
data/docs/index.asciidoc CHANGED
@@ -320,6 +320,7 @@ environment variables e.g. `proxy => '${LS_PROXY:}'`.
320
320
  Elasticsearch query string. More information is available in the
321
321
  {ref}/query-dsl-query-string-query.html#query-string-syntax[Elasticsearch query
322
322
  string documentation].
323
+ Use either `query` or `query_template`.
323
324
 
324
325
 
325
326
  [id="plugins-{type}s-{plugin}-query_template"]
@@ -330,6 +331,7 @@ string documentation].
330
331
 
331
332
  File path to elasticsearch query in DSL format. More information is available in
332
333
  the {ref}/query-dsl.html[Elasticsearch query documentation].
334
+ Use either `query` or `query_template`.
333
335
 
334
336
  [id="plugins-{type}s-{plugin}-result_size"]
335
337
  ===== `result_size`
@@ -22,6 +22,9 @@ module LogStash
22
22
  transport_options[:headers].merge!(setup_api_key(api_key))
23
23
  transport_options[:headers].merge!({ 'user-agent' => "#{user_agent}" })
24
24
 
25
+ transport_options[:pool_max] = 1000
26
+ transport_options[:pool_max_per_route] = 100
27
+
25
28
  logger.warn "Supplied proxy setting (proxy => '') has no effect" if @proxy.eql?('')
26
29
  transport_options[:proxy] = proxy.to_s if proxy && !proxy.eql?('')
27
30
 
@@ -4,6 +4,7 @@ require "logstash/namespace"
4
4
  require "logstash/json"
5
5
  require 'logstash/plugin_mixins/ca_trusted_fingerprint_support'
6
6
  require "logstash/plugin_mixins/normalize_config_support"
7
+ require "monitor"
7
8
 
8
9
  require_relative "elasticsearch/client"
9
10
  require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
@@ -139,7 +140,8 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
139
140
 
140
141
  include LogStash::PluginMixins::NormalizeConfigSupport
141
142
 
142
- attr_reader :clients_pool
143
+ include MonitorMixin
144
+ attr_reader :shared_client
143
145
 
144
146
  ##
145
147
  # @override to handle proxy => '' as if none was set
@@ -159,8 +161,6 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
159
161
  end
160
162
 
161
163
  def register
162
- @clients_pool = java.util.concurrent.ConcurrentHashMap.new
163
-
164
164
  #Load query if it exists
165
165
  if @query_template
166
166
  if File.zero?(@query_template)
@@ -170,6 +170,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
170
170
  @query_dsl = file.read
171
171
  end
172
172
 
173
+ validate_query_settings
173
174
  fill_hosts_from_cloud_id
174
175
  setup_ssl_params!
175
176
  validate_authentication
@@ -351,7 +352,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
351
352
  end
352
353
 
353
354
  def get_client
354
- @clients_pool.computeIfAbsent(Thread.current, lambda { |x| new_client })
355
+ @shared_client || synchronize do
356
+ @shared_client ||= new_client
357
+ end
355
358
  end
356
359
 
357
360
  # get an array of path elements from a path reference
@@ -391,6 +394,16 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
391
394
  hosts.is_a?(Array) && hosts.size == 1 && !original_params.key?('hosts')
392
395
  end
393
396
 
397
+ def validate_query_settings
398
+ unless @query || @query_template
399
+ raise LogStash::ConfigurationError, "Both `query` and `query_template` are empty. Require either `query` or `query_template`."
400
+ end
401
+
402
+ if @query && @query_template
403
+ raise LogStash::ConfigurationError, "Both `query` and `query_template` are set. Use either `query` or `query_template`."
404
+ end
405
+ end
406
+
394
407
  def validate_authentication
395
408
  authn_options = 0
396
409
  authn_options += 1 if @cloud_auth
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-elasticsearch'
4
- s.version = '3.15.1'
4
+ s.version = '3.15.3'
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"
@@ -15,9 +15,11 @@ describe LogStash::Filters::Elasticsearch do
15
15
 
16
16
  context "registration" do
17
17
 
18
- let(:plugin) { LogStash::Plugin.lookup("filter", "elasticsearch").new({}) }
18
+ let(:plugin) { LogStash::Plugin.lookup("filter", "elasticsearch").new(config) }
19
19
 
20
20
  context "against authentic Elasticsearch" do
21
+ let(:config) { { "query" => "*" } }
22
+
21
23
  before do
22
24
  allow(plugin).to receive(:test_connection!)
23
25
  end
@@ -28,6 +30,7 @@ describe LogStash::Filters::Elasticsearch do
28
30
  end
29
31
 
30
32
  context "against not authentic Elasticsearch" do
33
+ let(:config) { { "query" => "*" } }
31
34
  let(:failing_client) do
32
35
  client = double("client")
33
36
  allow(client).to receive(:ping).and_raise Elasticsearch::UnsupportedProductError
@@ -45,6 +48,19 @@ describe LogStash::Filters::Elasticsearch do
45
48
  expect {plugin.register}.to raise_error(LogStash::ConfigurationError)
46
49
  end
47
50
  end
51
+
52
+ context "query settings" do
53
+ it "raise an exception when query and query_template are empty" do
54
+ plugin = described_class.new({})
55
+ expect {plugin.register}.to raise_error(LogStash::ConfigurationError)
56
+ end
57
+
58
+ it "raise an exception when query and query_template are set" do
59
+ config = { "query" => "*", "query_template" => File.join(File.dirname(__FILE__), "fixtures", "query_template_unicode.json") }
60
+ plugin = described_class.new(config)
61
+ expect {plugin.register}.to raise_error(LogStash::ConfigurationError)
62
+ end
63
+ end
48
64
  end
49
65
 
50
66
  describe "data fetch" do
@@ -75,21 +91,6 @@ describe LogStash::Filters::Elasticsearch do
75
91
  Thread.current[:filter_elasticsearch_client] = nil
76
92
  end
77
93
 
78
- # Since the Elasticsearch Ruby client is not thread safe
79
- # and under high load we can get error with the connection pool
80
- # we have decided to create a new instance per worker thread which
81
- # will be lazy created on the first call to `#filter`
82
- #
83
- # I am adding a simple test case for future changes
84
- it "uses a different connection object per thread wait" do
85
- expect(plugin.clients_pool.size).to eq(0)
86
-
87
- Thread.new { plugin.filter(event) }.join
88
- Thread.new { plugin.filter(event) }.join
89
-
90
- expect(plugin.clients_pool.size).to eq(2)
91
- end
92
-
93
94
  it "should enhance the current event with new data" do
94
95
  plugin.filter(event)
95
96
  expect(event.get("code")).to eq(404)
@@ -450,6 +451,32 @@ describe LogStash::Filters::Elasticsearch do
450
451
  Thread.current[:filter_elasticsearch_client] = nil
451
452
  end
452
453
 
454
+ it 'uses a threadsafe transport adapter' do
455
+ client = plugin.send(:get_client).client
456
+ # we currently rely on the threadsafety guarantees provided by Manticore
457
+ # this spec is a safeguard to trigger an assessment of thread-safety should
458
+ # we choose a different transport adapter in the future.
459
+ transport_class = extract_transport(client).options.fetch(:transport_class)
460
+ expect(transport_class).to equal ::Elasticsearch::Transport::Transport::HTTP::Manticore
461
+ end
462
+
463
+ it 'uses a client with sufficient connection pool size' do
464
+ client = plugin.send(:get_client).client
465
+ transport_options = extract_transport(client).options.fetch(:transport_options)
466
+ # pool_max and pool_max_per_route are manticore-specific transport options
467
+ expect(transport_options).to include(:pool_max => 1000, :pool_max_per_route => 100)
468
+ end
469
+
470
+ it 'uses a single shared client across threads' do
471
+ q = Queue.new
472
+ 10.times.map do
473
+ Thread.new(plugin) { |instance| q.push instance.send(:get_client) }
474
+ end.map(&:join)
475
+
476
+ first = q.pop
477
+ expect(q.pop).to be(first) until q.empty?
478
+ end
479
+
453
480
  describe "cloud.id" do
454
481
  let(:valid_cloud_id) do
455
482
  'sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=='
@@ -594,7 +621,7 @@ describe LogStash::Filters::Elasticsearch do
594
621
 
595
622
  describe "ca_trusted_fingerprint" do
596
623
  let(:ca_trusted_fingerprint) { SecureRandom.hex(32) }
597
- let(:config) { {"ssl_enabled" => true, "ca_trusted_fingerprint" => ca_trusted_fingerprint}}
624
+ let(:config) { {"ssl_enabled" => true, "ca_trusted_fingerprint" => ca_trusted_fingerprint, "query" => "*"}}
598
625
 
599
626
  subject(:plugin) { described_class.new(config) }
600
627
 
@@ -633,6 +660,7 @@ describe LogStash::Filters::Elasticsearch do
633
660
  'hosts' => 'https://localhost:9200',
634
661
  'ssl_keystore_path' => keystore_path,
635
662
  'ssl_keystore_password' => keystore_password,
663
+ 'query' => '*'
636
664
  }
637
665
  end
638
666
 
@@ -663,7 +691,7 @@ describe LogStash::Filters::Elasticsearch do
663
691
 
664
692
  describe "defaults" do
665
693
 
666
- let(:config) { Hash.new }
694
+ let(:config) { {"query" => "*"} }
667
695
  let(:plugin) { described_class.new(config) }
668
696
 
669
697
  before { allow(plugin).to receive(:test_connection!) }
@@ -695,9 +723,9 @@ describe LogStash::Filters::Elasticsearch do
695
723
  end
696
724
 
697
725
  it "should read and send non-ascii query" do
698
- expect(client).to receive(:search).with(
726
+ expect(client).to receive(:search).with({
699
727
  :body => { "query" => { "terms" => { "lock" => [ "잠금", "uzávěr" ] } } },
700
- :index => "")
728
+ :index => ""})
701
729
 
702
730
  plugin.filter(LogStash::Event.new)
703
731
  end
@@ -5,7 +5,7 @@ require "logstash/codecs/base"
5
5
  describe "SSL options" do
6
6
  let(:es_client_double) { double("Elasticsearch::Client #{self.inspect}") }
7
7
  let(:hosts) {["localhost"]}
8
- let(:settings) { { "ssl_enabled" => true, "hosts" => hosts } }
8
+ let(:settings) { { "ssl_enabled" => true, "hosts" => hosts, "query" => "*" } }
9
9
 
10
10
  subject do
11
11
  require "logstash/filters/elasticsearch"
@@ -36,7 +36,8 @@ describe "SSL options" do
36
36
  context "false and cloud_id resolved host is https" do
37
37
  let(:settings) {{
38
38
  "ssl_enabled" => false,
39
- "cloud_id" => "sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=="
39
+ "cloud_id" => "sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA==",
40
+ "query" => "*"
40
41
  }}
41
42
 
42
43
  it "should not infer the ssl_enabled value" do
@@ -82,7 +83,8 @@ describe "SSL options" do
82
83
 
83
84
  context "and cloud_id resolved host is https" do
84
85
  let(:settings) {{
85
- "cloud_id" => "sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=="
86
+ "cloud_id" => "sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA==",
87
+ "query" => "*"
86
88
  }}
87
89
 
88
90
  it "should infer the ssl_enabled value to false" do
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.15.1
4
+ version: 3.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2023-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement