Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/logstash/outputs/elasticsearch/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def setup_after_successful_connection
sleep_interval = next_sleep_interval(sleep_interval)
end
if successful_connection?
discover_cluster_uuid
install_template
setup_ilm if ilm_in_use?
end
Expand Down Expand Up @@ -130,6 +131,14 @@ def install_template
@template_installed.make_true
end

def discover_cluster_uuid
return unless defined?(plugin_metadata)
cluster_info = client.get('/')
plugin_metadata.set(:cluster_uuid, cluster_info['cluster_uuid'])
rescue => e
# TODO introducing this logging message breaks many tests that need refactoring
end

def check_action_validity
raise LogStash::ConfigurationError, "No action specified!" unless @action

Expand Down
13 changes: 8 additions & 5 deletions spec/unit/outputs/elasticsearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,14 @@

context 'handling elasticsearch document-level status meant for the DLQ' do
let(:options) { { "manage_template" => false } }
let(:logger) { subject.instance_variable_get(:@logger) }

context 'when @dlq_writer is nil' do
before { subject.instance_variable_set '@dlq_writer', nil }

context 'resorting to previous behaviour of logging the error' do
context 'getting an invalid_index_name_exception' do
it 'should log at ERROR level' do
expect(logger).to receive(:error).with(/Could not index/, hash_including(:status, :action, :response))
subject.instance_variable_set(:@logger, double("logger").as_null_object)
mock_response = { 'index' => { 'error' => { 'type' => 'invalid_index_name_exception' } } }
subject.handle_dlq_status("Could not index event to Elasticsearch.",
[:action, :params, :event], :some_status, mock_response)
Expand All @@ -503,7 +502,9 @@

context 'when getting any other exception' do
it 'should log at WARN level' do
expect(logger).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response))
dlog = double_logger = double("logger").as_null_object
subject.instance_variable_set(:@logger, dlog)
expect(dlog).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response))
mock_response = { 'index' => { 'error' => { 'type' => 'illegal_argument_exception' } } }
subject.handle_dlq_status("Could not index event to Elasticsearch.",
[:action, :params, :event], :some_status, mock_response)
Expand All @@ -512,7 +513,9 @@

context 'when the response does not include [error]' do
it 'should not fail, but just log a warning' do
expect(logger).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response))
dlog = double_logger = double("logger").as_null_object
subject.instance_variable_set(:@logger, dlog)
expect(dlog).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response))
mock_response = { 'index' => {} }
expect do
subject.handle_dlq_status("Could not index event to Elasticsearch.",
Expand All @@ -532,7 +535,7 @@
# We should still log when sending to the DLQ.
# This shall be solved by another issue, however: logstash-output-elasticsearch#772
it 'should send the event to the DLQ instead, and not log' do
expect(dlq_writer).to receive(:write).with(:event, /Could not index/)
expect(dlq_writer).to receive(:write).once.with(:event, /Could not index/)
mock_response = { 'index' => { 'error' => { 'type' => 'illegal_argument_exception' } } }
subject.handle_dlq_status("Could not index event to Elasticsearch.",
[:action, :params, :event], :some_status, mock_response)
Expand Down