From 40e0632ed58949790599493990ab6dba9549fafc Mon Sep 17 00:00:00 2001 From: Nitzan Mordechai Date: Mon, 24 Jan 2022 12:55:23 +0200 Subject: [PATCH] pybind/mgr: ceph osd status crash with ZeroDivisionError If stats-update is called a second time within a second, get_rate() fails with a 'divide by 0' error. Change the check before the computation, taking into account the fact that two f.p numbers may differ, but still their diff - when cast into an int - might be zero. Fixed: https://tracker.ceph.com/issues/53538 Signed-off-by: Nitzan Mordechai (cherry picked from commit 140b7ce529f23ae429e71dfc1ad0deef13174e88) --- src/pybind/mgr/status/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pybind/mgr/status/module.py b/src/pybind/mgr/status/module.py index 879ab29cf073a..c57e6179e8241 100644 --- a/src/pybind/mgr/status/module.py +++ b/src/pybind/mgr/status/module.py @@ -24,7 +24,7 @@ class Module(MgrModule): def get_rate(self, daemon_type: str, daemon_name: str, stat: str) -> int: data = self.get_counter(daemon_type, daemon_name, stat)[stat] - if data and len(data) > 1 and data[-1][0] != data[-2][0]: + if data and len(data) > 1 and (int(data[-1][0] - data[-2][0]) != 0): return (data[-1][1] - data[-2][1]) // int(data[-1][0] - data[-2][0]) else: return 0 -- 2.39.5