Repository navigation
Conversation
Fixes fluent-plugins-nursery#96 Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thank you for the fix. With it, the messages no longer go to the local host in the four cases from #96.
I found two problems in how the new error behaves. Please see the inline comments.
- The plain
raisemakes Fluentd retry a chunk that can never succeed. The chunk goes back to the front of this output's queue, and the chunks for valid destinations wait behind it until the retries end. With a memory buffer, they are lost when the retry limit is reached. - The check also fires when the host is empty in the configuration, without a placeholder. The PR description says that these configurations are not affected.
| # A placeholder can expand to an empty string when the chunk has no | ||
| # value for its key. Raise, so that the chunk is retried or goes to | ||
| # <secondary>, instead of sending it to the local host. | ||
| if host.nil? || host.empty? | ||
| raise "host is empty after placeholders are replaced: host=#{@host.inspect} host_with_port=#{@host_with_port.inspect}" |
There was a problem hiding this comment.
MUST: A plain raise makes Fluentd retry this chunk. The chunk metadata never changes, so every retry fails in the same way. The failed chunk goes back to the front of this output's queue, and the chunks for valid destinations wait behind it. On master, those valid records are delivered.
I reproduced this with host "${dest}", <buffer dest>, protocol udp, and records that alternate between with and without dest. With the default retry settings (retry_timeout 72h), in 30 seconds:
- master: all 30 records with
destarrived. - this PR: 1 record with
destarrived. The same chunk failed again and again (retry_times0 to 4). - with
Fluent::UnrecoverableError: all 30 records withdestarrived. Each chunk withoutdestwent to the backup directory.
The valid records were also blocked or lost in these cases:
- When the retry limit is reached, Fluentd clears the queue of this output. With a memory buffer, the valid chunks in it are lost.
- With
retry_forever true, Fluentd does not move the chunk to<secondary>, so the delivery stops until a restart. - At shutdown, Fluentd stops flushing after the failed chunk. With a memory buffer, the valid chunks after it are lost.
- With a file buffer, a chunk without
destthat is restored at restart blocks the new records.
Could you raise Fluent::UnrecoverableError instead? Fluentd then skips the retries. It moves the chunk to a synchronous <secondary>, such as secondary_file, right away. Without <secondary>, it moves the chunk to the backup directory. Fluentd 1.20.1 itself raises this error in extract_placeholders for invalid path components in placeholder values.
There is one trade-off. For this error, Fluentd skips a <secondary> of the same type (remote_syslog) and backs up the chunk locally instead. With this PR, such a secondary receives the chunk after the retry threshold (80% of retry_timeout by default). So a fixed-host remote_syslog secondary no longer works as a fallback server for these chunks. The valid chunks keep flowing, and the chunks without dest stay in the local backup.
The test then needs assert_raise(Fluent::UnrecoverableError).
| # A placeholder can expand to an empty string when the chunk has no | |
| # value for its key. Raise, so that the chunk is retried or goes to | |
| # <secondary>, instead of sending it to the local host. | |
| if host.nil? || host.empty? | |
| raise "host is empty after placeholders are replaced: host=#{@host.inspect} host_with_port=#{@host_with_port.inspect}" | |
| # A placeholder can expand to an empty string when the chunk has no | |
| # value for its key. Retrying cannot fix such a chunk, so raise an | |
| # unrecoverable error to move it to <secondary> or the backup at once. | |
| if host.nil? || host.empty? | |
| raise Fluent::UnrecoverableError, "host is empty after placeholders are replaced: host=#{@host.inspect} host_with_port=#{@host_with_port.inspect}" |
There was a problem hiding this comment.
Thanks for measuring all of these. Switched to Fluent::UnrecoverableError in 0362839, and the test asserts it. I agree with the trade-off: keeping the valid chunks flowing matters more than a same-type secondary as a fallback for chunks that can never be sent.
| # A placeholder can expand to an empty string when the chunk has no | ||
| # value for its key. Raise, so that the chunk is retried or goes to | ||
| # <secondary>, instead of sending it to the local host. | ||
| if host.nil? || host.empty? |
There was a problem hiding this comment.
MUST: This check also fires when the host is empty in the configuration, without a placeholder. For example, host "" with port 514, or host_with_port ":514". host "#{ENV['SYSLOG_HOST']}" with the variable unset also gives host "". On master, these send to the local host. With this PR, every non-empty chunk fails to flush. The PR description says that configurations without placeholders are not affected.
Please keep the delivery for host "" with a port and for host_with_port ":514", and add a test for each. Use a different port in each test, because senders are cached per thread by host:port. The check should raise only when the expansion made the host empty. With host_with_port, use its host part to decide. One way is to keep the host part of the configured value in configure:
# in configure
@configured_host = (@host_with_port ? split_host_with_port(@host_with_port).first : @host).to_s
# in write
if host.to_s.empty? && !@configured_host.empty?I tried this with tests that write a chunk and receive the message on 127.0.0.1. They pass, and the tests for ${dest} still raise.
There was a problem hiding this comment.
You are right, the description was wrong about that. In 0362839 configure keeps the host part of the configured value (the host part of host_with_port when it is set), and write raises only when the expanded host is empty and the configured one is not. New test_write_with_empty_configured_host_sends_to_local_host covers host "" with port 5571 and host_with_port ":5572", each writing a chunk and receiving it on 127.0.0.1. Both fail on c288ad8. I used TCP there, because on macOS a UDP send to "" fails with EHOSTUNREACH, while TCP connects to the local host on both Linux and macOS.
| data("host udp", {target: %[host "${dest}"\nport 5568], protocol: "udp"}) | ||
| data("host tcp", {target: %[host "${dest}"\nport 5568], protocol: "tcp"}) | ||
| data("host_with_port udp", {target: %[host_with_port "${dest}:5568"], protocol: "udp"}) | ||
| data("host_with_port tcp", {target: %[host_with_port "${dest}:5568"], protocol: "tcp"}) |
There was a problem hiding this comment.
NIT: host_with_port "${dest}" (without a port) reaches the host.nil? side of the check, because "".split(":") returns []. None of the four cases covers it. Could you add it?
| data("host_with_port tcp", {target: %[host_with_port "${dest}:5568"], protocol: "tcp"}) | |
| data("host_with_port tcp", {target: %[host_with_port "${dest}:5568"], protocol: "tcp"}) | |
| data("host_with_port without port", {target: %[host_with_port "${dest}"], protocol: "udp"}) |
There was a problem hiding this comment.
Added the host_with_port without port case in 0362839. bundle exec rake test: 47 tests, 0 failures.
A plain raise made Fluentd retry a chunk that can never succeed, and the chunks for valid destinations waited behind it. Raise Fluent::UnrecoverableError, so the chunk goes to <secondary> or the backup at once. Keep sending to the local host when the host is empty in the configuration, as on master (host "" with a port, host_with_port ":514"). Only an empty host after the placeholders are replaced is an error. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thank you for the update. 0362839 addresses all three points from my previous review.
- When a placeholder makes the host empty,
writenow raisesFluent::UnrecoverableError, so Fluentd 1.20.1 does not retry the chunk. I reran the earlier scenarios: mixed records, the flush at shutdown,retry_foreverwithsecondary_file,copy, and a restart with a file buffer. In each one, the records for valid destinations were delivered. - A host that is empty in the configuration behaves as before this PR. I checked
host "",host_with_port "",host_with_port ":514", andhost_with_port "[]:514"on this branch, and again after merging it into the current master, which includes #93. - The test now covers
host_with_port "${dest}".
There is one new problem. The test for an empty host in the configuration fails on all the Windows jobs. CI has to pass before this can be merged, so please see the inline comment.
|
|
||
| data("host with a port", {target: %[host ""\nport 5571], port: 5571}) | ||
| data("host_with_port", {target: %[host_with_port ":5572"], port: 5572}) | ||
| def test_write_with_empty_configured_host_sends_to_local_host(data) |
There was a problem hiding this comment.
MUST: This test fails on the windows-latest runner for all four Ruby versions: https://github.com/fluent-plugins-nursery/fluent-plugin-remote_syslog/actions/runs/45503271604/job/138967985435. TCPSocket.new raises Errno::EADDRNOTAVAIL for connect(2) for "" port 5571. Ruby resolves the empty host to 0.0.0.0, and Winsock does not connect to that address, so the message never reaches the listener. The plugin still passes the same empty host to the sender as on master, so only the delivery check depends on the platform. Could you skip this test on Windows? I asked for this test in my previous review and missed the platform difference.
| def test_write_with_empty_configured_host_sends_to_local_host(data) | |
| def test_write_with_empty_configured_host_sends_to_local_host(data) | |
| omit_if(Fluent.windows?, "Windows cannot connect to 0.0.0.0") |
Fixes #96
When
hostorhost_with_porthas a placeholder such as${dest}and the chunk has no value for the key, the placeholder expands to an empty string.writepassed that empty host to the sender, which sent the messages to the local host without any error, so the chunk was never retried and never reached<secondary>.writenow raises when the host is empty (or missing) after the placeholders are replaced, before a sender is created, so the usual retry and<secondary>handling applies. The check only runs on the expanded value, so configurations without placeholders are not affected.This does not touch
split_host_with_port, so it is independent of #93.Test:
test_write_raises_on_empty_host, withhost "${dest}"andhost_with_port "${dest}:5568"over udp and tcp, writes a chunk whose metadata has nodest. On masterwritegoes on to open a socket to""(here it then fails withEHOSTUNREACH/ECONNREFUSEDonly because nothing listens on 5568; with a listener the message is delivered, as in the issue). With the change all 4 cases raise the new error.