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:
parent
96aaaa0348
commit
7b06d053ca
@ -235,15 +235,16 @@ module Rackstash
|
||||
private
|
||||
|
||||
def log_error(message, exception)
|
||||
message = Rackstash::Message.new(message, severity: ERROR)
|
||||
|
||||
error_event = {
|
||||
FIELD_ERROR => exception.class.name,
|
||||
FIELD_ERROR_MESSAGE => exception.message,
|
||||
FIELD_ERROR_TRACE => (exception.backtrace || []).join("\n"),
|
||||
|
||||
FIELD_TAGS => [],
|
||||
FIELD_MESSAGE => message,
|
||||
FIELD_TIMESTAMP => Time.now.utc.iso8601(ISO8601_PRECISION).freeze,
|
||||
FIELD_VERSION => '1'.freeze
|
||||
FIELD_MESSAGE => [message],
|
||||
FIELD_TIMESTAMP => message.time
|
||||
}
|
||||
error_flow.write!(error_event)
|
||||
rescue
|
||||
|
||||
@ -83,10 +83,15 @@ describe Rackstash::Flow do
|
||||
it 'rescues any exception thrown by the adapter' do
|
||||
error_flow = instance_double(described_class)
|
||||
expect(error_flow).to receive(:write!)
|
||||
.with hash_including(
|
||||
'message' => /^close failed for adapter/,
|
||||
.with(
|
||||
'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)
|
||||
|
||||
@ -242,10 +247,15 @@ describe Rackstash::Flow do
|
||||
it 'rescues any exception thrown by the adapter' do
|
||||
error_flow = instance_double(described_class)
|
||||
expect(error_flow).to receive(:write!)
|
||||
.with hash_including(
|
||||
'message' => /^reopen failed for adapter/,
|
||||
.with(
|
||||
'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)
|
||||
|
||||
@ -306,10 +316,15 @@ describe Rackstash::Flow do
|
||||
it 'rescues any exception thrown by the adapter' do
|
||||
error_flow = instance_double(described_class)
|
||||
expect(error_flow).to receive(:write!)
|
||||
.with hash_including(
|
||||
'message' => /^write failed for adapter/,
|
||||
.with(
|
||||
'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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user