summaryrefslogtreecommitdiff
path: root/nova/objects/monitor_metric.py
diff options
context:
space:
mode:
authorSurojit Pathak <suro@yahoo-inc.com>2015-11-25 19:21:24 +0000
committerMohammed Naser <mnaser@vexxhost.com>2016-03-31 18:18:17 +0000
commitc0dfe42382262f044471d0a852c6b724e8e81ad8 (patch)
treec7ccc048e75c296182cf458fd9a14d453bc59a97 /nova/objects/monitor_metric.py
parentacb2dc5e27a85b9148599f1c4dd59e317752f125 (diff)
downloadnova-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)
Diffstat (limited to 'nova/objects/monitor_metric.py')
-rw-r--r--nova/objects/monitor_metric.py14
1 files changed, 12 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