From 9572fa62f557e590949d68ebdc41dbf2d9e7837e Mon Sep 17 00:00:00 2001 From: John Dickinson Date: Fri, 8 Oct 2010 17:20:43 -0500 Subject: [PATCH] added lazy load of internal proxy to log processor (you were right clay) --- swift/stats/log_processor.py | 27 +++++++++++++++++---------- test/unit/stats/test_log_processor.py | 6 +++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/swift/stats/log_processor.py b/swift/stats/log_processor.py index 39679f0503..6fd6c68597 100644 --- a/swift/stats/log_processor.py +++ b/swift/stats/log_processor.py @@ -39,21 +39,13 @@ class LogProcessor(object): """Load plugins, process logs""" def __init__(self, conf, logger): - stats_conf = conf.get('log-processor', {}) - if isinstance(logger, tuple): self.logger = get_logger(*logger) else: self.logger = logger - proxy_server_conf_loc = stats_conf.get('proxy_server_conf', - '/etc/swift/proxy-server.conf') - self.proxy_server_conf = appconfig( - 'config:%s' % proxy_server_conf_loc, - name='proxy-server') - self.internal_proxy = InternalProxy(self.proxy_server_conf, - self.logger, - retries=3) + self.conf = conf + self._internal_proxy = None # load the processing plugins self.plugins = {} @@ -69,6 +61,21 @@ class LogProcessor(object): self.plugins[plugin_name]['instance'] = klass(plugin_conf) self.logger.debug('Loaded plugin "%s"' % plugin_name) + @property + def internal_proxy(self): + if self._internal_proxy is None: + stats_conf = self.conf.get('log-processor', {}) + proxy_server_conf_loc = stats_conf.get('proxy_server_conf', + '/etc/swift/proxy-server.conf') + proxy_server_conf = appconfig( + 'config:%s' % proxy_server_conf_loc, + name='proxy-server') + self._internal_proxy = InternalProxy(proxy_server_conf, + self.logger, + retries=3) + else: + return self._internal_proxy + def process_one_file(self, plugin_name, account, container, object_name): self.logger.info('Processing %s/%s/%s with plugin "%s"' % (account, container, diff --git a/test/unit/stats/test_log_processor.py b/test/unit/stats/test_log_processor.py index cee34e55b7..4ff73eccf3 100644 --- a/test/unit/stats/test_log_processor.py +++ b/test/unit/stats/test_log_processor.py @@ -127,7 +127,7 @@ class TestLogProcessor(unittest.TestCase): def test_get_container_listing(self): p = log_processor.LogProcessor(self.proxy_config, DumbLogger()) - p.internal_proxy = DumbInternalProxy() + p._internal_proxy = DumbInternalProxy() result = p.get_container_listing('a', 'foo') expected = ['2010/03/14/13/obj1'] self.assertEquals(result, expected) @@ -148,7 +148,7 @@ class TestLogProcessor(unittest.TestCase): def test_get_object_data(self): p = log_processor.LogProcessor(self.proxy_config, DumbLogger()) - p.internal_proxy = DumbInternalProxy() + p._internal_proxy = DumbInternalProxy() result = list(p.get_object_data('a', 'c', 'o', False)) expected = ['obj','data'] self.assertEquals(result, expected) @@ -163,7 +163,7 @@ class TestLogProcessor(unittest.TestCase): 'swift.stats.stats_processor.StatsLogProcessor' }}) p = log_processor.LogProcessor(stats_proxy_config, DumbLogger()) - p.internal_proxy = DumbInternalProxy() + p._internal_proxy = DumbInternalProxy() def get_object_data(*a,**kw): return [self.stats_test_line] p.get_object_data = get_object_data