Merge pull request #3245 from quay/log-archive-json-bug

Handle the case where the log metadata JSON cannot be parsed
This commit is contained in:
Joseph Schorr 2018-09-07 16:06:22 -04:00 committed by GitHub
commit 995ba4fd75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -106,13 +106,24 @@ class LogRotateWorker(Worker):
def log_dict(log):
""" Pretty prints a LogEntry in JSON. """
return {'kind_id': log.kind_id,
'account_id': log.account_id,
'performer_id': log.performer_id,
'repository_id': log.repository_id,
'datetime': str(log.datetime),
'ip': str(log.ip),
'metadata_json': json.loads(str(log.metadata_json))}
try:
metadata_json = json.loads(str(log.metadata_json))
except ValueError:
logger.exception('Could not parse metadata JSON for log entry %s', log.id)
metadata_json = {'__raw': log.metadata_json}
except TypeError:
logger.exception('Could not parse metadata JSON for log entry %s', log.id)
metadata_json = {'__raw': log.metadata_json}
return {
'kind_id': log.kind_id,
'account_id': log.account_id,
'performer_id': log.performer_id,
'repository_id': log.repository_id,
'datetime': str(log.datetime),
'ip': str(log.ip),
'metadata_json': metadata_json,
}
def main():