Skip to content

Commit 2b88b6a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add debug log for scheduler weight calculation"
2 parents 4ddd8bb + 154ab7b commit 2b88b6a

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

nova/weights.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919

2020
import abc
2121

22+
from oslo_log import log as logging
23+
2224
from nova import loadables
2325

2426

27+
LOG = logging.getLogger(__name__)
28+
29+
2530
def normalize(weight_list, minval=None, maxval=None):
2631
"""Normalize the values in a list between 0 and 1.0.
2732
@@ -128,13 +133,40 @@ def get_weighed_objects(self, weighers, obj_list, weighing_properties):
128133
for weigher in weighers:
129134
weights = weigher.weigh_objects(weighed_objs, weighing_properties)
130135

136+
LOG.debug(
137+
"%s: raw weights %s",
138+
weigher.__class__.__name__,
139+
{(obj.obj.host, obj.obj.nodename): weight
140+
for obj, weight in zip(weighed_objs, weights)}
141+
)
142+
131143
# Normalize the weights
132-
weights = normalize(weights,
133-
minval=weigher.minval,
134-
maxval=weigher.maxval)
144+
weights = list(
145+
normalize(
146+
weights, minval=weigher.minval, maxval=weigher.maxval))
147+
148+
LOG.debug(
149+
"%s: normalized weights %s",
150+
weigher.__class__.__name__,
151+
{(obj.obj.host, obj.obj.nodename): weight
152+
for obj, weight in zip(weighed_objs, weights)}
153+
)
154+
155+
log_data = {}
135156

136157
for i, weight in enumerate(weights):
137158
obj = weighed_objs[i]
138-
obj.weight += weigher.weight_multiplier(obj.obj) * weight
159+
multiplier = weigher.weight_multiplier(obj.obj)
160+
weigher_score = multiplier * weight
161+
obj.weight += weigher_score
162+
163+
log_data[(obj.obj.host, obj.obj.nodename)] = (
164+
f"{multiplier} * {weight}")
165+
166+
LOG.debug(
167+
"%s: score (multiplier * weight) %s",
168+
weigher.__class__.__name__,
169+
{name: log for name, log in log_data.items()}
170+
)
139171

140172
return sorted(weighed_objs, key=lambda x: x.weight, reverse=True)

0 commit comments

Comments
 (0)