Skip to content

Commit

Permalink
evaluated nodes only consider filter stage
Browse files Browse the repository at this point in the history
  • Loading branch information
AxeZhan committed May 8, 2024
1 parent 48dbcf6 commit 7030d89
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions pkg/scheduler/framework/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ type Diagnosis struct {
PreFilterMsg string
// PostFilterMsg records the messages returned from PostFilter plugins.
PostFilterMsg string
// EvaluatedNodes records the number of nodes reached Filter stage.
// It is used for debugging purposes only.
EvaluatedNodes int
}

// FitError describes a fit error of a pod.
Expand Down
7 changes: 5 additions & 2 deletions pkg/scheduler/schedule_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (sched *Scheduler) schedulePod(ctx context.Context, fwk framework.Framework
if len(feasibleNodes) == 1 {
return ScheduleResult{
SuggestedHost: feasibleNodes[0].Node().Name,
EvaluatedNodes: 1 + len(diagnosis.NodeToStatusMap),
EvaluatedNodes: diagnosis.EvaluatedNodes,
FeasibleNodes: 1,
}, nil
}
Expand All @@ -432,7 +432,7 @@ func (sched *Scheduler) schedulePod(ctx context.Context, fwk framework.Framework

return ScheduleResult{
SuggestedHost: host,
EvaluatedNodes: len(feasibleNodes) + len(diagnosis.NodeToStatusMap),
EvaluatedNodes: diagnosis.EvaluatedNodes,
FeasibleNodes: len(feasibleNodes),
}, err
}
Expand Down Expand Up @@ -594,6 +594,7 @@ func (sched *Scheduler) findNodesThatPassFilters(
for i := range feasibleNodes {
feasibleNodes[i] = nodes[(sched.nextStartNodeIndex+i)%numAllNodes]
}
diagnosis.EvaluatedNodes = len(feasibleNodes)
return feasibleNodes, nil
}

Expand Down Expand Up @@ -642,11 +643,13 @@ func (sched *Scheduler) findNodesThatPassFilters(
// are found.
fwk.Parallelizer().Until(ctx, numAllNodes, checkNode, metrics.Filter)
feasibleNodes = feasibleNodes[:feasibleNodesLen]
diagnosis.EvaluatedNodes = len(feasibleNodes)
for _, item := range result {
if item == nil {
continue
}
diagnosis.NodeToStatusMap[item.node] = item.status
diagnosis.EvaluatedNodes++
diagnosis.AddPluginStatus(item.status)
}
if err := errCh.ReceiveError(); err != nil {
Expand Down
21 changes: 15 additions & 6 deletions pkg/scheduler/schedule_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
"node2": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("FalseFilter"),
},
UnschedulablePlugins: sets.New("FalseFilter"),
EvaluatedNodes: 2,
},
},
},
Expand Down Expand Up @@ -1919,6 +1920,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
"1": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("FalseFilter"),
},
UnschedulablePlugins: sets.New("FalseFilter"),
EvaluatedNodes: 3,
},
},
},
Expand All @@ -1945,6 +1947,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
"2": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("NoPodsFilter"),
},
UnschedulablePlugins: sets.New("MatchFilter", "NoPodsFilter"),
EvaluatedNodes: 2,
},
},
},
Expand Down Expand Up @@ -2110,6 +2113,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
"3": framework.NewStatus(framework.Unschedulable, "injecting failure for pod test-filter").WithPlugin("FakeFilter"),
},
UnschedulablePlugins: sets.New("FakeFilter"),
EvaluatedNodes: 1,
},
},
},
Expand Down Expand Up @@ -2143,6 +2147,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
"3": framework.NewStatus(framework.Unschedulable, "injecting failure for pod test-filter").WithPlugin("FakeFilter"),
},
UnschedulablePlugins: sets.New("FakeFilter", framework.ExtenderName),
EvaluatedNodes: 3,
},
},
},
Expand All @@ -2168,6 +2173,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
"3": framework.NewStatus(framework.UnschedulableAndUnresolvable, "injecting failure for pod test-filter").WithPlugin("FakeFilter"),
},
UnschedulablePlugins: sets.New("FakeFilter"),
EvaluatedNodes: 1,
},
},
},
Expand Down Expand Up @@ -2249,7 +2255,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
nodes: []string{"node1", "node2", "node3"},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: sets.New("node2"),
wantEvaluatedNodes: ptr.To[int32](3),
wantEvaluatedNodes: ptr.To[int32](1),
},
{
name: "test prefilter plugin returning non-intersecting nodes",
Expand Down Expand Up @@ -2338,6 +2344,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
"node2": framework.NewStatus(framework.Unschedulable, "injecting failure for pod test-prefilter").WithPlugin("FakeFilter"),
},
UnschedulablePlugins: sets.New("FakeFilter"),
EvaluatedNodes: 1,
PreFilterMsg: "",
},
},
Expand Down Expand Up @@ -2416,10 +2423,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
},
nodes: []string{"node1", "node2", "node3"},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: sets.New("node1", "node2"),
wantEvaluatedNodes: ptr.To[int32](2),
nodes: []string{"node1", "node2", "node3"},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: sets.New("node1", "node2"),
// since this case has no score plugin, we'll only try to find one node in Filter stage
wantEvaluatedNodes: ptr.To[int32](1),
},
}
for _, test := range tests {
Expand Down Expand Up @@ -2483,7 +2491,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
if gotOK != wantOK {
t.Errorf("Expected err to be FitError: %v, but got %v (error: %v)", wantOK, gotOK, err)
} else if gotOK {
if diff := cmp.Diff(gotFitErr, wantFitErr); diff != "" {
if diff := cmp.Diff(wantFitErr, gotFitErr); diff != "" {
t.Errorf("Unexpected fitErr: (-want, +got): %s", diff)
}
}
Expand Down Expand Up @@ -2536,6 +2544,7 @@ func TestFindFitAllError(t *testing.T) {
"3": framework.NewStatus(framework.Unschedulable, tf.ErrReasonFake).WithPlugin("MatchFilter"),
},
UnschedulablePlugins: sets.New("MatchFilter"),
EvaluatedNodes: 3,
}
if diff := cmp.Diff(diagnosis, expected); diff != "" {
t.Errorf("Unexpected diagnosis: (-want, +got): %s", diff)
Expand Down

0 comments on commit 7030d89

Please sign in to comment.