Skip to content

Commit e29fa4b

Browse files
authored
profile handler ProcessResult returns additional return value (#1013)
* profile handler ProcessResult returns an error as additional return value Signed-off-by: Nir Rozenbaum <[email protected]> * minor update Signed-off-by: Nir Rozenbaum <[email protected]> * fixed log Signed-off-by: Nir Rozenbaum <[email protected]> * validate that single profile handler process only single profile Signed-off-by: Nir Rozenbaum <[email protected]> --------- Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent 7f8d67d commit e29fa4b

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

pkg/epp/common/config/configloader_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ func (p *testProfileHandler) Pick(ctx context.Context, request *types.LLMRequest
515515
return nil
516516
}
517517

518-
func (p *testProfileHandler) ProcessResults(ctx context.Context, request *types.LLMRequest, profileResults map[string]*types.ProfileRunResult) *types.SchedulingResult {
519-
return nil
518+
func (p *testProfileHandler) ProcessResults(ctx context.Context, request *types.LLMRequest, profileResults map[string]*types.ProfileRunResult) (*types.SchedulingResult, error) {
519+
return nil, nil
520520
}
521521

522522
func registerTestPlugins() {

pkg/epp/scheduling/framework/plugins.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ type ProfileHandler interface {
4040
// and the previously executed SchedluderProfile cycles along with their results.
4141
Pick(ctx context.Context, request *types.LLMRequest, profiles map[string]*SchedulerProfile, profileResults map[string]*types.ProfileRunResult) map[string]*SchedulerProfile
4242

43-
// ProcessResults handles the outcome of the profile runs after all profiles ran succuessfully.
43+
// ProcessResults handles the outcome of the profile runs after all profiles ran.
4444
// It may aggregate results, log test profile outputs, or apply custom logic. It specifies in the SchedulingResult the
4545
// key of the primary profile that should be used to get the request selected destination.
46-
ProcessResults(ctx context.Context, request *types.LLMRequest, profileResults map[string]*types.ProfileRunResult) *types.SchedulingResult
46+
// When a profile run fails, its result in the profileResults map is nil.
47+
ProcessResults(ctx context.Context, request *types.LLMRequest, profileResults map[string]*types.ProfileRunResult) (*types.SchedulingResult, error)
4748
}
4849

4950
// Filter defines the interface for filtering a list of pods based on context.

pkg/epp/scheduling/framework/plugins/profile/single_profile_handler.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package profile
1919
import (
2020
"context"
2121
"encoding/json"
22+
"errors"
23+
"fmt"
2224

2325
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
2426
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
@@ -58,15 +60,28 @@ func (h *SingleProfileHandler) Pick(_ context.Context, request *types.LLMRequest
5860
return profiles
5961
}
6062

61-
func (h *SingleProfileHandler) ProcessResults(_ context.Context, _ *types.LLMRequest, profileResults map[string]*types.ProfileRunResult) *types.SchedulingResult {
62-
var firstKey string
63-
for key := range profileResults {
64-
firstKey = key
63+
// ProcessResults handles the outcome of the profile runs after all profiles ran.
64+
// It may aggregate results, log test profile outputs, or apply custom logic. It specifies in the SchedulingResult the
65+
// key of the primary profile that should be used to get the request selected destination.
66+
// When a profile run fails, its result in the profileResults map is nil.
67+
func (h *SingleProfileHandler) ProcessResults(_ context.Context, _ *types.LLMRequest,
68+
profileResults map[string]*types.ProfileRunResult) (*types.SchedulingResult, error) {
69+
if len(profileResults) != 1 {
70+
return nil, errors.New("single profile handler is intended to be used with a single profile, failed to process multiple profiles")
71+
}
72+
73+
var singleProfileName string
74+
for profileName := range profileResults {
75+
singleProfileName = profileName
6576
break
6677
}
6778

79+
if profileResults[singleProfileName] == nil { // there was an error while running the profile
80+
return nil, fmt.Errorf("failed to run scheduler profile '%s'", singleProfileName)
81+
}
82+
6883
return &types.SchedulingResult{
6984
ProfileResults: profileResults,
70-
PrimaryProfileName: firstKey,
71-
}
85+
PrimaryProfileName: singleProfileName,
86+
}, nil
7287
}

pkg/epp/scheduling/scheduler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ func (s *Scheduler) Schedule(ctx context.Context, request *types.LLMRequest) (*t
123123
// run the selected profiles and collect results (current code runs all profiles)
124124
profileRunResult, err := profile.Run(ctx, request, cycleState, podsSnapshot)
125125
if err != nil {
126-
return nil, fmt.Errorf("failed to run all required scheduling profiles - %w", err)
126+
loggerDebug.Info("failed to run scheduler profile", "profile", name, "error", err.Error())
127127
}
128128

129-
profileRunResults[name] = profileRunResult
129+
profileRunResults[name] = profileRunResult // if profile failed to run, the run result is nil
130130
}
131131
}
132132

@@ -135,8 +135,8 @@ func (s *Scheduler) Schedule(ctx context.Context, request *types.LLMRequest) (*t
135135
}
136136

137137
before := time.Now()
138-
result := s.profileHandler.ProcessResults(ctx, request, profileRunResults)
138+
result, err := s.profileHandler.ProcessResults(ctx, request, profileRunResults)
139139
metrics.RecordSchedulerPluginProcessingLatency(framework.ProcessProfilesResultsType, s.profileHandler.Name(), time.Since(before))
140140

141-
return result, nil
141+
return result, err
142142
}

0 commit comments

Comments
 (0)