From 95fb45e8ad54b51518b4ebfdd3840d6710234626 Mon Sep 17 00:00:00 2001 From: Nizamudeen A Date: Tue, 26 Apr 2022 15:49:09 +0530 Subject: [PATCH] mgr/dashboard: prometheus rules internal server error After we increase/decrease the count of the node-exporter, we get a 500 - Internal server error from api/prometheus/rules endpoint. On further debugging its caused by the jsonDecodder, because I guess the expected input for the json.loads() is not a json formatted input. So to fix that issue I can either do an error handling on the json.loads() or I can move the json.loads() on the already existing try block. I went for the second approach here. Fixes: https://tracker.ceph.com/issues/54356 Signed-off-by: Nizamudeen A (cherry picked from commit 672e27cbd2d66f87afa5e9e33537f333eadfb243) --- src/pybind/mgr/dashboard/controllers/prometheus.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/controllers/prometheus.py b/src/pybind/mgr/dashboard/controllers/prometheus.py index f1dae7f1a2fa2..af90f0d600888 100644 --- a/src/pybind/mgr/dashboard/controllers/prometheus.py +++ b/src/pybind/mgr/dashboard/controllers/prometheus.py @@ -51,7 +51,12 @@ class PrometheusRESTController(RESTController): "Could not reach {}'s API on {}".format(api_name, base_url), http_status_code=404, component='prometheus') - content = json.loads(response.content) + try: + content = json.loads(response.content, strict=False) + except json.JSONDecodeError as e: + raise DashboardException( + "Error parsing Prometheus Alertmanager response: {}".format(e.msg), + component='prometheus') if content['status'] == 'success': if 'data' in content: return content['data'] -- 2.39.5