Просмотр исходного кода

Merge pull request #26 from aznashwan/logging-fixes

Logging fixes
Nashwan Azhari 7 лет назад
Родитель
Сommit
d366818f81
2 измененных файлов с 27 добавлено и 5 удалено
  1. 21 3
      coriolis/utils.py
  2. 6 2
      coriolis/worker/rpc/server.py

+ 21 - 3
coriolis/utils.py

@@ -3,6 +3,7 @@
 
 import base64
 import binascii
+import copy
 import functools
 import hashlib
 import io
@@ -49,8 +50,8 @@ def ignore_exceptions(func):
     def _ignore_exceptions(*args, **kwargs):
         try:
             return func(*args, **kwargs)
-        except Exception as ex:
-            LOG.exception(ex)
+        except Exception:
+            LOG.warn("Ignoring exception:\n%s", get_exception_details())
     return _ignore_exceptions
 
 
@@ -87,7 +88,9 @@ def retry_on_error(max_attempts=5, sleep_seconds=0,
 
                     i += 1
                     if i < max_attempts:
-                        LOG.warn("Exception occurred, retrying: %s", ex)
+                        LOG.warn(
+                            "Exception occurred, retrying (%d/%d):\n%s",
+                            i, max_attempts, get_exception_details())
                         time.sleep(sleep_seconds)
                     else:
                         raise
@@ -479,3 +482,18 @@ def bad_request_on_error(error_message):
             return (is_valid, message)
         return wrapper
     return _bad_request_on_error
+
+
+def filter_chunking_info_for_task(task_info):
+    """ Returns a copy of the given task info with any chunking
+    info on volumes removed.
+    """
+    cpy = copy.deepcopy(task_info)
+    if not cpy.get("volumes_info"):
+        return cpy
+
+    for vol in cpy['volumes_info']:
+        if vol.get("replica_state", {}).get("chunks"):
+            vol["replica_state"]["chunks"] = "<redacted>"
+
+    return cpy

+ 6 - 2
coriolis/worker/rpc/server.py

@@ -193,7 +193,9 @@ class WorkerServerEndpoint(object):
                 instance, task_info)
 
             if new_task_info:
-                LOG.info("Task info: %s", new_task_info)
+                LOG.info(
+                    "Task info: %s",
+                    utils.filter_chunking_info_for_task(new_task_info))
 
             # TODO(alexpilotti): replace the temp storage with a host
             # independent option
@@ -410,7 +412,9 @@ def _task_process(ctxt, task_id, task_type, origin, destination, instance,
                   "instance: %(instance)s, task_info: %(task_info)s",
                   {"task_id": task_id, "task_type": task_type,
                    "origin": origin, "destination": destination,
-                   "instance": instance, "task_info": task_info})
+                   "instance": instance,
+                   "task_info": utils.filter_chunking_info_for_task(
+                       task_info)})
 
         new_task_info = task_runner.run(
             ctxt, instance, origin, destination, task_info, event_handler)