diff options
author | Surojit Pathak <suro@yahoo-inc.com> | 2015-11-25 19:21:24 +0000 |
---|---|---|
committer | Mohammed Naser <mnaser@vexxhost.com> | 2016-03-31 18:18:17 +0000 |
commit | c0dfe42382262f044471d0a852c6b724e8e81ad8 (patch) | |
tree | c7ccc048e75c296182cf458fd9a14d453bc59a97 | |
parent | acb2dc5e27a85b9148599f1c4dd59e317752f125 (diff) | |
download | nova-c0dfe42382262f044471d0a852c6b724e8e81ad8.tar.gz |
Fix wrong CPU metric value in metrics_filter
CPU metrics are reported as a normalized value in [0,1].
When scheduler reads the data as MonitorMetric object, as part
of update_from_compute_node(), the value of the metric gets
lost due to a wrong type conversion, typecasting into an Integer,
reduces it to 0.
Note:
- It may seem unintuitive that to fix the same, we are not changing
the type of metric from Integer to Float. Please refer the
discussions -
* https://review.openstack.org/#/c/243825/
* https://review.openstack.org/#/c/216923/
- To summarize, we are trying to save some 'possible' downstream consumer
of metrics updates from compute nodes, i.e. consuming from AMPQ, from
software upgrade scenarios.
Change-Id: Ib504af33e05dfc4d7e97b52682e27befc67d784a
Closes-bug: #1514997
(cherry picked from commit ddb3c4e26f3a908de7836a8fac48360afa6aa1d7)
-rw-r--r-- | nova/objects/monitor_metric.py | 14 | ||||
-rw-r--r-- | nova/tests/unit/objects/test_monitor_metric.py | 12 |
2 files changed, 24 insertions, 2 deletions
diff --git a/nova/objects/monitor_metric.py b/nova/objects/monitor_metric.py index 7d6c350a41..0ad599b366 100644 --- a/nova/objects/monitor_metric.py +++ b/nova/objects/monitor_metric.py @@ -97,8 +97,18 @@ class MonitorMetricList(base.ObjectListBase, base.NovaObject): :returns: a MonitorMetricList Object. """ metrics = jsonutils.loads(metrics) if metrics else [] - metric_list = [ - MonitorMetric(**metric) for metric in metrics] + + # NOTE(suro-patz): While instantiating the MonitorMetric() from + # JSON-ified string, we need to re-convert the + # normalized metrics to avoid truncation to 0 by + # typecasting into an integer. + metric_list = [] + for metric in metrics: + if ('value' in metric and metric['name'] in + FIELDS_REQUIRING_CONVERSION): + metric['value'] = metric['value'] * 100 + metric_list.append(MonitorMetric(**metric)) + return MonitorMetricList(objects=metric_list) # NOTE(jaypipes): This method exists to convert the object to the diff --git a/nova/tests/unit/objects/test_monitor_metric.py b/nova/tests/unit/objects/test_monitor_metric.py index 30cea2ded7..a1df3ef2f0 100644 --- a/nova/tests/unit/objects/test_monitor_metric.py +++ b/nova/tests/unit/objects/test_monitor_metric.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_serialization import jsonutils from oslo_utils import timeutils from nova import objects @@ -73,6 +74,17 @@ class _TestMonitorMetricObject(object): source='nova.virt.libvirt.driver') self.assertEqual(_monitor_numa_metric_spec, obj.to_dict()) + def test_conversion_in_monitor_metric_list_from_json(self): + spec_list = [_monitor_metric_spec, _monitor_metric_perc_spec] + metrics = objects.MonitorMetricList.from_json( + jsonutils.dumps(spec_list)) + for metric, spec in zip(metrics, spec_list): + exp = spec['value'] + if (spec['name'] in + objects.monitor_metric.FIELDS_REQUIRING_CONVERSION): + exp = spec['value'] * 100 + self.assertEqual(exp, metric.value) + class TestMonitorMetricObject(test_objects._LocalTest, _TestMonitorMetricObject): |