Add log-tag to haproxy config file

By adding a log-tag line to the haproxy config file that contains
the network or router id, we will be able to differentiate which
proxy is logging what.  This should help with debugging.

Change-Id: I5bb57b7682c00645e20cce69847dbb3b72165aa8
Partial-bug: #1744359
This commit is contained in:
Brian Haley 2018-01-19 15:53:38 -05:00
parent 93f7c7707b
commit 703ff85b82
2 changed files with 15 additions and 4 deletions

View File

@ -39,6 +39,7 @@ PROXY_CONFIG_DIR = "ns-metadata-proxy"
_HAPROXY_CONFIG_TEMPLATE = """
global
log /dev/log local0 %(log_level)s
log-tag %(log_tag)s
user %(user)s
group %(group)s
maxconn 1024
@ -86,6 +87,12 @@ class HaproxyConfigurator(object):
self.pidfile = pid_file
self.log_level = (
'debug' if logging.is_debug_enabled(cfg.CONF) else 'info')
# log-tag will cause entries to have the string pre-pended, so use
# the uuid haproxy will be started with. Additionally, if it
# starts with "haproxy" then things will get logged to
# /var/log/haproxy.log on Debian distros, instead of to syslog.
uuid = network_id or router_id
self.log_tag = "haproxy-" + METADATA_SERVICE_NAME + "-" + uuid
def create_config_file(self):
"""Create the config file for haproxy."""
@ -114,7 +121,8 @@ class HaproxyConfigurator(object):
'user': username,
'group': groupname,
'pidfile': self.pidfile,
'log_level': self.log_level
'log_level': self.log_level,
'log_tag': self.log_tag
}
if self.network_id:
cfg_info['res_type'] = 'Network'

View File

@ -161,6 +161,8 @@ class TestMetadataDriverProcess(base.BaseTestCase):
'haproxy',
'-f', cfg_file]
log_tag = ("haproxy-" + metadata_driver.METADATA_SERVICE_NAME +
"-" + router_id)
cfg_contents = metadata_driver._HAPROXY_CONFIG_TEMPLATE % {
'user': self.EUNAME,
'group': self.EGNAME,
@ -169,7 +171,8 @@ class TestMetadataDriverProcess(base.BaseTestCase):
'res_type': 'Router',
'res_id': router_id,
'pidfile': self.PIDFILE,
'log_level': 'debug'}
'log_level': 'debug',
'log_tag': log_tag}
mock_open.assert_has_calls([
mock.call(cfg_file, 'w'),
@ -184,7 +187,7 @@ class TestMetadataDriverProcess(base.BaseTestCase):
def test_create_config_file_wrong_user(self):
with mock.patch('pwd.getpwnam', side_effect=KeyError):
config = metadata_driver.HaproxyConfigurator(mock.ANY, mock.ANY,
config = metadata_driver.HaproxyConfigurator(_uuid(), mock.ANY,
mock.ANY, mock.ANY,
self.EUNAME,
self.EGNAME,
@ -196,7 +199,7 @@ class TestMetadataDriverProcess(base.BaseTestCase):
with mock.patch('grp.getgrnam', side_effect=KeyError),\
mock.patch('pwd.getpwnam',
return_value=test_utils.FakeUser(self.EUNAME)):
config = metadata_driver.HaproxyConfigurator(mock.ANY, mock.ANY,
config = metadata_driver.HaproxyConfigurator(_uuid(), mock.ANY,
mock.ANY, mock.ANY,
self.EUNAME,
self.EGNAME,