summary refs log tree commit diff
path: root/synapse/metrics
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2022-10-31 13:02:07 +0000
committerGitHub <noreply@github.com>2022-10-31 13:02:07 +0000
commit2bb2c32e8ed5642a5bf3ba1e8c49e10cecc88905 (patch)
treeb25c0eb8017de0c12dc176dbae2679d9177c0cbf /synapse/metrics
parentPrevent federation user keys query from returning device names if disallowed ... (diff)
downloadsynapse-2bb2c32e8ed5642a5bf3ba1e8c49e10cecc88905.tar.xz
Avoid incrementing bg process utime/stime counters by negative durations (#14323)
Diffstat (limited to 'synapse/metrics')
-rw-r--r--synapse/metrics/background_process_metrics.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/synapse/metrics/background_process_metrics.py b/synapse/metrics/background_process_metrics.py
index 7a1516d3a8..9ea4e23b31 100644
--- a/synapse/metrics/background_process_metrics.py
+++ b/synapse/metrics/background_process_metrics.py
@@ -174,8 +174,10 @@ class _BackgroundProcess:
             diff = new_stats - self._reported_stats
         self._reported_stats = new_stats
 
-        _background_process_ru_utime.labels(self.desc).inc(diff.ru_utime)
-        _background_process_ru_stime.labels(self.desc).inc(diff.ru_stime)
+        # For unknown reasons, the difference in times can be negative. See comment in
+        # synapse.http.request_metrics.RequestMetrics.update_metrics.
+        _background_process_ru_utime.labels(self.desc).inc(max(diff.ru_utime, 0))
+        _background_process_ru_stime.labels(self.desc).inc(max(diff.ru_stime, 0))
         _background_process_db_txn_count.labels(self.desc).inc(diff.db_txn_count)
         _background_process_db_txn_duration.labels(self.desc).inc(
             diff.db_txn_duration_sec