Change in vdsm[ovirt-3.6]: virt: stats: make _disk_iops_bytes more robust

fromani at redhat.com fromani at redhat.com
Wed Feb 24 15:28:11 UTC 2016


Hello Nir Soffer, Martin Polednik,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/53997

to review the following change.

Change subject: virt: stats: make _disk_iops_bytes more robust
......................................................................

virt: stats: make _disk_iops_bytes more robust

Make reporting of iops and bytes more robust and less noisy
when some fields are missing from bulk stats.
This can happen, so we must handle this case silently.

Since this patch fixes the last possible source of
KeyErrors, is now possible to unbreak existing related
vmStatsTests.

Backport-To: 3.6
Change-Id: I341779e2629a1122e4c0fa55206ad404f3eb2f48
Bug-Url: https://bugzilla.redhat.com/1281337
Signed-off-by: Francesco Romani <fromani at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/50594
Continuous-Integration: Jenkins CI
Reviewed-by: Martin Polednik <mpolednik at redhat.com>
Reviewed-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/vmStatsTests.py
M vdsm/virt/vmstats.py
2 files changed, 14 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/97/53997/1

diff --git a/tests/vmStatsTests.py b/tests/vmStatsTests.py
index 16ddb8d..26b29e8 100644
--- a/tests/vmStatsTests.py
+++ b/tests/vmStatsTests.py
@@ -23,8 +23,6 @@
 
 from virt import vmstats
 
-from testValidation import brokentest
-
 from testlib import VdsmTestCase as TestCaseBase
 from testlib import permutations, expandPermutations
 
@@ -426,7 +424,6 @@
                                          stats['disks'],
                                          expected_keys)
 
-    @brokentest
     def test_disk_missing_rate(self):
         partial_stats = self._drop_stats(
             ('block.0.rd.bytes', 'block.1.rd.bytes',
@@ -442,7 +439,6 @@
                              partial_stats, partial_stats,
                              interval)
 
-    @brokentest
     def test_disk_missing_latency(self):
         partial_stats = self._drop_stats(
             ('block.0.rd.times', 'block.1.rd.times',
diff --git a/vdsm/virt/vmstats.py b/vdsm/virt/vmstats.py
index f29d195..5c3496f 100644
--- a/vdsm/virt/vmstats.py
+++ b/vdsm/virt/vmstats.py
@@ -347,12 +347,20 @@
 
 
 def _disk_iops_bytes(first_sample, first_index, last_sample, last_index):
-    return {
-        'readOps': str(last_sample['block.%d.rd.reqs' % last_index]),
-        'writeOps': str(last_sample['block.%d.wr.reqs' % last_index]),
-        'readBytes': str(last_sample['block.%d.rd.bytes' % last_index]),
-        'writtenBytes': str(last_sample['block.%d.wr.bytes' % last_index]),
-    }
+    stats = {}
+
+    for name, mode, field in (('readOps', 'rd', 'reqs'),
+                              ('writeOps', 'wr', 'reqs'),
+                              ('readBytes', 'rd', 'bytes'),
+                              ('writtenBytes', 'wr', 'bytes')):
+        key = 'block.%d.%s.%s' % (last_index, mode, field)
+        try:
+            value = last_sample[key]
+        except KeyError:
+            continue
+        stats[name] = str(value)
+
+    return stats
 
 
 def _diff(prev, curr, val):


-- 
To view, visit https://gerrit.ovirt.org/53997
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I341779e2629a1122e4c0fa55206ad404f3eb2f48
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Martin Polednik <mpolednik at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list