feat(endpoints/trackhelper): wrap log op for silent fails
This commit is contained in:
parent
503c4cd235
commit
6916d82e0d
2 changed files with 17 additions and 7 deletions
|
@ -273,9 +273,8 @@ class DefaultConfig(object):
|
||||||
SYSTEM_LOGS_FILE = "/var/log/syslog"
|
SYSTEM_LOGS_FILE = "/var/log/syslog"
|
||||||
SYSTEM_SERVICES_PATH = "conf/init/service/"
|
SYSTEM_SERVICES_PATH = "conf/init/service/"
|
||||||
|
|
||||||
# Disallow all registry operations if unable to write to the audit log
|
# Allow registry pulls when unable to write to the audit log
|
||||||
# When disabled, registry pulls are allowed despite any failures to write to audit log
|
ALLOW_PULLS_WITHOUT_STRICT_LOGGING = False
|
||||||
STRICT_AUDIT_LOG=true
|
|
||||||
|
|
||||||
# Services that should not be shown in the logs view.
|
# Services that should not be shown in the logs view.
|
||||||
SYSTEM_SERVICE_BLACKLIST = []
|
SYSTEM_SERVICE_BLACKLIST = []
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
from calendar import timegm
|
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 datetime import datetime, timedelta
|
||||||
from cachetools import lru_cache
|
from cachetools import lru_cache
|
||||||
|
|
||||||
from data.database import LogEntry, LogEntryKind, User, RepositoryActionCount, db
|
from data.database import LogEntry, LogEntryKind, User, RepositoryActionCount, db
|
||||||
from data.model import config, user, DataModelException
|
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,
|
def _logs_query(selections, start_time, end_time, performer=None, repository=None, namespace=None,
|
||||||
ignore=None):
|
ignore=None):
|
||||||
joined = (LogEntry
|
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)
|
kind = _get_log_entry_kind(kind_name)
|
||||||
metadata_json = json.dumps(metadata, default=_json_serialize)
|
metadata_json = json.dumps(metadata, default=_json_serialize)
|
||||||
LogEntry.create(kind=kind, account=account, performer=performer,
|
try:
|
||||||
repository=repository, ip=ip, metadata_json=metadata_json,
|
LogEntry.create(kind=kind, account=account, performer=performer,
|
||||||
datetime=timestamp)
|
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():
|
def get_stale_logs_start_id():
|
||||||
|
|
Reference in a new issue