Keep object-updater stats logging consistent
If we're going to encapsulate the stats tracking it seems reasonable if we ever add any more metrics we can reduce the number of places we need to update log messages. Change-Id: I187cf6cfec1e0a9138b709fa298e1991aa809ec4
This commit is contained in:
parent
22f700d1cc
commit
d2034cd7b6
@ -66,6 +66,16 @@ class SweepStats(object):
|
|||||||
self.successes = 0
|
self.successes = 0
|
||||||
self.unlinks = 0
|
self.unlinks = 0
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
keys = (
|
||||||
|
(self.successes, 'successes'),
|
||||||
|
(self.failures, 'failures'),
|
||||||
|
(self.quarantines, 'quarantines'),
|
||||||
|
(self.unlinks, 'unlinks'),
|
||||||
|
(self.errors, 'errors'),
|
||||||
|
)
|
||||||
|
return ', '.join('%d %s' % pair for pair in keys)
|
||||||
|
|
||||||
|
|
||||||
class ObjectUpdater(Daemon):
|
class ObjectUpdater(Daemon):
|
||||||
"""Update object information in container listings."""
|
"""Update object information in container listings."""
|
||||||
@ -148,16 +158,9 @@ class ObjectUpdater(Daemon):
|
|||||||
elapsed = time.time() - forkbegin
|
elapsed = time.time() - forkbegin
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
('Object update sweep of %(device)s '
|
('Object update sweep of %(device)s '
|
||||||
'completed: %(elapsed).02fs, '
|
'completed: %(elapsed).02fs, %(stats)s'),
|
||||||
'%(successes)d successes, %(failures)d failures, '
|
|
||||||
'%(quarantines)d quarantines, '
|
|
||||||
'%(unlinks)d unlinks, %(errors)d errors'),
|
|
||||||
{'device': device, 'elapsed': elapsed,
|
{'device': device, 'elapsed': elapsed,
|
||||||
'success': self.stats.successes,
|
'stats': self.stats})
|
||||||
'failures': self.stats.failures,
|
|
||||||
'quarantines': self.stats.quarantines,
|
|
||||||
'unlinks': self.stats.unlinks,
|
|
||||||
'errors': self.stats.errors})
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
while pids:
|
while pids:
|
||||||
pids.remove(os.wait()[0])
|
pids.remove(os.wait()[0])
|
||||||
@ -186,16 +189,8 @@ class ObjectUpdater(Daemon):
|
|||||||
elapsed = time.time() - begin
|
elapsed = time.time() - begin
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
('Object update single-threaded sweep completed: '
|
('Object update single-threaded sweep completed: '
|
||||||
'%(elapsed).02fs, %(successes)d successes, '
|
'%(elapsed).02fs, %(stats)s'),
|
||||||
'%(failures)d failures, '
|
{'elapsed': elapsed, 'stats': self.stats})
|
||||||
'%(quarantines)d quarantines, %(unlinks)d unlinks, '
|
|
||||||
'%(errors)d errors'),
|
|
||||||
{'elapsed': elapsed,
|
|
||||||
'successes': self.stats.successes,
|
|
||||||
'failures': self.stats.failures,
|
|
||||||
'quarantines': self.stats.quarantines,
|
|
||||||
'unlinks': self.stats.unlinks,
|
|
||||||
'errors': self.stats.errors})
|
|
||||||
dump_recon_cache({'object_updater_sweep': elapsed},
|
dump_recon_cache({'object_updater_sweep': elapsed},
|
||||||
self.rcache, self.logger)
|
self.rcache, self.logger)
|
||||||
|
|
||||||
@ -267,19 +262,11 @@ class ObjectUpdater(Daemon):
|
|||||||
this_sweep = self.stats.since(start_stats)
|
this_sweep = self.stats.since(start_stats)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
('Object update sweep progress on %(device)s: '
|
('Object update sweep progress on %(device)s: '
|
||||||
'%(elapsed).02fs, '
|
'%(elapsed).02fs, %(stats)s (pid: %(pid)d)'),
|
||||||
'%(successes)d successes, %(failures)d failures, '
|
|
||||||
'%(quarantines)d quarantines, '
|
|
||||||
'%(unlinks)d unlinks, %(errors)d errors '
|
|
||||||
'(pid: %(pid)d)'),
|
|
||||||
{'device': device,
|
{'device': device,
|
||||||
'elapsed': now - start_time,
|
'elapsed': now - start_time,
|
||||||
'pid': my_pid,
|
'pid': my_pid,
|
||||||
'successes': this_sweep.successes,
|
'stats': this_sweep})
|
||||||
'failures': this_sweep.failures,
|
|
||||||
'quarantines': this_sweep.quarantines,
|
|
||||||
'unlinks': this_sweep.unlinks,
|
|
||||||
'errors': this_sweep.errors})
|
|
||||||
last_status_update = now
|
last_status_update = now
|
||||||
try:
|
try:
|
||||||
os.rmdir(prefix_path)
|
os.rmdir(prefix_path)
|
||||||
|
@ -298,15 +298,21 @@ class TestObjectUpdater(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertIn("sweep progress", info_lines[1])
|
self.assertIn("sweep progress", info_lines[1])
|
||||||
# the space ensures it's a positive number
|
# the space ensures it's a positive number
|
||||||
self.assertIn(" 2 successes", info_lines[1])
|
self.assertIn(
|
||||||
|
"2 successes, 0 failures, 0 quarantines, 2 unlinks, 0 error",
|
||||||
|
info_lines[1])
|
||||||
self.assertIn(self.sda1, info_lines[1])
|
self.assertIn(self.sda1, info_lines[1])
|
||||||
|
|
||||||
self.assertIn("sweep progress", info_lines[2])
|
self.assertIn("sweep progress", info_lines[2])
|
||||||
self.assertIn(" 4 successes", info_lines[2])
|
self.assertIn(
|
||||||
|
"4 successes, 0 failures, 0 quarantines, 4 unlinks, 0 error",
|
||||||
|
info_lines[2])
|
||||||
self.assertIn(self.sda1, info_lines[2])
|
self.assertIn(self.sda1, info_lines[2])
|
||||||
|
|
||||||
self.assertIn("sweep complete", info_lines[3])
|
self.assertIn("sweep complete", info_lines[3])
|
||||||
self.assertIn(" 5 successes", info_lines[3])
|
self.assertIn(
|
||||||
|
"5 successes, 0 failures, 0 quarantines, 5 unlinks, 0 error",
|
||||||
|
info_lines[3])
|
||||||
self.assertIn(self.sda1, info_lines[3])
|
self.assertIn(self.sda1, info_lines[3])
|
||||||
|
|
||||||
@mock.patch.object(object_updater, 'check_drive')
|
@mock.patch.object(object_updater, 'check_drive')
|
||||||
|
Loading…
Reference in New Issue
Block a user