Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid zero division error when there are no available nodes #2482

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/fluent/plugin/out_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ def rebuild_weight_array
end

weight_array = []
if regular_nodes.empty?
log.warn('No nodes are available')
@weight_array = weight_array
return @weight_array
end

gcd = regular_nodes.map {|n| n.weight }.inject(0) {|r,w| r.gcd(w) }
regular_nodes.each {|n|
(n.weight / gcd).times {
Expand Down
14 changes: 14 additions & 0 deletions test/plugin/test_out_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,20 @@ def create_target_input_driver(response_stub: nil, disconnect: false, conf: TARG
end
end

test 'if no available node' do
# do not create output driver
d = create_driver(%[
<server>
name test
standby
host #{TARGET_HOST}
port #{TARGET_PORT}
</server>
])
d.instance_start
assert_nothing_raised { d.run }
end

sub_test_case 'keepalive' do
test 'Do not create connection per send_data' do
target_input_driver = create_target_input_driver(conf: TARGET_CONFIG)
Expand Down