]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/mgr_util: log traceback when exception occurs in RTimer.run() 60008/head
authorRishabh Dave <ridave@redhat.com>
Thu, 26 Sep 2024 19:13:31 +0000 (00:43 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 27 Sep 2024 04:36:56 +0000 (10:06 +0530)
When an exception occurs in class RTimer of mgr_util.py, only the
exception message is logged but not only this is insufficient for
debugging but also it is hard to spot in logs. This should not be the
case, especially for an occurring exception. Therefore, add code to log
traceback and exception name as well along with exception's message.

Log entry before this patch -

2024-09-27T00:22:38.656+0530 7f05c7e006c0  0 [volumes ERROR mgr_util] task exception: dummy exception for testing

Log entry with this patch -

2024-09-27T00:40:26.509+0530 7f61d64006c0  0 [volumes ERROR mgr_util] exception encountered in RTimer instance "<RTimer(Thread-7, started daemon 140058183075520)>":
Traceback (most recent call last):
  File "/home/rishabh/repos/ceph/minor3/src/pybind/mgr/mgr_util.py", line 91, in run
    self.function(*self.args, **self.kwargs)
  File "/home/rishabh/repos/ceph/minor3/src/pybind/mgr/volumes/fs/stats_util.py", line 232, in _update_progress_bars
    raise RuntimeError('dummy exception for testing')
RuntimeError: dummy exception for testing

Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/mgr/mgr_util.py

index a999b6525e9f1ee24e32d4b5d47a7b7b24772c65..5d37d478de7b1ed7b89d8769b3009612321a130d 100644 (file)
@@ -22,6 +22,7 @@ import sys
 from ipaddress import ip_address
 from threading import Lock, Condition
 from typing import no_type_check, NewType
+from traceback import format_exc as tb_format_exc
 import urllib
 from functools import wraps
 if sys.version_info >= (3, 3):
@@ -88,8 +89,9 @@ class RTimer(Timer):
             while not self.finished.is_set():
                 self.finished.wait(self.interval)
                 self.function(*self.args, **self.kwargs)
-        except Exception as e:
-            logger.error("task exception: %s", e)
+        except Exception:
+            logger.error(f'exception encountered in RTimer instance "{self}":'
+                         f'\n{tb_format_exc()}')
             raise