Merge "Truncate error logs to prevent log handler runs out of the buffer."
This commit is contained in:
commit
83373f833d
@ -336,6 +336,20 @@ class ObjectReplicator(Daemon):
|
|||||||
policy.load_ring(self.swift_dir)
|
policy.load_ring(self.swift_dir)
|
||||||
return policy.object_ring
|
return policy.object_ring
|
||||||
|
|
||||||
|
def _limit_rsync_log(self, line):
|
||||||
|
"""
|
||||||
|
If rsync_error_log_line_length is defined then
|
||||||
|
limit the error to that length
|
||||||
|
|
||||||
|
:param line: rsync log line
|
||||||
|
:return: If enabled the line limited to rsync_error_log_line_length
|
||||||
|
otherwise the initial line.
|
||||||
|
"""
|
||||||
|
if self.rsync_error_log_line_length:
|
||||||
|
return line[:self.rsync_error_log_line_length]
|
||||||
|
|
||||||
|
return line
|
||||||
|
|
||||||
def _rsync(self, args):
|
def _rsync(self, args):
|
||||||
"""
|
"""
|
||||||
Execute the rsync binary to replicate a partition.
|
Execute the rsync binary to replicate a partition.
|
||||||
@ -353,7 +367,9 @@ class ObjectReplicator(Daemon):
|
|||||||
results = proc.stdout.read()
|
results = proc.stdout.read()
|
||||||
ret_val = proc.wait()
|
ret_val = proc.wait()
|
||||||
except Timeout:
|
except Timeout:
|
||||||
self.logger.error(_("Killing long-running rsync: %s"), str(args))
|
self.logger.error(
|
||||||
|
self._limit_rsync_log(
|
||||||
|
_("Killing long-running rsync: %s") % str(args)))
|
||||||
if proc:
|
if proc:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
try:
|
try:
|
||||||
@ -385,11 +401,10 @@ class ObjectReplicator(Daemon):
|
|||||||
else:
|
else:
|
||||||
self.logger.error(result)
|
self.logger.error(result)
|
||||||
if ret_val:
|
if ret_val:
|
||||||
error_line = _('Bad rsync return code: %(ret)d <- %(args)s') % \
|
self.logger.error(
|
||||||
{'args': str(args), 'ret': ret_val}
|
self._limit_rsync_log(
|
||||||
if self.rsync_error_log_line_length:
|
_('Bad rsync return code: %(ret)d <- %(args)s') %
|
||||||
error_line = error_line[:self.rsync_error_log_line_length]
|
{'args': str(args), 'ret': ret_val}))
|
||||||
self.logger.error(error_line)
|
|
||||||
else:
|
else:
|
||||||
log_method = self.logger.info if results else self.logger.debug
|
log_method = self.logger.info if results else self.logger.debug
|
||||||
log_method(
|
log_method(
|
||||||
|
@ -2115,6 +2115,31 @@ class TestObjectReplicator(unittest.TestCase):
|
|||||||
])
|
])
|
||||||
self.assertEqual(len(mock_procs), 2)
|
self.assertEqual(len(mock_procs), 2)
|
||||||
|
|
||||||
|
def test_limit_rsync_log(self):
|
||||||
|
def do_test(length_limit, log_line, expected):
|
||||||
|
self.replicator.rsync_error_log_line_length = length_limit
|
||||||
|
result = self.replicator._limit_rsync_log(log_line)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
tests = [{'length_limit': 20,
|
||||||
|
'log_line': 'a' * 20,
|
||||||
|
'expected': 'a' * 20},
|
||||||
|
{'length_limit': 20,
|
||||||
|
'log_line': 'a' * 19,
|
||||||
|
'expected': 'a' * 19},
|
||||||
|
{'length_limit': 20,
|
||||||
|
'log_line': 'a' * 21,
|
||||||
|
'expected': 'a' * 20},
|
||||||
|
{'length_limit': None,
|
||||||
|
'log_line': 'a' * 50,
|
||||||
|
'expected': 'a' * 50},
|
||||||
|
{'length_limit': 0,
|
||||||
|
'log_line': 'a' * 50,
|
||||||
|
'expected': 'a' * 50}]
|
||||||
|
|
||||||
|
for params in tests:
|
||||||
|
do_test(**params)
|
||||||
|
|
||||||
|
|
||||||
@patch_policies([StoragePolicy(0, 'zero', False),
|
@patch_policies([StoragePolicy(0, 'zero', False),
|
||||||
StoragePolicy(1, 'one', True)])
|
StoragePolicy(1, 'one', True)])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user