Add object_updater_last stat

Change-Id: I22674f2e887bdeeffe325efd2898fb90faa4235f
This commit is contained in:
Chinemerem 2024-12-12 06:54:58 -08:00
parent ea06ed4494
commit 5281af5cf2
5 changed files with 38 additions and 20 deletions

View File

@ -190,7 +190,8 @@ class ReconMiddleware(object):
self.container_recon_cache)
elif recon_type == 'object':
return self._from_recon_cache(['object_updater_sweep',
'object_updater_stats'],
'object_updater_stats',
'object_updater_last'],
self.object_recon_cache)
else:
return None

View File

@ -538,12 +538,13 @@ class ObjectUpdater(Daemon):
self.begin = time.time()
devices = self._listdir(self.devices)
self._process_devices(devices)
elapsed = time.time() - self.begin
now = time.time()
elapsed = now - self.begin
self.logger.info(
('Object update sweep of all devices completed: '
'%(elapsed).02fs'),
{'elapsed': elapsed})
self.aggregate_and_dump_recon(devices, elapsed)
self.aggregate_and_dump_recon(devices, elapsed, now)
return elapsed
def _gather_recon_stats(self):
@ -572,7 +573,7 @@ class ObjectUpdater(Daemon):
self.logger,
)
def aggregate_and_dump_recon(self, devices, elapsed):
def aggregate_and_dump_recon(self, devices, elapsed, now):
"""
Aggregate recon stats across devices and dump the result to the
recon cache.
@ -638,6 +639,7 @@ class ObjectUpdater(Daemon):
'object_updater_sweep': elapsed,
'object_updater_stats': aggregated_stats,
'object_updater_per_device': update_device_stats,
'object_updater_last': now
},
self.rcache,
self.logger,

View File

@ -455,6 +455,11 @@ class UpdaterStatsMixIn(object):
self.assertIsNotNone(timestamp)
ac_set.add((account, container))
object_updater_last = recon.get('object_updater_last')
self.assertIsNotNone(object_updater_last,
"object_updater_last is missing")
self.assertGreater(object_updater_last, 0,
"Invalid object_updater_last time")
# All the collected ac_set are from the ac_pairs we created
for ac in ac_set:
self.assertIn(ac, set(ac_pairs))

View File

@ -836,14 +836,17 @@ class TestReconSuccess(TestCase):
self.assertEqual(rv, {"container_updater_sweep": 18.476239919662476})
def test_get_updater_info_object(self):
from_cache_response = {"object_updater_sweep": 0.79848217964172363}
from_cache_response = {"object_updater_sweep": 0.79848217964172363,
"object_updater_last": 1357969645.25}
self.fakecache.fakeout_calls = []
self.fakecache.fakeout = from_cache_response
rv = self.app.get_updater_info('object')
self.assertEqual(self.fakecache.fakeout_calls,
[((['object_updater_sweep', 'object_updater_stats'],
[((['object_updater_sweep', 'object_updater_stats',
'object_updater_last'],
self._full_recon_path('object')), {})])
self.assertEqual(rv, {"object_updater_sweep": 0.79848217964172363})
self.assertEqual(rv, {"object_updater_sweep": 0.79848217964172363,
"object_updater_last": 1357969645.25})
def test_get_updater_info_unrecognized(self):
rv = self.app.get_updater_info('unrecognized_recon_type')

View File

@ -921,9 +921,12 @@ class TestObjectUpdater(unittest.TestCase):
'concurrency': '1',
'node_timeout': '15'}, logger=self.logger)
# There are no asyncs so there are no failures
with mock.patch.object(ou, 'object_update',
return_value=(False, 'node-id', None)):
ou._process_device_in_child(self.sda1, 'sda1')
ts = next(self.ts_iter)
now = float(next(self.ts_iter))
with mock.patch('swift.obj.updater.time.time', return_value=now):
with mock.patch.object(ou, 'object_update',
return_value=(False, 'node-id', None)):
ou._process_device_in_child(self.sda1, 'sda1')
exp_recon_dump = {
'object_updater_per_device': {
'sda1': {
@ -940,7 +943,6 @@ class TestObjectUpdater(unittest.TestCase):
}
assert_and_reset_recon_dump_per_device(exp_recon_dump)
ts = next(self.ts_iter)
ohash = hash_path('a', 'c', 'o')
odir = os.path.join(async_dir, ohash[-3:])
mkdirs(odir)
@ -952,7 +954,6 @@ class TestObjectUpdater(unittest.TestCase):
'X-Container-Timestamp':
normalize_timestamp(0)}},
async_pending)
now = float(next(self.ts_iter))
with mock.patch('swift.obj.updater.time.time', return_value=now):
with mock.patch.object(ou, 'object_update',
return_value=(False, 'node-id', None)):
@ -1052,8 +1053,8 @@ class TestObjectUpdater(unittest.TestCase):
}
}
utils.dump_recon_cache(incomplete_recon, ou.rcache, ou.logger)
ou.aggregate_and_dump_recon(['sda1', 'sda2', 'sda3'], 30)
now = float(next(self.ts_iter))
ou.aggregate_and_dump_recon(['sda1', 'sda2', 'sda3'], 30, now)
with open(recon_file) as f:
found_data = json.load(f)
@ -1072,6 +1073,7 @@ class TestObjectUpdater(unittest.TestCase):
expected_recon = {
'object_updater_sweep': 30,
'object_updater_stats': expected_aggregated_stats,
'object_updater_last': now,
}
self.assertEqual(expected_recon, found_data)
@ -1098,8 +1100,8 @@ class TestObjectUpdater(unittest.TestCase):
}
}
utils.dump_recon_cache(empty_recon, ou.rcache, ou.logger)
ou.aggregate_and_dump_recon(['sda1', 'sda2'], 30)
now = float(next(self.ts_iter))
ou.aggregate_and_dump_recon(['sda1', 'sda2'], 30, now)
with open(recon_file) as f:
found_data = json.load(f)
@ -1118,6 +1120,7 @@ class TestObjectUpdater(unittest.TestCase):
expected_recon = {
'object_updater_sweep': 30,
'object_updater_stats': expected_aggregated_stats,
'object_updater_last': now
}
self.assertEqual(expected_recon, found_data)
@ -1143,7 +1146,8 @@ class TestObjectUpdater(unittest.TestCase):
utils.dump_recon_cache(malformed_recon, ou.rcache, ou.logger)
with self.assertRaises(TypeError) as cm:
ou.aggregate_and_dump_recon(['sda1', 'sda2'], 30)
now = float(next(self.ts_iter))
ou.aggregate_and_dump_recon(['sda1', 'sda2'], 30, now)
self.assertIn(
'object_updater_per_device must be a dict', str(cm.exception))
@ -1178,8 +1182,8 @@ class TestObjectUpdater(unittest.TestCase):
}
}
utils.dump_recon_cache(existing_recon, ou.rcache, ou.logger)
ou.aggregate_and_dump_recon(['sda1'], 30)
now = float(next(self.ts_iter))
ou.aggregate_and_dump_recon(['sda1'], 30, now)
with open(recon_file) as f:
found_data = json.load(f)
@ -1204,6 +1208,7 @@ class TestObjectUpdater(unittest.TestCase):
},
'object_updater_sweep': 30,
'object_updater_stats': expected_aggregated_stats,
'object_updater_last': now,
}
self.assertEqual(expected_recon, found_data)
@ -1369,7 +1374,8 @@ class TestObjectUpdater(unittest.TestCase):
self.assertEqual(existing_recon, found_data) # sanity
# we're setting this up like sdx is stale/unmounted
ou.aggregate_and_dump_recon(['sda1', 'sda2', 'sda3'], 30)
now = float(next(self.ts_iter))
ou.aggregate_and_dump_recon(['sda1', 'sda2', 'sda3'], 30, now)
with open(recon_file) as f:
found_data = json.load(f)
@ -1389,6 +1395,7 @@ class TestObjectUpdater(unittest.TestCase):
expected_recon = dict(existing_recon, **{
'object_updater_sweep': 30,
'object_updater_stats': expected_aggregated_stats,
'object_updater_last': now,
})
# and sda4 is removed
del expected_recon['object_updater_per_device']['sdx']