Repository navigation
Use port when host_with_port has no port - #93
Watson1978 merged 3 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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
portonly when the parsed port isnil, 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.
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for the update. Both requests from the previous review are addressed:
example.com::6514keeps 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 -con Ruby 2.2.split_host_with_portalso 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.
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
left a comment
There was a problem hiding this comment.
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.
Follow-up to #92.
host_with_porthad two gaps when the value has no:<port>part:host_with_port example.comsplit into["example.com"], so the port wasnil. The sender was created forexample.com:and every flush failed (TCP:getaddrinfo ... nodename nor servname provided, UDP: send without a port)."[::1]", went throughrpartition(":")and became host[:and port1].split_host_with_portnow reads a bracketed host up to]and takes the port from what follows ([2001:db8::1]:514:extragives port514, like the IPv4127.0.0.1:514:extracase already did). When no port is given, it falls back to theportparameter (default 514), the same valuehost+portwould use. An explicit port inhost:portor[IPv6]:portis 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 casesexample.com,example.com:,[::1],[2001:db8::1]:(all getport),[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 isport).test_write_tcp_with_host_with_port: new cases127.0.0.1and"[::1]"withport 5567, sending over TCP toin_syslog.example.com::6514already passes there, and the two write cases never deliver the record. With this changebundle exec rake testpasses: 32 tests, 74 assertions, 0 failures (with IPv6 loopback available).