Skip to content

Commit 634b828

Browse files
committed
Remove Type() and Name() from Plugin interface
Signed-off-by: Etai Lev Ran <elevran@gmail.com>
1 parent ca4cc1d commit 634b828

21 files changed

+66
-91
lines changed

conformance/testing-epp/plugins/filter/request_header_based_filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var _ framework.Filter = &HeaderBasedTestingFilter{}
4040
// This should only be used for testing purposes.
4141
func NewHeaderBasedTestingFilter() *HeaderBasedTestingFilter {
4242
return &HeaderBasedTestingFilter{
43-
TypedName: plugins.TypedName{PluginType: "header-based-testing", PluginName: "header-based-testing-filter"},
43+
TypedName: plugins.TypedName{Type: "header-based-testing", Name: "header-based-testing-filter"},
4444
}
4545
}
4646

pkg/epp/common/config/loader/configloader_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ type test1 struct {
561561

562562
func newTest1() *test1 {
563563
return &test1{
564-
TypedName: plugins.TypedName{PluginType: test1Type, PluginName: "test-1"},
564+
TypedName: plugins.TypedName{Type: test1Type, Name: "test-1"},
565565
}
566566
}
567567

@@ -580,7 +580,7 @@ type test2 struct {
580580

581581
func newTest2() *test2 {
582582
return &test2{
583-
TypedName: plugins.TypedName{PluginType: test2Type, PluginName: "test-2"},
583+
TypedName: plugins.TypedName{Type: test2Type, Name: "test-2"},
584584
}
585585
}
586586

@@ -599,7 +599,7 @@ type testPicker struct {
599599

600600
func newTestPicker() *testPicker {
601601
return &testPicker{
602-
TypedName: plugins.TypedName{PluginType: testPickerType, PluginName: "test-picker"},
602+
TypedName: plugins.TypedName{Type: testPickerType, Name: "test-picker"},
603603
}
604604
}
605605

@@ -616,7 +616,7 @@ type testProfileHandler struct {
616616

617617
func newTestProfileHandler() *testProfileHandler {
618618
return &testProfileHandler{
619-
TypedName: plugins.TypedName{PluginType: testProfileHandlerType, PluginName: "test-profile-handler"},
619+
TypedName: plugins.TypedName{Type: testProfileHandlerType, Name: "test-profile-handler"},
620620
}
621621
}
622622

pkg/epp/plugins/plugins.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ import (
2424
// Plugin defines the interface for a plugin.
2525
// This interface should be embedded in all plugins across the code.
2626
type Plugin interface {
27-
// Type returns the type of the plugin.
28-
Type() string
29-
// Name returns the name of this plugin instance.
30-
Name() string
3127
// GetTypedName returns the type and name of this plugin instance.
3228
GetTypedName() TypedName
3329
}

pkg/epp/plugins/typedname.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,10 @@ package plugins
2121
// It implements the Plugin interface and can be embedded in
2222
// plugins across the code to reduce boilerplate.
2323
type TypedName struct {
24-
PluginType string
25-
PluginName string
26-
}
27-
28-
// Type returns the type of the plugin.
29-
func (tn *TypedName) Type() string {
30-
return tn.PluginType
31-
}
32-
33-
// Name returns the name of this plugin instance.
34-
func (tn *TypedName) Name() string {
35-
return tn.PluginName
24+
// Type returns the type of the plugin.
25+
Type string
26+
// Name returns the name of this plugin instance.
27+
Name string
3628
}
3729

3830
const (
@@ -42,7 +34,7 @@ const (
4234
// String returns the type and name rendered as
4335
// "<type>/<name>".
4436
func (tn *TypedName) String() string {
45-
return tn.PluginType + Separator + tn.PluginName
37+
return tn.Type + Separator + tn.Name
4638
}
4739

4840
func (tn *TypedName) GetTypedName() TypedName {

pkg/epp/requestcontrol/director.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,18 @@ func RandomWeightedDraw(logger logr.Logger, model *v1alpha2.InferenceModel, seed
312312
func (d *Director) runPreRequestPlugins(ctx context.Context, request *schedulingtypes.LLMRequest, schedulingResult *schedulingtypes.SchedulingResult,
313313
targetPort int) {
314314
for _, plugin := range d.preRequestPlugins {
315-
log.FromContext(ctx).V(logutil.DEBUG).Info("Running pre-request plugin", "plugin", plugin.Type())
315+
log.FromContext(ctx).V(logutil.DEBUG).Info("Running pre-request plugin", "plugin", plugin.GetTypedName().Type)
316316
before := time.Now()
317317
plugin.PreRequest(ctx, request, schedulingResult, targetPort)
318-
metrics.RecordRequestControlPluginProcessingLatency(PreRequestPluginType, plugin.Type(), time.Since(before))
318+
metrics.RecordRequestControlPluginProcessingLatency(PreRequestPluginType, plugin.GetTypedName().Type, time.Since(before))
319319
}
320320
}
321321

322322
func (d *Director) runPostResponsePlugins(ctx context.Context, request *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
323323
for _, plugin := range d.postResponsePlugins {
324-
log.FromContext(ctx).V(logutil.DEBUG).Info("Running post-response plugin", "plugin", plugin.Type())
324+
log.FromContext(ctx).V(logutil.DEBUG).Info("Running post-response plugin", "plugin", plugin.GetTypedName().Type)
325325
before := time.Now()
326326
plugin.PostResponse(ctx, request, response, targetPod)
327-
metrics.RecordRequestControlPluginProcessingLatency(PostResponsePluginType, plugin.Type(), time.Since(before))
327+
metrics.RecordRequestControlPluginProcessingLatency(PostResponsePluginType, plugin.GetTypedName().Type, time.Since(before))
328328
}
329329
}

pkg/epp/requestcontrol/director_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ type testPostResponse struct {
702702

703703
func newTestPostResponse(name string) *testPostResponse {
704704
return &testPostResponse{
705-
TypedName: plugins.TypedName{PluginType: testPostResponseType, PluginName: name},
705+
TypedName: plugins.TypedName{Type: testPostResponseType, Name: name},
706706
}
707707
}
708708

pkg/epp/scheduling/framework/plugins/filter/decision_tree_filter.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,14 @@ func loadDecisionTreeEntry(entry *decisionTreeFilterEntry, handle plugins.Handle
133133
return nil, errors.New("either pluginRef or decisionTree must be specified")
134134
}
135135

136-
// Type returns the type of the filter.
137-
func (f *DecisionTreeFilter) Type() string {
138-
if f == nil {
139-
return "nil"
140-
}
141-
return f.Current.Type()
142-
}
143-
144-
// Name returns the name of the filter.
145-
func (f *DecisionTreeFilter) Name() string {
146-
if f == nil {
147-
return ""
148-
}
149-
return f.Current.Name()
150-
}
151-
152136
func (f *DecisionTreeFilter) GetTypedName() plugins.TypedName {
153-
return plugins.TypedName{
154-
PluginType: f.Type(),
155-
PluginName: f.Name(),
137+
if f == nil {
138+
// TODO: this keeps the previous behavior ("nil"/"") - not sure
139+
// why done this way.
140+
// Change to empty TypedName or some more meaningful values?
141+
return plugins.TypedName{Type: "nil", Name: ""}
156142
}
143+
return f.Current.GetTypedName()
157144
}
158145

159146
// Filter filters out pods that doesn't meet the filter criteria.
@@ -170,7 +157,7 @@ func (f *DecisionTreeFilter) Filter(ctx context.Context, cycleState *types.Cycle
170157
if f.NextOnSuccess != nil {
171158
next = f.NextOnSuccess
172159
}
173-
loggerTrace.Info("Filter succeeded", "filter", f.Type(), "next", next.Type(), "filteredPodCount", len(filteredPod))
160+
loggerTrace.Info("Filter succeeded", "filter", f.GetTypedName(), "next", next.GetTypedName(), "filteredPodCount", len(filteredPod))
174161
// On success, pass the filtered result to the next filter.
175162
return next.Filter(ctx, cycleState, request, filteredPod)
176163
} else {
@@ -181,7 +168,7 @@ func (f *DecisionTreeFilter) Filter(ctx context.Context, cycleState *types.Cycle
181168
if f.NextOnFailure != nil {
182169
next = f.NextOnFailure
183170
}
184-
loggerTrace.Info("Filter failed", "filter", f.Type(), "next", next.Type())
171+
loggerTrace.Info("Filter failed", "filter", f.GetTypedName(), "next", next.GetTypedName())
185172
// On failure, pass the initial set of pods to the next filter.
186173
return next.Filter(ctx, cycleState, request, pods)
187174
}

pkg/epp/scheduling/framework/plugins/filter/filter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type filterAll struct {
4545

4646
func newFilterAll() *filterAll {
4747
return &filterAll{
48-
TypedName: plugins.TypedName{PluginType: "filter-all", PluginName: "test-all"},
48+
TypedName: plugins.TypedName{Type: "filter-all", Name: "test-all"},
4949
}
5050
}
5151

pkg/epp/scheduling/framework/plugins/filter/least_kvcache_filter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func LeastKVCacheFilterFactory(name string, _ json.RawMessage, _ plugins.Handle)
4141
// NewLeastKVCacheFilter initializes a new LeastKVCacheFilter and returns its pointer.
4242
func NewLeastKVCacheFilter() *LeastKVCacheFilter {
4343
return &LeastKVCacheFilter{
44-
TypedName: plugins.TypedName{PluginType: LeastKVCacheFilterType, PluginName: LeastKVCacheFilterType},
44+
TypedName: plugins.TypedName{Type: LeastKVCacheFilterType, Name: LeastKVCacheFilterType},
4545
}
4646
}
4747

@@ -56,7 +56,7 @@ type LeastKVCacheFilter struct {
5656

5757
// WithName sets the name of the filter.
5858
func (f *LeastKVCacheFilter) WithName(name string) *LeastKVCacheFilter {
59-
f.PluginName = name
59+
f.Name = name
6060
return f
6161
}
6262

pkg/epp/scheduling/framework/plugins/filter/least_queue_filter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func LeastQueueFilterFactory(name string, _ json.RawMessage, _ plugins.Handle) (
4141
// NewLeastQueueFilter initializes a new LeastQueueFilter and returns its pointer.
4242
func NewLeastQueueFilter() *LeastQueueFilter {
4343
return &LeastQueueFilter{
44-
TypedName: plugins.TypedName{PluginType: LeastQueueFilterType, PluginName: LeastQueueFilterType},
44+
TypedName: plugins.TypedName{Type: LeastQueueFilterType, Name: LeastQueueFilterType},
4545
}
4646
}
4747

@@ -56,7 +56,7 @@ type LeastQueueFilter struct {
5656

5757
// WithName sets the name of the filter.
5858
func (f *LeastQueueFilter) WithName(name string) *LeastQueueFilter {
59-
f.PluginName = name
59+
f.Name = name
6060
return f
6161
}
6262

0 commit comments

Comments
 (0)