For stats uploader, allow override regex for source_filename_pattern and new_log_cutoff.

This commit is contained in:
David Goetz 2011-05-24 22:12:02 +00:00 committed by Tarmac
commit e3b6de6c08
2 changed files with 20 additions and 11 deletions

View File

@ -22,6 +22,10 @@ from swift.common import utils
if __name__ == '__main__':
parser = OptionParser("Usage: %prog CONFIG_FILE PLUGIN")
parser.add_option('-c', '--log_cutoff',
help='Override new_log_cutoff.')
parser.add_option('-x', '--regex',
help='Override source_filename_pattern regex.')
conf_file, options = parse_options(parser=parser)
try:
plugin = options['extra_args'][0]
@ -39,4 +43,7 @@ if __name__ == '__main__':
log_to_console=options.get('verbose', False))
# currently LogUploader only supports run_once
options['once'] = True
uploader = LogUploader(uploader_conf, plugin).run(**options)
regex = options.get('regex')
cutoff = options.get('log_cutoff')
uploader = LogUploader(uploader_conf, plugin,
regex=regex, cutoff=cutoff).run(**options)

View File

@ -54,7 +54,7 @@ class LogUploader(Daemon):
.*$
'''
def __init__(self, uploader_conf, plugin_name):
def __init__(self, uploader_conf, plugin_name, regex=None, cutoff=None):
super(LogUploader, self).__init__(uploader_conf)
log_name = '%s-log-uploader' % plugin_name
self.logger = utils.get_logger(uploader_conf, log_name,
@ -67,17 +67,19 @@ class LogUploader(Daemon):
proxy_server_conf = appconfig('config:%s' % proxy_server_conf_loc,
name='proxy-server')
self.internal_proxy = InternalProxy(proxy_server_conf)
self.new_log_cutoff = int(uploader_conf.get('new_log_cutoff', '7200'))
self.new_log_cutoff = int(cutoff or
uploader_conf.get('new_log_cutoff', '7200'))
self.unlink_log = uploader_conf.get('unlink_log', 'True').lower() in \
utils.TRUE_VALUES
self.filename_pattern = uploader_conf.get('source_filename_pattern',
'''
^%s-
(?P<year>[0-9]{4})
(?P<month>[0-1][0-9])
(?P<day>[0-3][0-9])
(?P<hour>[0-2][0-9])
.*$''' % plugin_name)
self.filename_pattern = regex or \
uploader_conf.get('source_filename_pattern',
'''
^%s-
(?P<year>[0-9]{4})
(?P<month>[0-1][0-9])
(?P<day>[0-3][0-9])
(?P<hour>[0-2][0-9])
.*$''' % plugin_name)
def run_once(self, *args, **kwargs):
self.logger.info(_("Uploading logs"))