From f0eb25a973585e6a6cdb7c69a342fc6a38055e0d Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Fri, 22 Jun 2012 04:47:52 -0700 Subject: [PATCH] add UDP protocol support for logger When a syslog daemon fails and SysLogHandler cannot reconnect to it, server processes (proxy, container, object, and more) would start consuming 100 % CPU and stop responding to requests. It is because the server process go into an infinite loop if they fail to reconnect to /dev/log. This problem happens only when using unix_sockets. This change enables us to use syslog without unix_sockets and fixes bug 780025. Change-Id: Ibcc99a1a148b1008036146bf3bd079a9be24982c --- AUTHORS | 1 + swift/common/middleware/proxy_logging.py | 3 ++- swift/common/utils.py | 22 +++++++++++++++------- swift/proxy/server.py | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/AUTHORS b/AUTHORS index aadffb227e..5d2bf25eaa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -78,3 +78,4 @@ Ye Jia Xu (xyj.asmy@gmail.com) Pete Zaitcev (zaitcev@kotori.zaitcev.us) Josh Kearney (josh@jk0.org) Vincent Untz (vuntz@suse.com) +Tsuyuzaki Kota (tsuyuzaki.kota@lab.ntt.co.jp) diff --git a/swift/common/middleware/proxy_logging.py b/swift/common/middleware/proxy_logging.py index 83bcd15e7a..7248f04de2 100644 --- a/swift/common/middleware/proxy_logging.py +++ b/swift/common/middleware/proxy_logging.py @@ -94,7 +94,8 @@ class ProxyLoggingMiddleware(object): self.app = app self.log_hdrs = conf.get('log_headers', 'no').lower() in TRUE_VALUES access_log_conf = {} - for key in ('log_facility', 'log_name', 'log_level'): + for key in ('log_facility', 'log_name', 'log_level', 'log_udp_host', + 'log_udp_port'): value = conf.get('access_' + key, conf.get(key, None)) if value: access_log_conf[key] = value diff --git a/swift/common/utils.py b/swift/common/utils.py index a353a5c122..5027b940ba 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -511,6 +511,8 @@ def get_logger(conf, name=None, log_to_console=False, log_route=None, log_facility = LOG_LOCAL0 log_level = INFO log_name = swift + log_udp_host = (disabled) + log_udp_port = logging.handlers.SYSLOG_UDP_PORT log_statsd_host = (disabled) log_statsd_port = 8125 log_statsd_default_sample_rate = 1 @@ -542,13 +544,19 @@ def get_logger(conf, name=None, log_to_console=False, log_route=None, # facility for this logger will be set by last call wins facility = getattr(SysLogHandler, conf.get('log_facility', 'LOG_LOCAL0'), SysLogHandler.LOG_LOCAL0) - log_address = conf.get('log_address', '/dev/log') - try: - handler = SysLogHandler(address=log_address, facility=facility) - except socket.error, e: - if e.errno != errno.ENOTSOCK: # Socket operation on non-socket - raise e - handler = SysLogHandler(facility=facility) + udp_host = conf.get('log_udp_host') + if udp_host: + udp_port = conf.get('log_udp_port', logging.handlers.SYSLOG_UDP_PORT) + handler = SysLogHandler(address=(udp_host, udp_port), + facility=facility) + else: + log_address = conf.get('log_address', '/dev/log') + try: + handler = SysLogHandler(address=log_address, facility=facility) + except socket.error, e: + if e.errno != errno.ENOTSOCK: # Socket operation on non-socket + raise e + handler = SysLogHandler(facility=facility) handler.setFormatter(formatter) logger.addHandler(handler) get_logger.handler4logger[logger] = handler diff --git a/swift/proxy/server.py b/swift/proxy/server.py index f4c0d832db..2f6844d45d 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -1865,7 +1865,8 @@ class BaseApplication(object): if logger is None: self.logger = get_logger(conf, log_route='proxy-server') access_log_conf = {} - for key in ('log_facility', 'log_name', 'log_level'): + for key in ('log_facility', 'log_name', 'log_level', + 'log_udp_host', 'log_udp_port'): value = conf.get('access_' + key, conf.get(key, None)) if value: access_log_conf[key] = value