Skip to content

Commit

Permalink
mgr/devicehealth: factor _get_device_metrics out of show_device_metrics
Browse files Browse the repository at this point in the history
Add the min_sample lower-bound argument too

Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Oct 4, 2019
1 parent 2f1670e commit 7be5c13
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/pybind/mgr/devicehealth/module.py
Expand Up @@ -418,16 +418,11 @@ def put_device_metrics(self, ioctx, devid, data):
ioctx.remove_omap_keys(op, tuple(erase))
ioctx.operate_write_op(op, devid)

def show_device_metrics(self, devid, sample):
# verify device exists
r = self.get("device " + devid)
if not r or 'device' not in r.keys():
return -errno.ENOENT, '', 'device ' + devid + ' not found'
# fetch metrics
def _get_device_metrics(self, devid, sample=None, min_sample=None):
res = {}
ioctx = self.open_connection(create_if_missing=False)
if not ioctx:
return 0, json.dumps(res, indent=4), ''
return {}
with ioctx:
with rados.ReadOpCtx() as op:
omap_iter, ret = ioctx.get_omap_vals(op, "", sample or '',
Expand All @@ -438,6 +433,8 @@ def show_device_metrics(self, devid, sample):
for key, value in list(omap_iter):
if sample and key != sample:
break
if min_sample and key < min_sample:
break
try:
v = json.loads(value)
except (ValueError, IndexError):
Expand All @@ -450,7 +447,15 @@ def show_device_metrics(self, devid, sample):
except rados.Error as e:
self.log.exception("RADOS error reading omap: {0}".format(e))
raise
return res

def show_device_metrics(self, devid, sample):
# verify device exists
r = self.get("device " + devid)
if not r or 'device' not in r.keys():
return -errno.ENOENT, '', 'device ' + devid + ' not found'
# fetch metrics
res = self._get_device_metrics(devid, sample=sample)
return 0, json.dumps(res, indent=4, sort_keys=True), ''

def check_health(self):
Expand Down

0 comments on commit 7be5c13

Please sign in to comment.