From 13cdf9c232ff16e0a44daeefc02a45bc94d946e9 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Wed, 23 Oct 2019 17:00:14 -0700 Subject: [PATCH] mgr: Improve balancer module status Add balancer status fields so that slow optimizations can be detected Signed-off-by: David Zafman (cherry picked from commit f04c505b9dc128bdfbcca49d82f8aac4abf8b56f) --- src/pybind/mgr/balancer/module.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index b53831c61000b..5854bc2003fff 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -13,6 +13,7 @@ import time from mgr_module import MgrModule, CommandResult from threading import Event from mgr_module import CRUSHMap +import datetime # available modes: 'none', 'crush', 'crush-compat', 'upmap', 'osd_weight' default_mode = 'none' @@ -291,6 +292,11 @@ class Module(MgrModule): plans = {} mode = '' optimizing = False + last_optimize_started = '' + last_optimize_duration = '' + optimize_result = '' + success_string = 'Optimization plan created successfully' + in_progress_string = 'in progress' def __init__(self, *args, **kwargs): super(Module, self).__init__(*args, **kwargs) @@ -302,6 +308,9 @@ class Module(MgrModule): s = { 'plans': list(self.plans.keys()), 'active': self.active, + 'last_optimize_started': self.last_optimize_started, + 'last_optimize_duration': self.last_optimize_duration, + 'optimize_result': self.optimize_result, 'mode': self.get_config('mode', default_mode), } return (0, json.dumps(s, indent=4), '') @@ -368,10 +377,18 @@ class Module(MgrModule): if len(invalid_pool_names): return (-errno.EINVAL, '', 'pools %s not found' % invalid_pool_names) plan = self.plan_create(command['plan'], osdmap, pools) + self.last_optimize_started = time.asctime(time.localtime()) + self.optimize_result = self.in_progress_string + start = time.time() r, detail = self.optimize(plan) - # Add plan if an optimization was created - if not r: + end = time.time() + self.last_optimize_duration = str(datetime.timedelta(seconds=(end - start))) + if r == 0: + # Add plan if an optimization was created + self.optimize_result = self.success_string self.plans[command['plan']] = plan + else: + self.optimize_result = detail return (r, '', detail) elif command['prefix'] == 'balancer rm': self.plan_rm(command['plan']) @@ -456,9 +473,17 @@ class Module(MgrModule): name = 'auto_%s' % time.strftime(TIME_FORMAT, time.gmtime()) plan = self.plan_create(name, self.get_osdmap(), []) self.optimizing = True + self.last_optimize_started = time.asctime(time.localtime()) + self.optimize_result = self.in_progress_string + start = time.time() r, detail = self.optimize(plan) + end = time.time() + self.last_optimize_duration = str(datetime.timedelta(seconds=(end - start))) if r == 0: + self.optimize_result = self.success_string self.execute(plan) + else: + self.optimize_result = detail self.optimizing = False self.log.debug('Sleeping for %d', sleep_interval) self.event.wait(sleep_interval) -- 2.39.5