1
0
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:
Holger Just 2017-08-24 19:01:35 +02:00
parent 7b06d053ca
commit 40aa74c5c0
2 changed files with 4 additions and 1 deletions

View File

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

View File

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