Merge "Fix TCP listener logging bug"

This commit is contained in:
Zuul 2019-06-17 10:48:29 +00:00 committed by Gerrit Code Review
commit 6e6f3a1f1c
3 changed files with 24 additions and 8 deletions

View File

@ -660,3 +660,6 @@ SUPPORTED_CLIENT_AUTH_MODES = [CLIENT_AUTH_NONE, CLIENT_AUTH_OPTIONAL,
CLIENT_AUTH_MANDATORY]
TOPIC_AMPHORA_V2 = 'octavia_provisioning_v2'
HAPROXY_HTTP_PROTOCOLS = [lib_consts.PROTOCOL_HTTP,
lib_consts.PROTOCOL_TERMINATED_HTTPS]

View File

@ -123,10 +123,22 @@ class JinjaTemplater(object):
JINJA_ENV.filters['hash_amp_id'] = octavia_utils.base64_sha1_string
return JINJA_ENV.get_template(os.path.basename(self.haproxy_template))
def _format_log_string(self, load_balancer):
def _format_log_string(self, load_balancer, protocol):
log_format = CONF.haproxy_amphora.user_log_format.replace(
'{project_id}', load_balancer.project_id)
log_format = log_format.replace('{lb_id}', load_balancer.id)
# Order of these filters matter.
# TODO(johnsom) Remove when HAProxy handles the format string
# with HTTP variables in TCP listeners.
# Currently it either throws an error or just fails
# to log the message.
if protocol not in constants.HAPROXY_HTTP_PROTOCOLS:
log_format = log_format.replace('%{+Q}r', '-')
log_format = log_format.replace('%r', '-')
log_format = log_format.replace('%{+Q}ST', '-')
log_format = log_format.replace('%ST', '-')
log_format = log_format.replace(' ', '\ ')
return log_format
@ -234,7 +246,8 @@ class JinjaTemplater(object):
'topology': listener.load_balancer.topology,
'amphorae': listener.load_balancer.amphorae,
'enabled': listener.enabled,
'user_log_format': self._format_log_string(loadbalancer),
'user_log_format': self._format_log_string(loadbalancer,
listener.protocol),
'timeout_client_data': (
listener.timeout_client_data or
CONF.haproxy_amphora.timeout_client_data),

View File

@ -298,7 +298,7 @@ class TestHaproxyCfg(base.TestCase):
def test_render_template_https_real_monitor(self):
fe = ("frontend sample_listener_id_1\n"
" log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ "
"%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ "
"%ci\\ %cp\\ %t\\ -\\ -\\ %B\\ %U\\ "
"%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ "
"%tsc\n"
" maxconn {maxconn}\n"
@ -334,7 +334,7 @@ class TestHaproxyCfg(base.TestCase):
def test_render_template_https_hello_monitor(self):
fe = ("frontend sample_listener_id_1\n"
" log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ "
"%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ "
"%ci\\ %cp\\ %t\\ -\\ -\\ %B\\ %U\\ "
"%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ "
"%tsc\n"
" maxconn {maxconn}\n"
@ -439,7 +439,7 @@ class TestHaproxyCfg(base.TestCase):
def test_render_template_no_monitor_https(self):
fe = ("frontend sample_listener_id_1\n"
" log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ "
"%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ "
"%ci\\ %cp\\ %t\\ -\\ -\\ %B\\ %U\\ "
"%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ "
"%tsc\n"
" maxconn {maxconn}\n"
@ -498,7 +498,7 @@ class TestHaproxyCfg(base.TestCase):
def test_render_template_no_persistence_https(self):
fe = ("frontend sample_listener_id_1\n"
" log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ "
"%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ "
"%ci\\ %cp\\ %t\\ -\\ -\\ %B\\ %U\\ "
"%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ "
"%tsc\n"
" maxconn {maxconn}\n"
@ -599,7 +599,7 @@ class TestHaproxyCfg(base.TestCase):
def test_render_template_unlimited_connections(self):
fe = ("frontend sample_listener_id_1\n"
" log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ "
"%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ "
"%ci\\ %cp\\ %t\\ -\\ -\\ %B\\ %U\\ "
"%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ "
"%tsc\n"
" maxconn {maxconn}\n"
@ -630,7 +630,7 @@ class TestHaproxyCfg(base.TestCase):
def test_render_template_limited_connections(self):
fe = ("frontend sample_listener_id_1\n"
" log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ "
"%ci\\ %cp\\ %t\\ %{+Q}r\\ %ST\\ %B\\ %U\\ "
"%ci\\ %cp\\ %t\\ -\\ -\\ %B\\ %U\\ "
"%[ssl_c_verify]\\ %{+Q}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ "
"%tsc\n"
" maxconn 2014\n"