Skip to content

Commit 2c5860d

Browse files
author
Ian Driver
committed
Add send_keepalive_packet option to out_forward plugin
This adds the send_keepalive_packet configuration parameter to enable TCP keepalive (SO_KEEPALIVE) on forward output connections, similar to the implementation in in_forward (PR #2352). The existing 'keepalive' parameter only enables connection pooling, not TCP-level keepalive probes. Signed-off-by: Ian Driver <idriver@williamhill.us>
1 parent 1327bed commit 2c5860d

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

lib/fluent/plugin/out_forward.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class ForwardOutput < Output
119119
config_param :keepalive, :bool, default: false
120120
desc "Expired time of keepalive. Default value is nil, which means to keep connection as long as possible"
121121
config_param :keepalive_timeout, :time, default: nil
122+
desc 'Check the remote connection is still available by sending a keepalive packet if this value is true.'
123+
config_param :send_keepalive_packet, :bool, default: false
122124

123125
config_section :security, required: false, multi: false do
124126
desc 'The hostname'
@@ -414,6 +416,7 @@ def create_transfer_socket(host, port, hostname, &block)
414416
send_timeout: @send_timeout,
415417
recv_timeout: @ack_response_timeout,
416418
connect_timeout: @connect_timeout,
419+
send_keepalive_packet: @send_keepalive_packet,
417420
&block
418421
)
419422
when :tcp
@@ -423,6 +426,7 @@ def create_transfer_socket(host, port, hostname, &block)
423426
send_timeout: @send_timeout,
424427
recv_timeout: @ack_response_timeout,
425428
connect_timeout: @connect_timeout,
429+
send_keepalive_packet: @send_keepalive_packet,
426430
&block
427431
)
428432
else

test/plugin/test_out_forward.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ def try_write(chunk)
153153
end
154154
end
155155

156+
test 'send_keepalive_packet is disabled by default' do
157+
@d = d = create_driver(config)
158+
assert_false d.instance.send_keepalive_packet
159+
end
160+
161+
test 'send_keepalive_packet can be enabled' do
162+
@d = d = create_driver(config + "\nsend_keepalive_packet true")
163+
assert_true d.instance.send_keepalive_packet
164+
end
165+
156166
test 'configure with ignore_network_errors_at_startup' do
157167
normal_conf = config_element('match', '**', {}, [
158168
config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'})
@@ -1303,7 +1313,8 @@ def plugin_id_for_test?
13031313
linger_timeout: anything,
13041314
send_timeout: anything,
13051315
recv_timeout: anything,
1306-
connect_timeout: anything
1316+
connect_timeout: anything,
1317+
send_keepalive_packet: anything
13071318
) { |sock| mock(sock).close.once; sock }.twice
13081319

13091320
target_input_driver.run(timeout: 15) do
@@ -1343,7 +1354,8 @@ def plugin_id_for_test?
13431354
linger_timeout: anything,
13441355
send_timeout: anything,
13451356
recv_timeout: anything,
1346-
connect_timeout: anything
1357+
connect_timeout: anything,
1358+
send_keepalive_packet: anything
13471359
) { |sock| mock(sock).close.once; sock }.once
13481360

13491361
target_input_driver.run(timeout: 15) do
@@ -1380,7 +1392,8 @@ def plugin_id_for_test?
13801392
linger_timeout: anything,
13811393
send_timeout: anything,
13821394
recv_timeout: anything,
1383-
connect_timeout: anything) { |sock|
1395+
connect_timeout: anything,
1396+
send_keepalive_packet: anything) { |sock|
13841397
mock(sock).close.once; sock
13851398
}.twice
13861399

0 commit comments

Comments
 (0)