From 12b1ce1222c093f26a642b919e67bd6e2b117f1c Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Thu, 12 Nov 2026 22:20:13 -0300 Subject: [PATCH 1/3] Fix every chunk failing when the formatter has add_newline false 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 --- lib/fluent/plugin/out_remote_syslog.rb | 7 ++++- test/plugin/out_remote_syslog.rb | 36 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/out_remote_syslog.rb b/lib/fluent/plugin/out_remote_syslog.rb index 2f37255..74dc4d8 100644 --- a/lib/fluent/plugin/out_remote_syslog.rb +++ b/lib/fluent/plugin/out_remote_syslog.rb @@ -82,9 +82,14 @@ def close def format(tag, time, record) r = inject_values_to_record(tag, time, record) formatted = @formatter.format(tag, time, r) - return formatted unless @use_event_time return unless formatted + unless @use_event_time + # write reads the chunk back line by line, so every record must end + # with a newline, also with add_newline false in . + return formatted.end_with?("\n") ? formatted : formatted + "\n" + end + # Packed as binary, so the bytes are sent as they are, as with the # option off, and not converted or validated as UTF-8. [time.to_i, formatted.b].to_msgpack diff --git a/test/plugin/out_remote_syslog.rb b/test/plugin/out_remote_syslog.rb index e088912..c45a71f 100644 --- a/test/plugin/out_remote_syslog.rb +++ b/test/plugin/out_remote_syslog.rb @@ -227,6 +227,42 @@ def test_write_with_use_event_time_skips_nil_formatted_record assert_equal(["first".b, "last".b], messages) end + data("udp", "udp") + data("tcp", "tcp") + def test_write_with_add_newline_false(protocol) + out_driver = create_driver_out_syslog %[ + @type remote_syslog + hostname foo.com + host localhost + port 5566 + protocol #{protocol} + + + @type single_value + message_key message + add_newline false + + ] + + in_driver = create_driver_in_syslog %[ + @type syslog + tag tag + port 5566 + bind 127.0.0.1 + protocol_type #{protocol} + ] + + in_driver.run(expect_records: 2, timeout: 5) do + out_driver.run do + out_driver.feed("tag", Fluent::EventTime.now, {"message" => "first"}) + out_driver.feed("tag", Fluent::EventTime.now, {"message" => "second"}) + end + end + + assert_equal(["first", "second"], in_driver.events.map {|_tag, _time, record| record["message"] }) + assert_false(out_driver.logs.any? {|log| log.include?("error_class") }) + end + data("primary true, secondary omitted", ["use_event_time true", ""]) data("primary false, secondary true", ["", "use_event_time true"]) def test_configure_rejects_secondary_with_other_use_event_time(data) From edc74aea605d735b00b54bc57302cca083bdbf8b Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Fri, 13 Nov 2026 21:23:10 -0300 Subject: [PATCH 2/3] Check and add the newline as bytes 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 --- lib/fluent/plugin/out_remote_syslog.rb | 3 ++- test/plugin/out_remote_syslog.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/out_remote_syslog.rb b/lib/fluent/plugin/out_remote_syslog.rb index 74dc4d8..32f429a 100644 --- a/lib/fluent/plugin/out_remote_syslog.rb +++ b/lib/fluent/plugin/out_remote_syslog.rb @@ -87,7 +87,8 @@ def format(tag, time, record) unless @use_event_time # write reads the chunk back line by line, so every record must end # with a newline, also with add_newline false in . - return formatted.end_with?("\n") ? formatted : formatted + "\n" + return formatted if formatted.getbyte(-1) == "\n".ord + return formatted.b << "\n" end # Packed as binary, so the bytes are sent as they are, as with the diff --git a/test/plugin/out_remote_syslog.rb b/test/plugin/out_remote_syslog.rb index c45a71f..db65cba 100644 --- a/test/plugin/out_remote_syslog.rb +++ b/test/plugin/out_remote_syslog.rb @@ -263,6 +263,25 @@ def test_write_with_add_newline_false(protocol) assert_false(out_driver.logs.any? {|log| log.include?("error_class") }) end + data("ending with a newline", "日本語\n") + data("without a newline", "日本語") + def test_format_with_add_newline_false_and_iso_2022_jp(message) + d = create_driver_out_syslog %[ + @type remote_syslog + host localhost + + + @type single_value + message_key message + add_newline false + + ] + + record = {"message" => message.encode("ISO-2022-JP")} + formatted = d.instance.format("tag", Fluent::EventTime.now, record) + assert_equal("#{message.chomp}\n".encode("ISO-2022-JP").b, formatted.b) + end + data("primary true, secondary omitted", ["use_event_time true", ""]) data("primary false, secondary true", ["", "use_event_time true"]) def test_configure_rejects_secondary_with_other_use_event_time(data) From 8c3220a6d460e2b5d80ed88855942c4c101c4219 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Tue, 17 Nov 2026 19:53:28 -0300 Subject: [PATCH 3/3] Keep an empty message empty with add_newline false Signed-off-by: Lucas Barros --- lib/fluent/plugin/out_remote_syslog.rb | 2 +- test/plugin/out_remote_syslog.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/out_remote_syslog.rb b/lib/fluent/plugin/out_remote_syslog.rb index 32f429a..77b9b90 100644 --- a/lib/fluent/plugin/out_remote_syslog.rb +++ b/lib/fluent/plugin/out_remote_syslog.rb @@ -87,7 +87,7 @@ def format(tag, time, record) unless @use_event_time # write reads the chunk back line by line, so every record must end # with a newline, also with add_newline false in . - return formatted if formatted.getbyte(-1) == "\n".ord + return formatted if formatted.empty? || formatted.getbyte(-1) == "\n".ord return formatted.b << "\n" end diff --git a/test/plugin/out_remote_syslog.rb b/test/plugin/out_remote_syslog.rb index db65cba..c03ebfe 100644 --- a/test/plugin/out_remote_syslog.rb +++ b/test/plugin/out_remote_syslog.rb @@ -282,6 +282,21 @@ def test_format_with_add_newline_false_and_iso_2022_jp(message) assert_equal("#{message.chomp}\n".encode("ISO-2022-JP").b, formatted.b) end + def test_format_with_add_newline_false_keeps_empty_message_empty + d = create_driver_out_syslog %[ + @type remote_syslog + host localhost + + + @type single_value + message_key message + add_newline false + + ] + + assert_equal("", d.instance.format("tag", Fluent::EventTime.now, {"message" => ""})) + end + data("primary true, secondary omitted", ["use_event_time true", ""]) data("primary false, secondary true", ["", "use_event_time true"]) def test_configure_rejects_secondary_with_other_use_event_time(data)