@@ -217,14 +217,19 @@ func (s *StepMonitor) Run(request api.Request) (map[string]float64, error) {
217
217
defer timer .ObserveDuration ()
218
218
}
219
219
220
- weights , err := s .Step .Run (request )
220
+ inWeights := request .GetWeights ()
221
+ outWeights , err := s .Step .Run (request )
221
222
if err != nil {
222
223
return nil , err
223
224
}
225
+ slog .Info (
226
+ "scheduler: finished step" , "name" , stepName ,
227
+ "inWeights" , inWeights , "outWeights" , outWeights ,
228
+ )
224
229
225
230
// Observe how much the step modifies the weights of the hosts.
226
231
if s .stepHostWeight != nil {
227
- for host , weight := range weights {
232
+ for host , weight := range outWeights {
228
233
s .stepHostWeight .WithLabelValues (host , stepName ).Add (weight )
229
234
if weight != 0.0 {
230
235
slog .Info ("scheduler: modified host weight" , "name" , stepName , "weight" , weight )
@@ -233,11 +238,9 @@ func (s *StepMonitor) Run(request api.Request) (map[string]float64, error) {
233
238
}
234
239
235
240
// Observe how many hosts are removed from the state.
236
- hostsInScenario := make (map [string ]struct {})
237
- for _ , host := range request .GetHosts () {
238
- hostsInScenario [host ] = struct {}{}
239
- }
240
- nHostsRemoved := len (hostsInScenario ) - len (weights )
241
+ hostsIn := request .GetHosts ()
242
+ hostsOut := slices .Collect (maps .Keys (outWeights ))
243
+ nHostsRemoved := len (hostsIn ) - len (hostsOut )
241
244
if nHostsRemoved < 0 {
242
245
slog .Info ("scheduler: removed hosts" , "name" , stepName , "count" , nHostsRemoved )
243
246
}
@@ -248,14 +251,19 @@ func (s *StepMonitor) Run(request api.Request) (map[string]float64, error) {
248
251
// Observe the number of reorderings conducted by the scheduler.
249
252
if s .reorderingsObserver != nil {
250
253
// Calculate the Levenshtein distance between the hosts going in and out.
251
- hosts := slices .Collect (maps .Keys (weights ))
252
- sort .Slice (hosts , func (i , j int ) bool {
253
- return weights [hosts [i ]] > weights [hosts [j ]]
254
+ sort .Slice (hostsIn , func (i , j int ) bool {
255
+ return inWeights [hostsIn [i ]] > inWeights [hostsIn [j ]]
256
+ })
257
+ sort .Slice (hostsOut , func (i , j int ) bool {
258
+ return outWeights [hostsOut [i ]] > outWeights [hostsOut [j ]]
254
259
})
255
- distance := levenshteinDistance (request .GetHosts (), hosts )
256
- slog .Info ("scheduler: reorderings" , "name" , stepName , "distance" , distance , "hosts_in" , request .GetHosts (), "hosts_out" , hosts )
260
+ distance := levenshteinDistance (hostsIn , hostsOut )
261
+ slog .Info (
262
+ "scheduler: reorderings" , "name" , stepName , "distance" , distance ,
263
+ "hostsIn" , hostsIn , "hostsOut" , hostsOut ,
264
+ )
257
265
s .reorderingsObserver .Observe (float64 (distance ))
258
266
}
259
267
260
- return weights , nil
268
+ return outWeights , nil
261
269
}
0 commit comments