From 51421d85b89e9611a627b267d13864d32454bcef Mon Sep 17 00:00:00 2001 From: Afreen Date: Thu, 7 Mar 2024 01:52:16 +0530 Subject: [PATCH] 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 (cherry picked from commit 82d100ad264c35d79262c1983a8005d8d4791855) --- src/pybind/mgr/dashboard/controllers/pool.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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] -- 2.39.5