1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

Create an error event in the Flow exactly as a Buffer would

That way, we ensure that the error_flow receives an expected event and
doesn;t have to deal with different data formats which might result in
additional (then quietly hidden) errors.
This commit is contained in:
Holger Just 2017-08-24 18:58:33 +02:00
parent 96aaaa0348
commit 7b06d053ca
2 changed files with 28 additions and 12 deletions

View File

@ -235,15 +235,16 @@ module Rackstash
private private
def log_error(message, exception) def log_error(message, exception)
message = Rackstash::Message.new(message, severity: ERROR)
error_event = { error_event = {
FIELD_ERROR => exception.class.name, FIELD_ERROR => exception.class.name,
FIELD_ERROR_MESSAGE => exception.message, FIELD_ERROR_MESSAGE => exception.message,
FIELD_ERROR_TRACE => (exception.backtrace || []).join("\n"), FIELD_ERROR_TRACE => (exception.backtrace || []).join("\n"),
FIELD_TAGS => [], FIELD_TAGS => [],
FIELD_MESSAGE => message, FIELD_MESSAGE => [message],
FIELD_TIMESTAMP => Time.now.utc.iso8601(ISO8601_PRECISION).freeze, FIELD_TIMESTAMP => message.time
FIELD_VERSION => '1'.freeze
} }
error_flow.write!(error_event) error_flow.write!(error_event)
rescue rescue

View File

@ -83,10 +83,15 @@ describe Rackstash::Flow do
it 'rescues any exception thrown by the adapter' do it 'rescues any exception thrown by the adapter' do
error_flow = instance_double(described_class) error_flow = instance_double(described_class)
expect(error_flow).to receive(:write!) expect(error_flow).to receive(:write!)
.with hash_including( .with(
'message' => /^close failed for adapter/,
'error' => 'RuntimeError', 'error' => 'RuntimeError',
'error_message' => 'ERROR' 'error_message' => 'ERROR',
'error_trace' => instance_of(String),
'tags' => [],
'message' => [instance_of(Rackstash::Message)],
'@timestamp' => instance_of(Time)
) )
expect(flow).to receive(:error_flow).and_return(error_flow) expect(flow).to receive(:error_flow).and_return(error_flow)
@ -242,10 +247,15 @@ describe Rackstash::Flow do
it 'rescues any exception thrown by the adapter' do it 'rescues any exception thrown by the adapter' do
error_flow = instance_double(described_class) error_flow = instance_double(described_class)
expect(error_flow).to receive(:write!) expect(error_flow).to receive(:write!)
.with hash_including( .with(
'message' => /^reopen failed for adapter/,
'error' => 'RuntimeError', 'error' => 'RuntimeError',
'error_message' => 'ERROR' 'error_message' => 'ERROR',
'error_trace' => instance_of(String),
'tags' => [],
'message' => [instance_of(Rackstash::Message)],
'@timestamp' => instance_of(Time)
) )
expect(flow).to receive(:error_flow).and_return(error_flow) expect(flow).to receive(:error_flow).and_return(error_flow)
@ -306,10 +316,15 @@ describe Rackstash::Flow do
it 'rescues any exception thrown by the adapter' do it 'rescues any exception thrown by the adapter' do
error_flow = instance_double(described_class) error_flow = instance_double(described_class)
expect(error_flow).to receive(:write!) expect(error_flow).to receive(:write!)
.with hash_including( .with(
'message' => /^write failed for adapter/,
'error' => 'RuntimeError', 'error' => 'RuntimeError',
'error_message' => 'ERROR' 'error_message' => 'ERROR',
'error_trace' => instance_of(String),
'tags' => [],
'message' => [instance_of(Rackstash::Message)],
'@timestamp' => instance_of(Time)
) )
expect(flow).to receive(:error_flow).and_return(error_flow) expect(flow).to receive(:error_flow).and_return(error_flow)