Francesco Romani has uploaded a new change for review.
Change subject: vmstats: do not catch unlikely ZeroDivisionError
......................................................................
vmstats: do not catch unlikely ZeroDivisionError
Nowadays, the only foreseeable reason to have ZeroDivisionError
in the vmstats functions, is when interval is zero.
This case is in turn very very unlikely, as it should
happen only in the extravagant case of two polling cycles racing
together, saving bad bugs in the sampling code.
So, drop the ZeroDivisionError from the handled
exception, and we add an explicit guard to be sure
we record these end-of-the-world-like cases.
Change-Id: I6c6719414d185a8b359b5d8a9f4a28ac87b64327
Signed-off-by: Francesco Romani <fromani(a)redhat.com>
---
M vdsm/virt/vmstats.py
1 file changed, 17 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/16/40916/1
diff --git a/vdsm/virt/vmstats.py b/vdsm/virt/vmstats.py
index 4af8501..11feead 100644
--- a/vdsm/virt/vmstats.py
+++ b/vdsm/virt/vmstats.py
@@ -74,6 +74,11 @@
if first_sample is None or last_sample is None:
return
+ if interval <= 0:
+ logging.warning(
+ 'invalid interval %i when computing CPU stats',
+ interval)
+ return
stats['cpuUsage'] = str(last_sample['system_time']
+ last_sample['user_time'])
@@ -88,7 +93,7 @@
- _diff(last_sample, first_sample, 'cpu.system'),
interval)
- except (KeyError, TypeError, ZeroDivisionError) as e:
+ except (KeyError, TypeError) as e:
logging.exception("CPU stats not available: %s", e)
@@ -206,10 +211,16 @@
last_disk = last_sample.get('block', {}).get(vm_drive.name, {})
if first_disk and last_disk:
# will be None if sampled during recovery
- drive_stats.update(
- _disk_rate(first_disk, last_disk, interval))
- drive_stats.update(
- _disk_latency(first_disk, last_disk))
+ if interval > 0:
+ drive_stats.update(
+ _disk_rate(first_disk, last_disk, interval))
+ drive_stats.update(
+ _disk_latency(first_disk, last_disk))
+ else:
+ logging.warning(
+ 'invalid interval %i when calculating '
+ 'stats for vm %s disk %s',
+ interval, vm.id, vm_drive.name)
drive_info = last_sample[vm_drive.name]
drive_stats['readOps'] = str(drive_info['rd.reqs'])
@@ -217,7 +228,7 @@
drive_stats['readBytes'] = str(drive_info['rd.bytes'])
drive_stats['writtenBytes'] =
str(drive_info['wr.bytes'])
- except (AttributeError, TypeError, ZeroDivisionError):
+ except (AttributeError, TypeError):
logging.exception("Disk %s stats not available",
vm_drive.name)
--
To view, visit
https://gerrit.ovirt.org/40916
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c6719414d185a8b359b5d8a9f4a28ac87b64327
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani(a)redhat.com>