Skip to content

Commit cd8d64d

Browse files
committed
switch to manticore and improve logging during connection failures
1 parent 98227e5 commit cd8d64d

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.5.0
2+
- Added connection check during register to avoid failures during processing
3+
- Changed Elasticsearch Client transport to use Manticore
4+
- Changed amount of logging details during connection failure
5+
16
## 3.4.0
27
- Adds `[@metadata][total_hits]` with total hits returned from the query ([#106](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/106))
38
- Improves error logging to fully inspect caught exceptions ([#105](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/105))

lib/logstash/filters/elasticsearch.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def register
7171
@query_dsl = file.read
7272
end
7373

74+
test_connection!
7475
end # def register
7576

7677
def filter(event)
@@ -123,7 +124,13 @@ def filter(event)
123124
end
124125

125126
rescue => e
126-
@logger.warn("Failed to query elasticsearch for previous event", :index => @index, :query => query, :event => event, :error => e.inspect)
127+
if @logger.trace?
128+
@logger.warn("Failed to query elasticsearch for previous event", :index => @index, :query => query, :event => event.to_hash, :error => e.message, :backtrace => e.backtrace)
129+
elsif @logger.debug?
130+
@logger.warn("Failed to query elasticsearch for previous event", :index => @index, :error => e.message, :backtrace => e.backtrace)
131+
else
132+
@logger.warn("Failed to query elasticsearch for previous event", :index => @index, :error => e.message)
133+
end
127134
@tag_on_failure.each{|tag| event.tag(tag)}
128135
else
129136
filter_matched(event) if matched
@@ -165,4 +172,8 @@ def extract_value(source, path)
165172
memo[old_key_fragment]
166173
end
167174
end
175+
176+
def test_connection!
177+
get_client.client.ping
178+
end
168179
end #class LogStash::Filters::Elasticsearch

lib/logstash/filters/elasticsearch/client.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# encoding: utf-8
22
require "elasticsearch"
33
require "base64"
4+
require "elasticsearch/transport/transport/http/manticore"
45

56

67
module LogStash
@@ -22,10 +23,11 @@ def initialize(user, password, options={})
2223

2324
hosts.map! {|h| { host: h, scheme: 'https' } } if ssl
2425
# set ca_file even if ssl isn't on, since the host can be an https url
25-
transport_options[:ssl] = { ca_file: options[:ca_file] } if options[:ca_file]
26+
ssl_options = { ssl: true, ca_file: options[:ca_file] } if options[:ca_file]
27+
ssl_options ||= {}
2628

2729
@logger.info("New ElasticSearch filter client", :hosts => hosts)
28-
@client = ::Elasticsearch::Client.new(hosts: hosts, transport_options: transport_options)
30+
@client = ::Elasticsearch::Client.new(hosts: hosts, transport_options: transport_options, transport_class: ::Elasticsearch::Transport::Transport::HTTP::Manticore, :ssl => ssl_options)
2931
end
3032

3133
def search(params)

logstash-filter-elasticsearch.gemspec

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

33
s.name = 'logstash-filter-elasticsearch'
4-
s.version = '3.4.0'
4+
s.version = '3.5.0'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Copies fields from previous log events in Elasticsearch to current events "
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"
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
2222
# Gem dependencies
2323
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
2424
s.add_runtime_dependency 'elasticsearch', ">= 5.0.3", " <6.0.0"
25+
s.add_runtime_dependency 'manticore', "~> 0.6"
2526

2627
s.add_development_dependency 'logstash-devutils'
2728
end

spec/filters/elasticsearch_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
context "registration" do
1010

1111
let(:plugin) { LogStash::Plugin.lookup("filter", "elasticsearch").new({}) }
12+
before do
13+
allow(plugin).to receive(:test_connection!)
14+
end
1215

1316
it "should not raise an exception" do
1417
expect {plugin.register}.to_not raise_error
@@ -37,6 +40,7 @@
3740
before(:each) do
3841
allow(LogStash::Filters::ElasticsearchClient).to receive(:new).and_return(client)
3942
allow(client).to receive(:search).and_return(response)
43+
allow(plugin).to receive(:test_connection!)
4044
plugin.register
4145
end
4246

0 commit comments

Comments
 (0)