Skip to content

Commit

Permalink
Merge pull request #1399 from fluent/ignore-network-error-at-startup-…
Browse files Browse the repository at this point in the history
…in-out_forward

add ignore_network_errors_at_startup
  • Loading branch information
tagomoris authored Jan 10, 2017
2 parents 46d31ef + d63e5e4 commit 2a53248
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lib/fluent/plugin/out_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class ConnectionClosedError < Error; end
desc 'Enable client-side DNS round robin.'
config_param :dns_round_robin, :bool, default: false # heartbeat_type 'udp' is not available for this

desc 'Ignore DNS resolution and errors at startup time.'
config_param :ignore_network_errors_at_startup, :bool, default: false

desc 'Compress buffered data.'
config_param :compress, :enum, list: [:text, :gzip], default: :text

Expand Down Expand Up @@ -148,7 +151,15 @@ def configure(conf)
if @heartbeat_type == :none
@nodes << NoneHeartbeatNode.new(self, server, failure: failure)
else
@nodes << Node.new(self, server, failure: failure)
node = Node.new(self, server, failure: failure)
begin
node.validate_host_resolution!
rescue => e
raise unless @ignore_network_errors_at_startup
log.warn "failed to resolve node name when configured", server: (server.name || server.host), error: e
node.disable!
end
@nodes << node
end
end

Expand Down Expand Up @@ -453,7 +464,7 @@ def initialize(sender, server, failure:)

@resolved_host = nil
@resolved_time = 0
resolved_host # check dns
@resolved_once = false
end

attr_accessor :usock
Expand All @@ -462,6 +473,10 @@ def initialize(sender, server, failure:)
attr_reader :sockaddr # used by on_heartbeat
attr_reader :failure, :available # for test

def validate_host_resolution!
resolved_host
end

def available?
@available
end
Expand Down Expand Up @@ -550,9 +565,20 @@ def send_data(tag, chunk)

# FORWARD_TCP_HEARTBEAT_DATA = FORWARD_HEADER + ''.to_msgpack + [].to_msgpack
def send_heartbeat
begin
dest_addr = resolved_host
@resolved_once = true
rescue ::SocketError => e
if !@resolved_once && @sender.ignore_network_errors_at_startup
@log.warn "failed to resolve node name in heartbeating", server: @name || @host, error: e
return
end
raise
end

case @sender.heartbeat_type
when :tcp
@sender.create_transfer_socket(resolved_host, port) do |sock|
@sender.create_transfer_socket(dest_addr, port) do |sock|
## don't send any data to not cause a compatibility problem
# sock.write FORWARD_TCP_HEARTBEAT_DATA

Expand Down
18 changes: 18 additions & 0 deletions test/plugin/test_out_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ def read_ack_from_sock(sock, unpacker)
end
end

test 'configure with ignore_network_errors_at_startup' do
normal_conf = config_element('match', '**', {}, [
config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'})
])
assert_raise SocketError do
create_driver(normal_conf)
end

conf = config_element('match', '**', {'ignore_network_errors_at_startup' => 'true'}, [
config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'})
])
@d = d = create_driver(conf)
expected_log = "failed to resolve node name when configured"
expected_detail = 'server="test" error_class=SocketError'
logs = d.logs
assert{ logs.any?{|log| log.include?(expected_log) && log.include?(expected_detail) } }
end

test 'compress_default_value' do
@d = d = create_driver
assert_equal :text, d.instance.compress
Expand Down

0 comments on commit 2a53248

Please sign in to comment.