Skip to content

Commit

Permalink
in_tcp: Add send_keepalive_packet option
Browse files Browse the repository at this point in the history
This adds a new option "send_keepalive_packet" which enables
SO_KEEPALIVE on underlying sockets.

This is especially useful for connecting to Fluentd over network
boundary (i.e. to prevent firewalls from closing connections).

Signed-off-by: I326463 <[email protected]>
Signed-off-by: Fujimoto Seiji <[email protected]>
  • Loading branch information
DimitarKiryakovSAP authored and Fujimoto Seiji committed Nov 22, 2022
1 parent e89092c commit 66c4a8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/fluent/plugin/in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TcpInput < Input

desc 'The payload is read up to this character.'
config_param :delimiter, :string, default: "\n" # syslog family add "\n" to each message and this seems only way to split messages in tcp stream
desc 'Check the remote connection is still available by sending a keepalive packet if this value is true.'
config_param :send_keepalive_packet, :bool, default: false

# in_forward like host/network restriction
config_section :security, required: false, multi: false do
Expand Down Expand Up @@ -101,7 +103,7 @@ def start
log.info "listening tcp socket", bind: @bind, port: @port
del_size = @delimiter.length
if @_extract_enabled && @_extract_tag_key
server_create(:in_tcp_server_single_emit, @port, bind: @bind, resolve_name: !!@source_hostname_key) do |data, conn|
server_create(:in_tcp_server_single_emit, @port, bind: @bind, resolve_name: !!@source_hostname_key, send_keepalive_packet: @send_keepalive_packet) do |data, conn|
unless check_client(conn)
conn.close
next
Expand Down Expand Up @@ -131,7 +133,7 @@ def start
buf.slice!(0, pos) if pos > 0
end
else
server_create(:in_tcp_server_batch_emit, @port, bind: @bind, resolve_name: !!@source_hostname_key) do |data, conn|
server_create(:in_tcp_server_batch_emit, @port, bind: @bind, resolve_name: !!@source_hostname_key, send_keepalive_packet: @send_keepalive_packet) do |data, conn|
unless check_client(conn)
conn.close
next
Expand Down
13 changes: 13 additions & 0 deletions test/plugin/test_in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ def create_tcp_socket(host, port, &block)
assert_equal hostname, event[2]['host']
end

test "send_keepalive_packet_can_be_enabled" do
d = create_driver(base_config + %!
format none
send_keepalive_packet true
!)
assert_true d.instance.send_keepalive_packet

d = create_driver(base_config + %!
format none
!)
assert_false d.instance.send_keepalive_packet
end

test 'source_address_key' do
d = create_driver(base_config + %!
format none
Expand Down

0 comments on commit 66c4a8b

Please sign in to comment.