Merge "Log updater stats once per pass, not per policy"
This commit is contained in:
@@ -278,25 +278,25 @@ class ObjectUpdater(Daemon):
|
|||||||
os.rmdir(prefix_path)
|
os.rmdir(prefix_path)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
self.logger.timing_since('timing', start_time)
|
self.logger.timing_since('timing', start_time)
|
||||||
sweep_totals = self.stats.since(start_stats)
|
sweep_totals = self.stats.since(start_stats)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
('Object update sweep completed on %(device)s '
|
('Object update sweep completed on %(device)s '
|
||||||
'in %(elapsed).02fs seconds:, '
|
'in %(elapsed).02fs seconds:, '
|
||||||
'%(successes)d successes, %(failures)d failures, '
|
'%(successes)d successes, %(failures)d failures, '
|
||||||
'%(quarantines)d quarantines, '
|
'%(quarantines)d quarantines, '
|
||||||
'%(unlinks)d unlinks, %(errors)d errors, '
|
'%(unlinks)d unlinks, %(errors)d errors, '
|
||||||
'%(redirects)d redirects '
|
'%(redirects)d redirects '
|
||||||
'(pid: %(pid)d)'),
|
'(pid: %(pid)d)'),
|
||||||
{'device': device,
|
{'device': device,
|
||||||
'elapsed': time.time() - start_time,
|
'elapsed': time.time() - start_time,
|
||||||
'pid': my_pid,
|
'pid': my_pid,
|
||||||
'successes': sweep_totals.successes,
|
'successes': sweep_totals.successes,
|
||||||
'failures': sweep_totals.failures,
|
'failures': sweep_totals.failures,
|
||||||
'quarantines': sweep_totals.quarantines,
|
'quarantines': sweep_totals.quarantines,
|
||||||
'unlinks': sweep_totals.unlinks,
|
'unlinks': sweep_totals.unlinks,
|
||||||
'errors': sweep_totals.errors,
|
'errors': sweep_totals.errors,
|
||||||
'redirects': sweep_totals.redirects})
|
'redirects': sweep_totals.redirects})
|
||||||
|
|
||||||
def process_object_update(self, update_path, device, policy):
|
def process_object_update(self, update_path, device, policy):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -321,6 +321,55 @@ class TestObjectUpdater(unittest.TestCase):
|
|||||||
info_lines[3])
|
info_lines[3])
|
||||||
self.assertIn(self.sda1, info_lines[3])
|
self.assertIn(self.sda1, info_lines[3])
|
||||||
|
|
||||||
|
def test_sweep_logs_multiple_policies(self):
|
||||||
|
for policy in _mocked_policies:
|
||||||
|
asyncdir = os.path.join(self.sda1, get_async_dir(policy.idx))
|
||||||
|
prefix_dir = os.path.join(asyncdir, 'abc')
|
||||||
|
mkpath(prefix_dir)
|
||||||
|
|
||||||
|
for o, t in [('abc', 123), ('def', 234), ('ghi', 345)]:
|
||||||
|
ohash = hash_path('account', 'container%d' % policy.idx, o)
|
||||||
|
o_path = os.path.join(prefix_dir, ohash + '-' +
|
||||||
|
normalize_timestamp(t))
|
||||||
|
write_pickle({}, o_path)
|
||||||
|
|
||||||
|
class MockObjectUpdater(object_updater.ObjectUpdater):
|
||||||
|
def process_object_update(self, update_path, device, policy):
|
||||||
|
os.unlink(update_path)
|
||||||
|
self.stats.successes += 1
|
||||||
|
self.stats.unlinks += 1
|
||||||
|
|
||||||
|
logger = FakeLogger()
|
||||||
|
ou = MockObjectUpdater({
|
||||||
|
'devices': self.devices_dir,
|
||||||
|
'mount_check': 'false',
|
||||||
|
'swift_dir': self.testdir,
|
||||||
|
'interval': '1',
|
||||||
|
'concurrency': '1',
|
||||||
|
'report_interval': '10.0',
|
||||||
|
'node_timeout': '5'}, logger=logger)
|
||||||
|
|
||||||
|
now = [time()]
|
||||||
|
|
||||||
|
def mock_time():
|
||||||
|
rv = now[0]
|
||||||
|
now[0] += 0.01
|
||||||
|
return rv
|
||||||
|
|
||||||
|
with mock.patch('swift.obj.updater.time',
|
||||||
|
mock.MagicMock(time=mock_time)):
|
||||||
|
ou.object_sweep(self.sda1)
|
||||||
|
|
||||||
|
completion_lines = [l for l in logger.get_lines_for_level('info')
|
||||||
|
if "sweep complete" in l]
|
||||||
|
|
||||||
|
self.assertEqual(len(completion_lines), 1)
|
||||||
|
self.assertIn("sweep complete", completion_lines[0])
|
||||||
|
self.assertIn(
|
||||||
|
"6 successes, 0 failures, 0 quarantines, 6 unlinks, 0 errors, "
|
||||||
|
"0 redirects",
|
||||||
|
completion_lines[0])
|
||||||
|
|
||||||
@mock.patch.object(object_updater, 'check_drive')
|
@mock.patch.object(object_updater, 'check_drive')
|
||||||
def test_run_once_with_disk_unmounted(self, mock_check_drive):
|
def test_run_once_with_disk_unmounted(self, mock_check_drive):
|
||||||
mock_check_drive.return_value = False
|
mock_check_drive.return_value = False
|
||||||
|
|||||||
Reference in New Issue
Block a user