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

Resolving the remote host name to IP only once at startup time. #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion lib/fluent/plugin/out_remote_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def initialize
@loggers = {}
end

def start
super
require 'resolv'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@host_ip = Resolv.getaddress(@host)
end

def shutdown
super
@loggers.values.each(&:close)
Expand All @@ -41,7 +47,7 @@ def emit(tag, es, chain)
end

tag = rewrite_tag!(tag.dup)
@loggers[tag] ||= RemoteSyslogLogger::UdpSender.new(@host,
@loggers[tag] ||= RemoteSyslogLogger::UdpSender.new(@host_ip,
@port,
facility: @facility,
severity: @severity,
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/out_remote_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_configure
d = create_driver %[
type remote_syslog
hostname foo.com
host example.com
host localhost
port 5566
severity debug
tag minitest
Expand All @@ -29,7 +29,7 @@ def test_configure

logger = loggers.values.first

assert_equal "example.com", logger.instance_variable_get(:@remote_hostname)
assert_equal "127.0.0.1", logger.instance_variable_get(:@remote_hostname)
assert_equal 5566, logger.instance_variable_get(:@remote_port)

p = logger.instance_variable_get(:@packet)
Expand Down