]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: fix CephPGImbalance alert
authorAashish Sharma <aasharma@redhat.com>
Thu, 15 Sep 2022 12:32:29 +0000 (18:02 +0530)
committerAashish Sharma <aasharma@redhat.com>
Tue, 22 Nov 2022 05:08:56 +0000 (10:38 +0530)
Donot show the CephPgImbalance alert if the balancer shows no optimization required

Fixes: https://tracker.ceph.com/issues/55568
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
src/pybind/mgr/balancer/module.py
src/pybind/mgr/dashboard/controllers/prometheus.py

index d313bc4de848dc801a79ac9582a4dd2276210926..19d4b09cfe539a76d1e723fcf30038e1c61c5b79 100644 (file)
@@ -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), '')
@@ -1023,6 +1025,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'
index af90f0d60088866045729debcedda8afa2239a24..ae4abfc1668859529111e9b4cc526981b39ca077 100644 (file)
@@ -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')