Skip to content

Use port when host_with_port has no port - #93

Merged
Watson1978 merged 3 commits into
fluent-plugins-nursery:masterfrom
lbarrosby:host-with-port-default-port
Nov 24, 2026
Merged

Watson1978 merged 3 commits into
fluent-plugins-nursery:masterfrom
lbarrosby:host-with-port-default-port

Conversation

@lbarrosby

@lbarrosby lbarrosby commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #92.

host_with_port had two gaps when the value has no :<port> part:

  • host_with_port example.com split into ["example.com"], so the port was nil. The sender was created for example.com: and every flush failed (TCP: getaddrinfo ... nodename nor servname provided, UDP: send without a port).
  • A bracketed IPv6 address without a port, "[::1]", went through rpartition(":") and became host [: and port 1].

split_host_with_port now reads a bracketed host up to ] and takes the port from what follows ([2001:db8::1]:514:extra gives port 514, like the IPv4 127.0.0.1:514:extra case already did). When no port is given, it falls back to the port parameter (default 514), the same value host + port would use. An explicit port in host:port or [IPv6]:port is still used as given. A value that starts with [ but has no ] is kept as the host, as on master, so a flush fails with a name resolution error. README row updated.

Tests:

  • test_split_host_with_port: new cases example.com, example.com:, [::1], [2001:db8::1]: (all get port), [2001:db8::1]:514:extra, example.com::6514 (the port stays "") and [2001:db8::1:6514 (no closing bracket: the whole value is the host, and the port is port).
  • test_write_tcp_with_host_with_port: new cases 127.0.0.1 and "[::1]" with port 5567, sending over TCP to in_syslog.
  • On master, 8 of the 9 new cases fail. example.com::6514 already passes there, and the two write cases never deliver the record. With this change bundle exec rake test passes: 32 tests, 74 assertions, 0 failures (with IPv6 loopback available).

host_with_port without ":<port>" left the port nil, so the sender was
created for "host:" and every flush failed. A bracketed IPv6 address
without a port, such as "[::1]", was also split at its last colon and
became host "[:" and port "1]".

Read the address up to the closing bracket, and fall back to the port
parameter when no port is given.

Signed-off-by: Lucas Barros <lucasbarros@devops.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up. Falling back to port when the value has no port is a good change, and reading the bracketed host up to ] fixes "[::1]".

I have two requests inline, and I would like them fixed before merging:

  • Use port only when the parsed port is nil, not when it is an empty string.
  • Keep the code loadable on older Ruby, as the README lists Ruby 2.1 or later.

Separately, an empty value after placeholder expansion (for example host_with_port "${dest}" with no dest in the record) can now be sent to localhost, using the port value (514 by default). host "${dest}" already does the same on master, so we will handle that separately. No change to empty-host handling is needed in this PR.

Comment thread lib/fluent/plugin/out_remote_syslog.rb Resolved
Comment thread lib/fluent/plugin/out_remote_syslog.rb Resolved
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Both requests from the previous review are addressed:

  • example.com::6514 keeps port "", and the new test covers it.
  • The code no longer needs Ruby 2.5 or 2.6. The plugin and the test file pass ruby -c on Ruby 2.2. split_host_with_port also gives the same results on Ruby 2.2 and 3.4 for the test values.

I have one more request inline, for a value with a missing ]. I should have caught it in the first review. Sorry for the extra round.

Comment thread lib/fluent/plugin/out_remote_syslog.rb Resolved
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. With a missing ], the whole value is now kept as the host. A flush with such a value fails with a getaddrinfo error, as on master. The new test checks the host and port for this case.

I also checked this change merged with the current master (3120f44), which now has #94 and #95. bundle exec rake test passes there with IPv6 loopback enabled. A value without a port also works together with use_event_time and add_newline false.

Looks good to me. Thank you for working through the review rounds.

@Watson1978
Watson1978 merged commit 1bea4d7 into fluent-plugins-nursery:master Nov 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants