# HG changeset patch # User Marcin Kuzminski # Date 2018-09-10 20:18:53 # Node ID e2100892e42d3fc7596ed55ebdbd5b8a7bd46d96 # Parent 26521a96d815c17ac5e325ef8273df649e079074 exc_tracker: allow setting custom store via .ini file - use safer exc read when listing exceptions. diff --git a/configs/development.ini b/configs/development.ini --- a/configs/development.ini +++ b/configs/development.ini @@ -292,6 +292,10 @@ supervisor.group_id = dev ## Display extended labs settings labs_settings_active = true +## custom exception store path, defaults to TMPDIR +exception_store_path = + + #################################### ### CELERY CONFIG #### #################################### diff --git a/configs/production.ini b/configs/production.ini --- a/configs/production.ini +++ b/configs/production.ini @@ -267,6 +267,10 @@ supervisor.group_id = prod ## Display extended labs settings labs_settings_active = true +## custom exception store path, defaults to TMPDIR +exception_store_path = + + #################################### ### CELERY CONFIG #### #################################### diff --git a/rhodecode/apps/admin/views/exception_tracker.py b/rhodecode/apps/admin/views/exception_tracker.py --- a/rhodecode/apps/admin/views/exception_tracker.py +++ b/rhodecode/apps/admin/views/exception_tracker.py @@ -73,10 +73,16 @@ class ExceptionsTrackerView(BaseAppView) if read_metadata: full_path = os.path.join(exc_store_path, fname) - # we can read our metadata - with open(full_path, 'rb') as f: - exc_metadata = exc_tracking.exc_unserialize(f.read()) - exc.update(exc_metadata) + if not os.path.isfile(full_path): + continue + try: + # we can read our metadata + with open(full_path, 'rb') as f: + exc_metadata = exc_tracking.exc_unserialize(f.read()) + exc.update(exc_metadata) + except Exception: + log.exception('Failed to read exc data from:{}'.format(full_path)) + pass # convert our timestamp to a date obj, for nicer representation exc['exc_utc_date'] = time_to_utcdatetime(exc['exc_timestamp']) diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -436,6 +436,7 @@ def _sanitize_vcs_settings(settings): def _sanitize_cache_settings(settings): + default_cache_dir = os.path.join(tempfile.gettempdir(), 'rc_cache') # save default, cache dir, and use it for all backends later. @@ -448,6 +449,12 @@ def _sanitize_cache_settings(settings): if not os.path.isdir(default_cache_dir): os.makedirs(default_cache_dir, mode=0755) + # exception store cache + _string_setting( + settings, + 'exception_store_path', + default_cache_dir, lower=False) + # cache_perms _string_setting( settings, diff --git a/rhodecode/lib/exc_tracking.py b/rhodecode/lib/exc_tracking.py --- a/rhodecode/lib/exc_tracking.py +++ b/rhodecode/lib/exc_tracking.py @@ -31,6 +31,7 @@ log = logging.getLogger(__name__) # NOTE: Any changes should be synced with exc_tracking at vcsserver.lib.exc_tracking global_prefix = 'rhodecode' +exc_store_dir_name = 'rc_exception_store_v1' def exc_serialize(exc_id, tb, exc_type): @@ -54,13 +55,10 @@ def get_exc_store(): """ Get and create exception store if it's not existing """ - exc_store_dir = 'rc_exception_store_v1' - # fallback - _exc_store_path = os.path.join(tempfile.gettempdir(), exc_store_dir) + import rhodecode as app - exc_store_dir = '' # TODO: need a persistent cross instance store here - if exc_store_dir: - _exc_store_path = os.path.join(exc_store_dir, exc_store_dir) + exc_store_dir = app.CONFIG.get('exception_store_path', '') or tempfile.gettempdir() + _exc_store_path = os.path.join(exc_store_dir, exc_store_dir_name) _exc_store_path = os.path.abspath(_exc_store_path) if not os.path.isdir(_exc_store_path):