From dc94773e600fef29cf88d304ffb1515b145aea13 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 24 Jun 2019 10:01:16 +0100 Subject: [PATCH] Avoid raising exceptions in metrics Sentry will catch the errors if they happen, so that should be good enough, and woun't make things explode if we hit the error condition. --- synapse/util/logcontext.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py index 10022ff62..6b0d2deea 100644 --- a/synapse/util/logcontext.py +++ b/synapse/util/logcontext.py @@ -374,20 +374,26 @@ class LoggingContext(object): # sanity check if utime_delta < 0: - raise ValueError("utime went backwards! %f < %f" % ( - current.ru_utime, self.usage_start.ru_utime, - )) + logger.error( + "utime went backwards! %f < %f", + current.ru_utime, + self.usage_start.ru_utime, + ) + utime_delta = 0 if stime_delta < 0: - raise ValueError("stime went backwards! %f < %f" % ( - current.ru_stime, self.usage_start.ru_stime, - )) + logger.error( + "stime went backwards! %f < %f", + current.ru_stime, + self.usage_start.ru_stime, + ) + stime_delta = 0 return utime_delta, stime_delta def add_database_transaction(self, duration_sec): if duration_sec < 0: - raise ValueError('DB txn time can only be non-negative') + raise ValueError("DB txn time can only be non-negative") self._resource_usage.db_txn_count += 1 self._resource_usage.db_txn_duration_sec += duration_sec @@ -399,7 +405,7 @@ class LoggingContext(object): connection """ if sched_sec < 0: - raise ValueError('DB scheduling time can only be non-negative') + raise ValueError("DB scheduling time can only be non-negative") self._resource_usage.db_sched_duration_sec += sched_sec def record_event_fetch(self, event_count):