Last active
September 6, 2023 10:58
-
-
Save clayg/7f66eab2a61c77869e1e84ac4ed6f1df to your computer and use it in GitHub Desktop.
check on the expirer queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from collections import defaultdict | |
import sys | |
import time | |
from argparse import ArgumentParser | |
from swift.common.internal_client import InternalClient | |
from swift.common.utils import Timestamp | |
from swift.common.wsgi import ConfigString | |
from swift.container.sync import ic_conf_body | |
from swift.obj.expirer import parse_task_obj | |
parser = ArgumentParser() | |
parser.add_argument('-v', '--verbose', action='store_true', | |
help='more detailed info') | |
parser.add_argument('--objects-container-divisor', type=int, default=86400, | |
help='The window size for pending expirations') | |
parser.add_argument('-d', '--details', action='store_true', | |
help='more detailed counts') | |
def main(): | |
args = parser.parse_args() | |
now = time.time() | |
t_now = Timestamp.now() | |
expiring_account = '.expiring_objects' | |
conf = ConfigString(ic_conf_body) | |
swift = InternalClient(conf, 'swift-expirer-status', 1) | |
stats = defaultdict(int) | |
for container_item in swift.iter_containers(expiring_account): | |
if args.verbose: | |
print ('%s/' % expiring_account + | |
'%(name)s: %(count)s' % container_item) | |
try: | |
container = int(container_item['name']) | |
except ValueError: | |
continue | |
stats['total'] += container_item['count'] | |
if container < now: | |
if container < (now - args.objects_container_divisor): | |
stats['stale'] += container_item['count'] | |
else: | |
if not args.details: | |
stats['pending'] += container_item['count'] | |
continue | |
for object_item in swift.iter_objects( | |
expiring_account, container_item['name']): | |
if args.verbose: | |
print '%(name)s: %(content_type)s' % object_item | |
# this should probably be done in parse_task_obj | |
task_object = object_item['name'].encode('utf8') | |
delete_timestamp, _target_account, _target_container, \ | |
_target_object = parse_task_obj(task_object) | |
if t_now > delete_timestamp: | |
stats['stale'] += 1 | |
else: | |
stats['pending'] += 1 | |
print ' Total entries: %(total)s' % stats | |
print 'Pending entries: %(pending)s' % stats | |
print ' Stale entries: %(stale)s' % stats | |
if __name__ == "__main__": | |
sys.exit(main()) |
Let's just submit it to gerrit as a new cli tool to the main swift repo, you can add me as a co-author or "inspired by" if you want.
Sounds good to me; I've put this on my TODO (no promises as to timescale)
I've finally got round to doing this - you can see the CR here:
https://review.opendev.org/c/openstack/swift/+/893861
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I used this to look at an issue we're investigating at work, made a couple of tweaks to make it run on a Debian bullseye system (and correspondingly more recent Swift code). In case I want to use it again, would you mind agreeing to licensing it please? [e.g. Apache-2].
Work = The Wikimedia Foundation, a non-profit org.