Add async_pending_last time to object.recon

The async_pending count isn't near as useful when we don't know how out
of date it is.

Change-Id: I3e5e904ffc0eba7a7e141e1c2d9f9840e4952041
This commit is contained in:
Tim Burke 2020-10-16 10:38:20 -07:00
parent 1a5b42da9e
commit 39ad468dfe
3 changed files with 12 additions and 6 deletions

View File

@ -18,6 +18,7 @@ swift-recon-cron.py
import os
import sys
import time
from eventlet import Timeout
@ -65,7 +66,10 @@ def main():
try:
with lock_path(lock_dir):
asyncs = get_async_count(device_dir, logger)
dump_recon_cache({'async_pending': asyncs}, cache_file, logger)
dump_recon_cache({
'async_pending': asyncs,
'async_pending_last': time.time(),
}, cache_file, logger)
except (Exception, Timeout) as err:
msg = 'Exception during recon-cron while accessing devices'
logger.exception(msg)

View File

@ -81,7 +81,7 @@ class ReconMiddleware(object):
try:
with openr(cache_file, 'r') as f:
recondata = json.load(f)
return dict((key, recondata.get(key)) for key in cache_keys)
return {key: recondata.get(key) for key in cache_keys}
except IOError as err:
if err.errno == errno.ENOENT and ignore_missing:
pass
@ -132,7 +132,7 @@ class ReconMiddleware(object):
def get_async_info(self):
"""get # of async pendings"""
return self._from_recon_cache(['async_pending'],
return self._from_recon_cache(['async_pending', 'async_pending_last'],
self.object_recon_cache)
def get_driveaudit_error(self):

View File

@ -22,6 +22,7 @@ import os
from posix import stat_result, statvfs_result
from shutil import rmtree
import tempfile
import time
import unittest
from unittest import TestCase
@ -676,13 +677,14 @@ class TestReconSuccess(TestCase):
self.assertEqual(rv, meminfo_resp)
def test_get_async_info(self):
from_cache_response = {'async_pending': 5}
now = time.time()
from_cache_response = {'async_pending': 5, 'async_pending_last': now}
self.fakecache.fakeout = from_cache_response
rv = self.app.get_async_info()
self.assertEqual(self.fakecache.fakeout_calls,
[((['async_pending'],
[((['async_pending', 'async_pending_last'],
'/var/cache/swift/object.recon'), {})])
self.assertEqual(rv, {'async_pending': 5})
self.assertEqual(rv, {'async_pending': 5, 'async_pending_last': now})
def test_get_replication_info_account(self):
from_cache_response = {