feat(endpoints/trackhelper): wrap log op for silent fails

This commit is contained in:
EvB 2017-02-15 15:44:08 -05:00
parent 503c4cd235
commit 6916d82e0d
2 changed files with 17 additions and 7 deletions

View file

@ -273,9 +273,8 @@ class DefaultConfig(object):
SYSTEM_LOGS_FILE = "/var/log/syslog"
SYSTEM_SERVICES_PATH = "conf/init/service/"
# Disallow all registry operations if unable to write to the audit log
# When disabled, registry pulls are allowed despite any failures to write to audit log
STRICT_AUDIT_LOG=true
# Allow registry pulls when unable to write to the audit log
ALLOW_PULLS_WITHOUT_STRICT_LOGGING = False
# Services that should not be shown in the logs view.
SYSTEM_SERVICE_BLACKLIST = []

View file

@ -1,13 +1,16 @@
import json
import logging
from calendar import timegm
from peewee import JOIN_LEFT_OUTER, fn
from peewee import JOIN_LEFT_OUTER, fn, PeeweeException
from datetime import datetime, timedelta
from cachetools import lru_cache
from data.database import LogEntry, LogEntryKind, User, RepositoryActionCount, db
from data.model import config, user, DataModelException
logger = logging.getLogger(__name__)
def _logs_query(selections, start_time, end_time, performer=None, repository=None, namespace=None,
ignore=None):
joined = (LogEntry
@ -109,9 +112,17 @@ def log_action(kind_name, user_or_organization_name, performer=None, repository=
kind = _get_log_entry_kind(kind_name)
metadata_json = json.dumps(metadata, default=_json_serialize)
LogEntry.create(kind=kind, account=account, performer=performer,
repository=repository, ip=ip, metadata_json=metadata_json,
datetime=timestamp)
try:
LogEntry.create(kind=kind, account=account, performer=performer,
repository=repository, ip=ip, metadata_json=metadata_json,
datetime=timestamp)
except PeeweeException:
if kind_name is 'pull_repo' and config.app_config.get('ALLOW_PULLS_WITHOUT_STRICT_LOGGING'):
logger.warning('log_action failed: kind=%s account=%s user=%s repo=%s ip=%s metadata=%s',
kind_name, account, performer, repository, ip, metadata_json)
else:
raise
def get_stale_logs_start_id():