Skip to content

Commit 3565802

Browse files
Renamed the post response plugins to not include the word post.
1 parent bbeb5b6 commit 3565802

File tree

5 files changed

+104
-96
lines changed

5 files changed

+104
-96
lines changed

pkg/epp/requestcontrol/director.go

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,37 @@ type SaturationDetector interface {
5959
IsSaturated(ctx context.Context, candidatePods []backendmetrics.PodMetrics) bool
6060
}
6161

62+
type RequestControlPlugins struct {
63+
preRequestPlugins []PreRequest
64+
responseReceivedPlugins []ResponseReceived
65+
responseStreamingPlugins []ResponseStreaming
66+
responseCompletePlugins []ResponseComplete
67+
}
68+
6269
// NewDirectorWithConfig creates a new Director instance with all dependencies.
6370
func NewDirectorWithConfig(datastore Datastore, scheduler Scheduler, saturationDetector SaturationDetector, config *Config) *Director {
71+
RCPlugins := RequestControlPlugins{
72+
preRequestPlugins: config.preRequestPlugins,
73+
responseReceivedPlugins: config.responseReceivedPlugins,
74+
responseStreamingPlugins: config.responseStreamingPlugins,
75+
responseCompletePlugins: config.responseCompletePlugins,
76+
}
77+
6478
return &Director{
65-
datastore: datastore,
66-
scheduler: scheduler,
67-
saturationDetector: saturationDetector,
68-
preRequestPlugins: config.preRequestPlugins,
69-
postResponseReceivedPlugins: config.postResponseReceivedPlugins,
70-
postResponseStreamingPlugins: config.postResponseStreamingPlugins,
71-
postResponseCompletePlugins: config.postResponseCompletePlugins,
72-
defaultPriority: 0, // define default priority explicitly
79+
datastore: datastore,
80+
scheduler: scheduler,
81+
saturationDetector: saturationDetector,
82+
requestControlPlugins: RCPlugins,
83+
defaultPriority: 0, // define default priority explicitly
7384
}
7485
}
7586

7687
// Director orchestrates the request handling flow, including scheduling.
7788
type Director struct {
78-
datastore Datastore
79-
scheduler Scheduler
80-
saturationDetector SaturationDetector
81-
preRequestPlugins []PreRequest
82-
postResponseReceivedPlugins []PostResponseReceived
83-
postResponseStreamingPlugins []PostResponseStreaming
84-
postResponseCompletePlugins []PostResponseComplete
89+
datastore Datastore
90+
scheduler Scheduler
91+
saturationDetector SaturationDetector
92+
requestControlPlugins RequestControlPlugins
8593
// we just need a pointer to an int variable since priority is a pointer in InferenceObjective
8694
// no need to set this in the constructor, since the value we want is the default int val
8795
// and value types cannot be nil
@@ -291,7 +299,7 @@ func (d *Director) HandleResponseReceived(ctx context.Context, reqCtx *handlers.
291299

292300
// TODO: to extend fallback functionality, handle cases where target pod is unavailable
293301
// https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/1224
294-
d.runPostResponseReceivedPlugins(ctx, reqCtx.SchedulingRequest, response, reqCtx.TargetPod)
302+
d.runResponseReceivedPlugins(ctx, reqCtx.SchedulingRequest, response, reqCtx.TargetPod)
295303

296304
return reqCtx, nil
297305
}
@@ -305,7 +313,7 @@ func (d *Director) HandleResponseBodyStreaming(ctx context.Context, reqCtx *hand
305313
Headers: reqCtx.Response.Headers,
306314
}
307315

308-
d.runPostResponseStreamingPlugins(ctx, reqCtx.SchedulingRequest, response, reqCtx.TargetPod)
316+
d.runResponseStreamingPlugins(ctx, reqCtx.SchedulingRequest, response, reqCtx.TargetPod)
309317
logger.V(logutil.TRACE).Info("Exiting HandleResponseBodyChunk")
310318
return reqCtx, nil
311319
}
@@ -319,7 +327,7 @@ func (d *Director) HandleResponseBodyComplete(ctx context.Context, reqCtx *handl
319327
Headers: reqCtx.Response.Headers,
320328
}
321329

322-
d.runPostResponseCompletePlugins(ctx, reqCtx.SchedulingRequest, response, reqCtx.TargetPod)
330+
d.runResponseCompletePlugins(ctx, reqCtx.SchedulingRequest, response, reqCtx.TargetPod)
323331

324332
logger.V(logutil.DEBUG).Info("Exiting HandleResponseBodyComplete")
325333
return reqCtx, nil
@@ -338,7 +346,7 @@ func (d *Director) GetRandomPod() *backend.Pod {
338346
func (d *Director) runPreRequestPlugins(ctx context.Context, request *schedulingtypes.LLMRequest,
339347
schedulingResult *schedulingtypes.SchedulingResult, targetPort int) {
340348
loggerDebug := log.FromContext(ctx).V(logutil.DEBUG)
341-
for _, plugin := range d.preRequestPlugins {
349+
for _, plugin := range d.requestControlPlugins.preRequestPlugins {
342350
loggerDebug.Info("Running pre-request plugin", "plugin", plugin.TypedName())
343351
before := time.Now()
344352
plugin.PreRequest(ctx, request, schedulingResult, targetPort)
@@ -347,34 +355,34 @@ func (d *Director) runPreRequestPlugins(ctx context.Context, request *scheduling
347355
}
348356
}
349357

350-
func (d *Director) runPostResponseReceivedPlugins(ctx context.Context, request *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
358+
func (d *Director) runResponseReceivedPlugins(ctx context.Context, request *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
351359
loggerDebug := log.FromContext(ctx).V(logutil.DEBUG)
352-
for _, plugin := range d.postResponseReceivedPlugins {
360+
for _, plugin := range d.requestControlPlugins.responseReceivedPlugins {
353361
loggerDebug.Info("Running post-response plugin", "plugin", plugin.TypedName())
354362
before := time.Now()
355-
plugin.PostResponseReceived(ctx, request, response, targetPod)
356-
metrics.RecordPluginProcessingLatency(PostResponseReceivedExtensionPoint, plugin.TypedName().Type, plugin.TypedName().Name, time.Since(before))
363+
plugin.ResponseReceived(ctx, request, response, targetPod)
364+
metrics.RecordPluginProcessingLatency(ResponseReceivedExtensionPoint, plugin.TypedName().Type, plugin.TypedName().Name, time.Since(before))
357365
loggerDebug.Info("Completed running post-response plugin successfully", "plugin", plugin.TypedName())
358366
}
359367
}
360368

361-
func (d *Director) runPostResponseStreamingPlugins(ctx context.Context, request *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
369+
func (d *Director) runResponseStreamingPlugins(ctx context.Context, request *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
362370
loggerTrace := log.FromContext(ctx).V(logutil.TRACE)
363-
for _, plugin := range d.postResponseStreamingPlugins {
371+
for _, plugin := range d.requestControlPlugins.responseStreamingPlugins {
364372
loggerTrace.Info("Running post-response chunk plugin", "plugin", plugin.TypedName())
365373
before := time.Now()
366-
plugin.PostResponseStreaming(ctx, request, response, targetPod)
367-
metrics.RecordPluginProcessingLatency(PostResponseStreamingExtensionPoint, plugin.TypedName().Type, plugin.TypedName().Name, time.Since(before))
374+
plugin.ResponseStreaming(ctx, request, response, targetPod)
375+
metrics.RecordPluginProcessingLatency(ResponseStreamingExtensionPoint, plugin.TypedName().Type, plugin.TypedName().Name, time.Since(before))
368376
}
369377
}
370378

371-
func (d *Director) runPostResponseCompletePlugins(ctx context.Context, request *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
379+
func (d *Director) runResponseCompletePlugins(ctx context.Context, request *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
372380
loggerDebug := log.FromContext(ctx).V(logutil.DEBUG)
373-
for _, plugin := range d.postResponseCompletePlugins {
381+
for _, plugin := range d.requestControlPlugins.responseCompletePlugins {
374382
loggerDebug.Info("Running post-response complete plugin", "plugin", plugin.TypedName())
375383
before := time.Now()
376-
plugin.PostResponseComplete(ctx, request, response, targetPod)
377-
metrics.RecordPluginProcessingLatency(PostResponseCompleteExtensionPoint, plugin.TypedName().Type, plugin.TypedName().Name, time.Since(before))
384+
plugin.ResponseComplete(ctx, request, response, targetPod)
385+
metrics.RecordPluginProcessingLatency(ResponseCompleteExtensionPoint, plugin.TypedName().Type, plugin.TypedName().Name, time.Since(before))
378386
loggerDebug.Info("Completed running post-response complete plugin successfully", "plugin", plugin.TypedName())
379387
}
380388
}

pkg/epp/requestcontrol/director_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,12 @@ func TestGetRandomPod(t *testing.T) {
593593
}
594594

595595
func TestDirector_HandleResponseReceived(t *testing.T) {
596-
pr1 := newTestPostResponseReceived("pr1")
596+
pr1 := newTestResponseReceived("pr1")
597597

598598
ctx := logutil.NewTestLoggerIntoContext(context.Background())
599599
ds := datastore.NewDatastore(t.Context(), nil)
600600
mockSched := &mockScheduler{}
601-
director := NewDirectorWithConfig(ds, mockSched, nil, NewConfig().WithPostResponseReceivedPlugins(pr1))
601+
director := NewDirectorWithConfig(ds, mockSched, nil, NewConfig().WithResponseReceivedPlugins(pr1))
602602

603603
reqCtx := &handlers.RequestContext{
604604
Request: &handlers.Request{
@@ -630,12 +630,12 @@ func TestDirector_HandleResponseReceived(t *testing.T) {
630630
}
631631

632632
func TestDirector_HandleResponseStreaming(t *testing.T) {
633-
ps1 := newTestPostResponseStreaming("ps1")
633+
ps1 := newTestResponseStreaming("ps1")
634634

635635
ctx := logutil.NewTestLoggerIntoContext(context.Background())
636636
ds := datastore.NewDatastore(t.Context(), nil)
637637
mockSched := &mockScheduler{}
638-
director := NewDirectorWithConfig(ds, mockSched, nil, NewConfig().WithPostResponseStreamingPlugins(ps1))
638+
director := NewDirectorWithConfig(ds, mockSched, nil, NewConfig().WithResponseStreamingPlugins(ps1))
639639

640640
reqCtx := &handlers.RequestContext{
641641
Request: &handlers.Request{
@@ -666,12 +666,12 @@ func TestDirector_HandleResponseStreaming(t *testing.T) {
666666
}
667667

668668
func TestDirector_HandleResponseComplete(t *testing.T) {
669-
pc1 := newTestPostResponseComplete("pc1")
669+
pc1 := newTestResponseComplete("pc1")
670670

671671
ctx := logutil.NewTestLoggerIntoContext(context.Background())
672672
ds := datastore.NewDatastore(t.Context(), nil)
673673
mockSched := &mockScheduler{}
674-
director := NewDirectorWithConfig(ds, mockSched, nil, NewConfig().WithPostResponseCompletePlugins(pc1))
674+
director := NewDirectorWithConfig(ds, mockSched, nil, NewConfig().WithResponseCompletePlugins(pc1))
675675

676676
reqCtx := &handlers.RequestContext{
677677
Request: &handlers.Request{
@@ -702,70 +702,70 @@ func TestDirector_HandleResponseComplete(t *testing.T) {
702702
}
703703

704704
const (
705-
testPostResponseReceivedType = "test-post-response"
706-
testPostStreamingType = "test-post-streaming"
707-
testPostCompleteType = "test-post-complete"
705+
testResponseReceivedType = "test-post-response"
706+
testPostStreamingType = "test-post-streaming"
707+
testPostCompleteType = "test-post-complete"
708708
)
709709

710-
type testPostResponseReceived struct {
710+
type testResponseReceived struct {
711711
tn plugins.TypedName
712712
lastRespOnResponse *Response
713713
lastTargetPodOnResponse string
714714
}
715715

716-
type testPostResponseStreaming struct {
716+
type testResponseStreaming struct {
717717
tn plugins.TypedName
718718
lastRespOnStreaming *Response
719719
lastTargetPodOnStreaming string
720720
}
721721

722-
type testPostResponseComplete struct {
722+
type testResponseComplete struct {
723723
tn plugins.TypedName
724724
lastRespOnComplete *Response
725725
lastTargetPodOnComplete string
726726
}
727727

728-
func newTestPostResponseReceived(name string) *testPostResponseReceived {
729-
return &testPostResponseReceived{
730-
tn: plugins.TypedName{Type: testPostResponseReceivedType, Name: name},
728+
func newTestResponseReceived(name string) *testResponseReceived {
729+
return &testResponseReceived{
730+
tn: plugins.TypedName{Type: testResponseReceivedType, Name: name},
731731
}
732732
}
733733

734-
func newTestPostResponseStreaming(name string) *testPostResponseStreaming {
735-
return &testPostResponseStreaming{
734+
func newTestResponseStreaming(name string) *testResponseStreaming {
735+
return &testResponseStreaming{
736736
tn: plugins.TypedName{Type: testPostStreamingType, Name: name},
737737
}
738738
}
739739

740-
func newTestPostResponseComplete(name string) *testPostResponseComplete {
741-
return &testPostResponseComplete{
740+
func newTestResponseComplete(name string) *testResponseComplete {
741+
return &testResponseComplete{
742742
tn: plugins.TypedName{Type: testPostCompleteType, Name: name},
743743
}
744744
}
745745

746-
func (p *testPostResponseReceived) TypedName() plugins.TypedName {
746+
func (p *testResponseReceived) TypedName() plugins.TypedName {
747747
return p.tn
748748
}
749749

750-
func (p *testPostResponseStreaming) TypedName() plugins.TypedName {
750+
func (p *testResponseStreaming) TypedName() plugins.TypedName {
751751
return p.tn
752752
}
753753

754-
func (p *testPostResponseComplete) TypedName() plugins.TypedName {
754+
func (p *testResponseComplete) TypedName() plugins.TypedName {
755755
return p.tn
756756
}
757757

758-
func (p *testPostResponseReceived) PostResponseReceived(_ context.Context, _ *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
758+
func (p *testResponseReceived) ResponseReceived(_ context.Context, _ *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
759759
p.lastRespOnResponse = response
760760
p.lastTargetPodOnResponse = targetPod.NamespacedName.String()
761761
}
762762

763-
func (p *testPostResponseStreaming) PostResponseStreaming(_ context.Context, _ *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
763+
func (p *testResponseStreaming) ResponseStreaming(_ context.Context, _ *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
764764
p.lastRespOnStreaming = response
765765
p.lastTargetPodOnStreaming = targetPod.NamespacedName.String()
766766
}
767767

768-
func (p *testPostResponseComplete) PostResponseComplete(_ context.Context, _ *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
768+
func (p *testResponseComplete) ResponseComplete(_ context.Context, _ *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
769769
p.lastRespOnComplete = response
770770
p.lastTargetPodOnComplete = targetPod.NamespacedName.String()
771771
}

pkg/epp/requestcontrol/plugins.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
)
2626

2727
const (
28-
PreRequestExtensionPoint = "PreRequest"
29-
PostResponseReceivedExtensionPoint = "PostResponseReceived"
30-
PostResponseStreamingExtensionPoint = "PostResponseStreaming"
31-
PostResponseCompleteExtensionPoint = "PostResponseComplete"
28+
PreRequestExtensionPoint = "PreRequest"
29+
ResponseReceivedExtensionPoint = "ResponseReceived"
30+
ResponseStreamingExtensionPoint = "ResponseStreaming"
31+
ResponseCompleteExtensionPoint = "ResponseComplete"
3232
)
3333

3434
// PreRequest is called by the director after a getting result from scheduling layer and
@@ -38,21 +38,21 @@ type PreRequest interface {
3838
PreRequest(ctx context.Context, request *types.LLMRequest, schedulingResult *types.SchedulingResult, targetPort int)
3939
}
4040

41-
// PostResponseReceived is called by the director after a successful response is sent.
41+
// ResponseReceived is called by the director after a successful response is sent.
4242
// The given pod argument is the pod that served the request.
43-
type PostResponseReceived interface {
43+
type ResponseReceived interface {
4444
plugins.Plugin
45-
PostResponseReceived(ctx context.Context, request *types.LLMRequest, response *Response, targetPod *backend.Pod)
45+
ResponseReceived(ctx context.Context, request *types.LLMRequest, response *Response, targetPod *backend.Pod)
4646
}
4747

48-
// PostResponseStreaming is called by the director after each chunk of streaming response is sent.
49-
type PostResponseStreaming interface {
48+
// ResponseStreaming is called by the director after each chunk of streaming response is sent.
49+
type ResponseStreaming interface {
5050
plugins.Plugin
51-
PostResponseStreaming(ctx context.Context, request *types.LLMRequest, response *Response, targetPod *backend.Pod)
51+
ResponseStreaming(ctx context.Context, request *types.LLMRequest, response *Response, targetPod *backend.Pod)
5252
}
5353

54-
// PostResponseComplete is called by the director after the complete response is sent.
55-
type PostResponseComplete interface {
54+
// ResponseComplete is called by the director after the complete response is sent.
55+
type ResponseComplete interface {
5656
plugins.Plugin
57-
PostResponseComplete(ctx context.Context, request *types.LLMRequest, response *Response, targetPod *backend.Pod)
57+
ResponseComplete(ctx context.Context, request *types.LLMRequest, response *Response, targetPod *backend.Pod)
5858
}

0 commit comments

Comments
 (0)