Skip to content

Commit

Permalink
add ignore_network_errors_at_startup
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Jan 4, 2017
1 parent b99df50 commit 9cfcf92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 15 additions & 2 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,14 @@ 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
end
@nodes << node
end
end

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

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

attr_accessor :usock
Expand All @@ -462,6 +471,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
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.new("getaddrinfo: nodename nor servname provided, or not known") 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 error="getaddrinfo: nodename nor servname provided, or not known"'
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 9cfcf92

Please sign in to comment.