Skip to content

Commit

Permalink
Verify connection to Elasticsearch (#150)
Browse files Browse the repository at this point in the history
Update Elasticsearch ruby client to version 7.14 and manage the not valid product error
  • Loading branch information
andsel authored Oct 11, 2021
1 parent bd46017 commit 9fefde9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import:
- logstash-plugins/.ci:travis/[email protected]

env:
- INTEGRATION=false ELASTIC_STACK_VERSION=6.x
- INTEGRATION=false ELASTIC_STACK_VERSION=7.x
- INTEGRATION=true ELASTIC_STACK_VERSION=6.x ELASTIC_PASSWORD=password ELASTIC_SECURITY_ENABLED=true
- INTEGRATION=true ELASTIC_STACK_VERSION=7.x
- INTEGRATION=true ELASTIC_STACK_VERSION=7.x ELASTIC_PASSWORD=password ELASTIC_SECURITY_ENABLED=true
- INTEGRATION=true ELASTIC_STACK_VERSION=7.x SNAPSHOT=true
- INTEGRATION=true ELASTIC_STACK_VERSION=8.x SNAPSHOT=true
- INTEGRATION=true ELASTIC_STACK_VERSION=7.10.2 ELASTIC_PASSWORD=password ELASTIC_SECURITY_ENABLED=true
- INTEGRATION=true ELASTIC_STACK_VERSION=7.14.0 ELASTIC_PASSWORD=password ELASTIC_SECURITY_ENABLED=true
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.11.0
- Feat: update Elasticsearch client to 7.14.0 [#150](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/150)

## 3.10.0
- Feat: add user-agent header passed to the Elasticsearch HTTP connection [#152](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/152)

Expand Down
6 changes: 5 additions & 1 deletion lib/logstash/filters/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ def parse_user_password_from_cloud_auth(cloud_auth)
end

def test_connection!
get_client.client.ping
begin
get_client.client.ping
rescue Elasticsearch::UnsupportedProductError
raise LogStash::ConfigurationError, "Could not connect to a compatible version of Elasticsearch"
end
end
end #class LogStash::Filters::Elasticsearch
4 changes: 2 additions & 2 deletions logstash-filter-elasticsearch.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-filter-elasticsearch'
s.version = '3.10.0'
s.version = '3.11.0'
s.licenses = ['Apache License (2.0)']
s.summary = "Copies fields from previous log events in Elasticsearch to current events "
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"
Expand All @@ -21,7 +21,7 @@ Gem::Specification.new do |s|

# Gem dependencies
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
s.add_runtime_dependency 'elasticsearch', ">= 5.0.5" # LS >= 6.7 and < 7.14 all used version 5.0.5
s.add_runtime_dependency 'elasticsearch', ">= 7.14.0" # LS >= 6.7 and < 7.14 all used version 5.0.5
s.add_runtime_dependency 'manticore', ">= 0.7.1"
s.add_development_dependency 'cabin', ['~> 0.6']
s.add_development_dependency 'webrick'
Expand Down
30 changes: 26 additions & 4 deletions spec/filters/elasticsearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,34 @@
context "registration" do

let(:plugin) { LogStash::Plugin.lookup("filter", "elasticsearch").new({}) }
before do
allow(plugin).to receive(:test_connection!)

context "against authentic Elasticsearch" do
before do
allow(plugin).to receive(:test_connection!)
end

it "should not raise an exception" do
expect {plugin.register}.to_not raise_error
end
end

it "should not raise an exception" do
expect {plugin.register}.to_not raise_error
context "against not authentic Elasticsearch" do
let(:failing_client) do
client = double("client")
allow(client).to receive(:ping).and_raise Elasticsearch::UnsupportedProductError

client_wrapper = double("filter_client")
allow(client_wrapper).to receive(:client).and_return client
client_wrapper
end

before do
allow(plugin).to receive(:get_client).and_return(failing_client)
end

it "should raise ConfigurationError" do
expect {plugin.register}.to raise_error(LogStash::ConfigurationError)
end
end
end

Expand Down

0 comments on commit 9fefde9

Please sign in to comment.