diff options
-rw-r--r-- | src/pybind/mgr/balancer/module.py | 3 | ||||
-rw-r--r-- | src/pybind/mgr/dashboard/controllers/prometheus.py | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 7a43b7ce220..ea5455ea3ea 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -324,6 +324,7 @@ class Module(MgrModule): last_optimize_started = '' last_optimize_duration = '' optimize_result = '' + no_optimization_needed = False success_string = 'Optimization plan created successfully' in_progress_string = 'in progress' @@ -342,6 +343,7 @@ class Module(MgrModule): 'last_optimize_started': self.last_optimize_started, 'last_optimize_duration': self.last_optimize_duration, 'optimize_result': self.optimize_result, + 'no_optimization_needed': self.no_optimization_needed, 'mode': self.get_module_option('mode'), } return (0, json.dumps(s, indent=4, sort_keys=True), '') @@ -1037,6 +1039,7 @@ class Module(MgrModule): break self.log.info('prepared %d/%d changes' % (total_did, max_optimizations)) if total_did == 0: + self.no_optimization_needed = True return -errno.EALREADY, 'Unable to find further optimization, ' \ 'or pool(s) pg_num is decreasing, ' \ 'or distribution is already perfect' diff --git a/src/pybind/mgr/dashboard/controllers/prometheus.py b/src/pybind/mgr/dashboard/controllers/prometheus.py index af90f0d6008..ae4abfc1668 100644 --- a/src/pybind/mgr/dashboard/controllers/prometheus.py +++ b/src/pybind/mgr/dashboard/controllers/prometheus.py @@ -7,6 +7,7 @@ import requests from ..exceptions import DashboardException from ..security import Scope +from ..services import ceph_service from ..settings import Settings from . import APIDoc, APIRouter, BaseController, Endpoint, RESTController, Router @@ -41,6 +42,9 @@ class PrometheusRESTController(RESTController): def _get_api_url(self, host): return host.rstrip('/') + '/api/v1' + def balancer_status(self): + return ceph_service.CephService.send_command('mon', 'balancer status') + def _proxy(self, base_url, method, path, api_name, params=None, payload=None, verify=True): # type (str, str, str, str, dict, dict, bool) try: @@ -57,8 +61,16 @@ class PrometheusRESTController(RESTController): raise DashboardException( "Error parsing Prometheus Alertmanager response: {}".format(e.msg), component='prometheus') - if content['status'] == 'success': + balancer_status = self.balancer_status() + if content['status'] == 'success': # pylint: disable=R1702 if 'data' in content: + if balancer_status['active'] and balancer_status['no_optimization_needed'] and path == '/alerts': # noqa E501 #pylint: disable=line-too-long + for alert in content['data']: + for k, v in alert.items(): + if k == 'labels': + for key, value in v.items(): + if key == 'alertname' and value == 'CephPGImbalance': + content['data'].remove(alert) return content['data'] return content raise DashboardException(content, http_status_code=400, component='prometheus') |