Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify connection to Elasticsearch #150

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Expand Up @@ -2,12 +2,9 @@ import:
- logstash-plugins/.ci:travis/travis.yml@1.x

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
@@ -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
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
@@ -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
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