mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Always add a @timestamp field in the logstash encoder, even if it was removed by a filter
This commit is contained in:
parent
7b06d053ca
commit
40aa74c5c0
@ -20,6 +20,8 @@ module Rackstash
|
||||
# @return [String] the event as a single-line JSON string
|
||||
def encode(event)
|
||||
event[FIELD_VERSION] = '1'.freeze if event[FIELD_VERSION].nil?
|
||||
event[FIELD_TIMESTAMP] ||= Time.now.utc.freeze
|
||||
|
||||
super(event)
|
||||
end
|
||||
end
|
||||
|
||||
@ -14,7 +14,8 @@ describe Rackstash::Encoders::Logstash do
|
||||
describe '#encode' do
|
||||
it 'formats the passed event hash as a JSON string and includes @version' do
|
||||
event = { 'hello' => 'world', 'message' => ["hello\n", "world"] }
|
||||
expect(encoder.encode(event)).to eql '{"hello":"world","message":"hello\nworld","@version":"1"}'
|
||||
expect(encoder.encode(event))
|
||||
.to match /\A\{"hello":"world","message":"hello\\nworld","@version":"1","@timestamp":"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}Z"\}\z/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user