Skip to content

Commit

Permalink
Merge pull request #48525 from rhcs-dashboard/fix-PgImbalance-alert
Browse files Browse the repository at this point in the history
mgr/dashboard: fix CephPGImbalance alert

Reviewed-by: Avan Thakkar <athakkar@redhat.com>
Reviewed-by: Ernesto Puerta <epuertat@redhat.com>
Reviewed-by: Nizamudeen A <nia@redhat.com>
Reviewed-by: Tatjana Dehler <tdehler@suse.com>
  • Loading branch information
nizamial09 committed Nov 29, 2022
2 parents 3f1c1b6 + a75792d commit 559f151
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/pybind/mgr/balancer/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -342,6 +343,7 @@ def show_status(self) -> Tuple[int, str, str]:
'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), '')
Expand Down Expand Up @@ -1037,6 +1039,7 @@ def do_upmap(self, plan: Plan) -> Tuple[int, str]:
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'
Expand Down
14 changes: 13 additions & 1 deletion src/pybind/mgr/dashboard/controllers/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

Expand Down Expand Up @@ -41,6 +42,9 @@ def alert_proxy(self, method, path, params=None, payload=None):
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:
Expand All @@ -57,8 +61,16 @@ def _proxy(self, base_url, method, path, api_name, params=None, payload=None, ve
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')
Expand Down

0 comments on commit 559f151

Please sign in to comment.