From: Afreen Date: Wed, 6 Mar 2024 20:22:16 +0000 (+0530) Subject: mgr/dashboard: handle infinite values for pools X-Git-Tag: v20.0.0~2441^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=82d100ad264c35d79262c1983a8005d8d4791855;p=ceph.git mgr/dashboard: handle infinite values for pools Fixes https://tracker.ceph.com/issues/64724 Issue: ====== Json parsing is failing because of Infinity values present in pools meteadata. "read_balance": {"score_acting": Infinity, "score_stable": Infinity,} Due to this entire pool list is not rendered. Fix: ==== Added a handler for checking "inf" values and replacing them with a string "Infinity" so that json parsing does not fail on frontend. Signed-off-by: Afreen --- diff --git a/src/pybind/mgr/dashboard/controllers/pool.py b/src/pybind/mgr/dashboard/controllers/pool.py index 1e2e04e1b14da..9310d2f97aab1 100644 --- a/src/pybind/mgr/dashboard/controllers/pool.py +++ b/src/pybind/mgr/dashboard/controllers/pool.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import math import time from typing import Any, Dict, Iterable, List, Optional, Union, cast @@ -101,7 +102,7 @@ class Pool(RESTController): crush_rules = {r['rule_id']: r["rule_name"] for r in mgr.get('osd_map_crush')['rules']} - res: Dict[Union[int, str], Union[str, List[Any]]] = {} + res: Dict[Union[int, str], Union[str, List[Any], Dict[str, Any]]] = {} for attr in attrs: if attr not in pool: continue @@ -111,6 +112,15 @@ class Pool(RESTController): res[attr] = crush_rules[pool[attr]] elif attr == 'application_metadata': res[attr] = list(pool[attr].keys()) + # handle infinity values + elif attr == 'read_balance' and isinstance(pool[attr], dict): + read_balance: Dict[str, Any] = {} + for key, value in pool[attr].items(): + if isinstance(value, float) and math.isinf(value): + read_balance[key] = "Infinity" + else: + read_balance[key] = value + res[attr] = read_balance else: res[attr] = pool[attr]