Skip to content

Commit 9d87fa2

Browse files
authored
Merge pull request kubernetes#124735 from AxeZhan/evaluatedNodes
Change EvaluatedNodes to count Nodes that reach Filter phase only
2 parents df074ed + bcf1c55 commit 9d87fa2

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

pkg/scheduler/framework/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ type Diagnosis struct {
337337
PreFilterMsg string
338338
// PostFilterMsg records the messages returned from PostFilter plugins.
339339
PostFilterMsg string
340+
// EvaluatedNodes records the number of nodes evaluated by Filter stage.
341+
// It is used for debugging purposes only.
342+
EvaluatedNodes int
340343
}
341344

342345
// FitError describes a fit error of a pod.

pkg/scheduler/schedule_one.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (sched *Scheduler) schedulePod(ctx context.Context, fwk framework.Framework
417417
if len(feasibleNodes) == 1 {
418418
return ScheduleResult{
419419
SuggestedHost: feasibleNodes[0].Node().Name,
420-
EvaluatedNodes: 1 + len(diagnosis.NodeToStatusMap),
420+
EvaluatedNodes: diagnosis.EvaluatedNodes,
421421
FeasibleNodes: 1,
422422
}, nil
423423
}
@@ -432,7 +432,7 @@ func (sched *Scheduler) schedulePod(ctx context.Context, fwk framework.Framework
432432

433433
return ScheduleResult{
434434
SuggestedHost: host,
435-
EvaluatedNodes: len(feasibleNodes) + len(diagnosis.NodeToStatusMap),
435+
EvaluatedNodes: diagnosis.EvaluatedNodes,
436436
FeasibleNodes: len(feasibleNodes),
437437
}, err
438438
}
@@ -594,6 +594,7 @@ func (sched *Scheduler) findNodesThatPassFilters(
594594
for i := range feasibleNodes {
595595
feasibleNodes[i] = nodes[(sched.nextStartNodeIndex+i)%numAllNodes]
596596
}
597+
diagnosis.EvaluatedNodes = int(numNodesToFind)
597598
return feasibleNodes, nil
598599
}
599600

@@ -642,11 +643,13 @@ func (sched *Scheduler) findNodesThatPassFilters(
642643
// are found.
643644
fwk.Parallelizer().Until(ctx, numAllNodes, checkNode, metrics.Filter)
644645
feasibleNodes = feasibleNodes[:feasibleNodesLen]
646+
diagnosis.EvaluatedNodes = int(feasibleNodesLen)
645647
for _, item := range result {
646648
if item == nil {
647649
continue
648650
}
649651
diagnosis.NodeToStatusMap[item.node] = item.status
652+
diagnosis.EvaluatedNodes++
650653
diagnosis.AddPluginStatus(item.status)
651654
}
652655
if err := errCh.ReceiveError(); err != nil {

pkg/scheduler/schedule_one_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ func TestSchedulerNoPhantomPodAfterDelete(t *testing.T) {
935935
node.Name: framework.NewStatus(framework.Unschedulable, nodeports.ErrReason).WithPlugin(nodeports.Name),
936936
},
937937
UnschedulablePlugins: sets.New(nodeports.Name),
938+
EvaluatedNodes: 1,
938939
},
939940
}
940941
if !reflect.DeepEqual(expectErr, err) {
@@ -1042,6 +1043,7 @@ func TestSchedulerFailedSchedulingReasons(t *testing.T) {
10421043
Diagnosis: framework.Diagnosis{
10431044
NodeToStatusMap: failedNodeStatues,
10441045
UnschedulablePlugins: sets.New(noderesources.Name),
1046+
EvaluatedNodes: 100,
10451047
},
10461048
}
10471049
if len(fmt.Sprint(expectErr)) > 150 {
@@ -1829,6 +1831,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
18291831
"node2": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("FalseFilter"),
18301832
},
18311833
UnschedulablePlugins: sets.New("FalseFilter"),
1834+
EvaluatedNodes: 2,
18321835
},
18331836
},
18341837
},
@@ -1919,6 +1922,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
19191922
"1": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("FalseFilter"),
19201923
},
19211924
UnschedulablePlugins: sets.New("FalseFilter"),
1925+
EvaluatedNodes: 3,
19221926
},
19231927
},
19241928
},
@@ -1945,6 +1949,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
19451949
"2": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("NoPodsFilter"),
19461950
},
19471951
UnschedulablePlugins: sets.New("MatchFilter", "NoPodsFilter"),
1952+
EvaluatedNodes: 2,
19481953
},
19491954
},
19501955
},
@@ -2110,6 +2115,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
21102115
"3": framework.NewStatus(framework.Unschedulable, "injecting failure for pod test-filter").WithPlugin("FakeFilter"),
21112116
},
21122117
UnschedulablePlugins: sets.New("FakeFilter"),
2118+
EvaluatedNodes: 1,
21132119
},
21142120
},
21152121
},
@@ -2143,6 +2149,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
21432149
"3": framework.NewStatus(framework.Unschedulable, "injecting failure for pod test-filter").WithPlugin("FakeFilter"),
21442150
},
21452151
UnschedulablePlugins: sets.New("FakeFilter", framework.ExtenderName),
2152+
EvaluatedNodes: 3,
21462153
},
21472154
},
21482155
},
@@ -2168,6 +2175,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
21682175
"3": framework.NewStatus(framework.UnschedulableAndUnresolvable, "injecting failure for pod test-filter").WithPlugin("FakeFilter"),
21692176
},
21702177
UnschedulablePlugins: sets.New("FakeFilter"),
2178+
EvaluatedNodes: 1,
21712179
},
21722180
},
21732181
},
@@ -2249,7 +2257,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
22492257
nodes: []string{"node1", "node2", "node3"},
22502258
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
22512259
wantNodes: sets.New("node2"),
2252-
wantEvaluatedNodes: ptr.To[int32](3),
2260+
wantEvaluatedNodes: ptr.To[int32](1),
22532261
},
22542262
{
22552263
name: "test prefilter plugin returning non-intersecting nodes",
@@ -2338,6 +2346,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
23382346
"node2": framework.NewStatus(framework.Unschedulable, "injecting failure for pod test-prefilter").WithPlugin("FakeFilter"),
23392347
},
23402348
UnschedulablePlugins: sets.New("FakeFilter"),
2349+
EvaluatedNodes: 1,
23412350
PreFilterMsg: "",
23422351
},
23432352
},
@@ -2416,10 +2425,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
24162425
),
24172426
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
24182427
},
2419-
nodes: []string{"node1", "node2", "node3"},
2420-
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
2421-
wantNodes: sets.New("node1", "node2"),
2422-
wantEvaluatedNodes: ptr.To[int32](2),
2428+
nodes: []string{"node1", "node2", "node3"},
2429+
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
2430+
wantNodes: sets.New("node1", "node2"),
2431+
// since this case has no score plugin, we'll only try to find one node in Filter stage
2432+
wantEvaluatedNodes: ptr.To[int32](1),
24232433
},
24242434
}
24252435
for _, test := range tests {
@@ -2483,7 +2493,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
24832493
if gotOK != wantOK {
24842494
t.Errorf("Expected err to be FitError: %v, but got %v (error: %v)", wantOK, gotOK, err)
24852495
} else if gotOK {
2486-
if diff := cmp.Diff(gotFitErr, wantFitErr); diff != "" {
2496+
if diff := cmp.Diff(wantFitErr, gotFitErr); diff != "" {
24872497
t.Errorf("Unexpected fitErr: (-want, +got): %s", diff)
24882498
}
24892499
}
@@ -2536,6 +2546,7 @@ func TestFindFitAllError(t *testing.T) {
25362546
"3": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("MatchFilter"),
25372547
},
25382548
UnschedulablePlugins: sets.New("MatchFilter"),
2549+
EvaluatedNodes: 3,
25392550
}
25402551
if diff := cmp.Diff(diagnosis, expected); diff != "" {
25412552
t.Errorf("Unexpected diagnosis: (-want, +got): %s", diff)

0 commit comments

Comments
 (0)