Repository navigation
Fix sending records when the formatter has add_newline false - #95
Conversation
write reads the chunk back with io.each_line and calls chomp! on each line. With add_newline false the records are stored without a newline, so the chunk is a single line without one, chomp! returns nil and transmit raises "undefined method 'split' for nil". Fluentd treats NoMethodError as unrecoverable, so every chunk went to the backup directory and no message was sent. End each formatted record with a newline when the formatter did not add one. use_event_time keeps the records apart with msgpack and is not affected. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for fixing this. I checked the change with single_value, json and ltsv, newline crlf, empty messages, invalid UTF-8 and use_event_time true. With add_newline false, the records of a chunk are no longer joined, and the chunk no longer fails. In these cases with add_newline true, the chunk bytes are the same as on master.
I found one input that works on master and fails with this change. Please see the inline comment.
end_with?("\n") raises Encoding::CompatibilityError for a string in an
encoding that is not ASCII compatible, such as ISO-2022-JP. The chunk is
written as bytes, so a binary string is fine here.
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
|
Thanks for catching the ISO-2022-JP case. Pushed edc74ae:
Both new cases raise |
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the update. 8c3220a keeps an empty message empty, and the new test covers it.
I also ran this version with real Fluentd, single_value and add_newline false, with the messages "first", "", "third\n" and "fourth". I tried file and memory buffers with compress gzip, <buffer tag,time>, flush_mode immediate, and copy with out_file. In each case, the receiver got first, third and fourth, in this order, as with add_newline true on master. Thanks for fixing this!
3120f44
into
fluent-plugins-nursery:master
With
add_newline falsein<format>(a common choice withsingle_value, since a syslog message has no trailing newline anyway), a chunk fails when its last record does not end with a line ending, and the records in a chunk are glued together:Without
use_event_time,#formatstores the formatter output as is and#writereads the chunk back withio.each_lineandmsg.chomp!. Without newlines the whole chunk is one line with no"\n"at the end,chomp!returnsnil, andtransmit(nil)fails. Fluentd treatsNoMethodErroras unrecoverable, so the chunk goes straight to the<secondary>, or to the backup directory when there is none. Even if it did not fail, the records of a chunk would be glued into a single message.#formatnow appends"\n"when the formatted record does not end with one, so#writeno longer glues records together whateveradd_newlinesays. Empty output is kept empty, and the newline check and append operate on bytes, so ISO-2022-JP output is kept as is. Records that already end with a newline are stored exactly as before.use_event_timekeeps records apart with msgpack and is unchanged (it useschomp, notchomp!).Tests:
test_write_with_add_newline_false(UDP and TCP, samein_syslogsetup astest_write_udp/test_write_tcp): two records withsingle_valueandadd_newline false. On masterin_syslogreceives nothing and the log has theNoMethodErrorabove; with the change it receivesfirstandsecondas two messages.test_format_with_add_newline_false_and_iso_2022_jp: ISO-2022-JP output ends with exactly one newline, whether or not the message ends with one.test_format_with_add_newline_false_keeps_empty_message_empty: an empty message stays empty.bundle exec rake test: 40 tests, 0 failures.