Skip to content

Commit 3766b51

Browse files
committed
use TypedName as private field, not embedded
Signed-off-by: Etai Lev Ran <elevran@gmail.com>
1 parent c062db2 commit 3766b51

21 files changed

+162
-83
lines changed

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

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

4747
// HeaderBasedTestingFilter filters Pods based on an address specified in the "test-epp-endpoint-selection" request header.
4848
type HeaderBasedTestingFilter struct {
49-
plugins.TypedName
49+
tn plugins.TypedName
50+
}
51+
52+
// TypedName returns the type and name tuple of this plugin instance.
53+
func (f *HeaderBasedTestingFilter) TypedName() plugins.TypedName {
54+
return f.tn
5055
}
5156

5257
// Filter selects pods that match the IP addresses specified in the request header.

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,16 +555,20 @@ schedulingProfiles:
555555
var _ framework.Filter = &test1{}
556556

557557
type test1 struct {
558-
plugins.TypedName
558+
tn plugins.TypedName
559559
Threshold int `json:"threshold"`
560560
}
561561

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

568+
func (f *test1) TypedName() plugins.TypedName {
569+
return f.tn
570+
}
571+
568572
// Filter filters out pods that doesn't meet the filter criteria.
569573
func (f *test1) Filter(_ context.Context, _ *types.CycleState, _ *types.LLMRequest, pods []types.Pod) []types.Pod {
570574
return pods
@@ -575,15 +579,19 @@ var _ framework.Scorer = &test2{}
575579
var _ framework.PostCycle = &test2{}
576580

577581
type test2 struct {
578-
plugins.TypedName
582+
tn plugins.TypedName
579583
}
580584

581585
func newTest2() *test2 {
582586
return &test2{
583-
TypedName: plugins.TypedName{Type: test2Type, Name: "test-2"},
587+
tn: plugins.TypedName{Type: test2Type, Name: "test-2"},
584588
}
585589
}
586590

591+
func (m *test2) TypedName() plugins.TypedName {
592+
return m.tn
593+
}
594+
587595
func (m *test2) Score(_ context.Context, _ *types.CycleState, _ *types.LLMRequest, _ []types.Pod) map[types.Pod]float64 {
588596
return map[types.Pod]float64{}
589597
}
@@ -594,15 +602,19 @@ func (m *test2) PostCycle(_ context.Context, _ *types.CycleState, _ *types.Profi
594602
var _ framework.Picker = &testPicker{}
595603

596604
type testPicker struct {
597-
plugins.TypedName
605+
tn plugins.TypedName
598606
}
599607

600608
func newTestPicker() *testPicker {
601609
return &testPicker{
602-
TypedName: plugins.TypedName{Type: testPickerType, Name: "test-picker"},
610+
tn: plugins.TypedName{Type: testPickerType, Name: "test-picker"},
603611
}
604612
}
605613

614+
func (p *testPicker) TypedName() plugins.TypedName {
615+
return p.tn
616+
}
617+
606618
func (p *testPicker) Pick(_ context.Context, _ *types.CycleState, _ []*types.ScoredPod) *types.ProfileRunResult {
607619
return nil
608620
}
@@ -611,15 +623,19 @@ func (p *testPicker) Pick(_ context.Context, _ *types.CycleState, _ []*types.Sco
611623
var _ framework.ProfileHandler = &testProfileHandler{}
612624

613625
type testProfileHandler struct {
614-
plugins.TypedName
626+
tn plugins.TypedName
615627
}
616628

617629
func newTestProfileHandler() *testProfileHandler {
618630
return &testProfileHandler{
619-
TypedName: plugins.TypedName{Type: testProfileHandlerType, Name: "test-profile-handler"},
631+
tn: plugins.TypedName{Type: testProfileHandlerType, Name: "test-profile-handler"},
620632
}
621633
}
622634

635+
func (p *testProfileHandler) TypedName() plugins.TypedName {
636+
return p.tn
637+
}
638+
623639
func (p *testProfileHandler) Pick(_ context.Context, _ *types.CycleState, _ *types.LLMRequest, _ map[string]*framework.SchedulerProfile, _ map[string]*types.ProfileRunResult) map[string]*framework.SchedulerProfile {
624640
return nil
625641
}

pkg/epp/plugins/plugins.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ 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-
// GetTypedName returns the type and name of this plugin instance.
28-
GetTypedName() TypedName
27+
// TypedName returns the type and name tuple of this plugin instance.
28+
TypedName() TypedName
2929
}
3030

3131
// Handle provides plugins a set of standard data and tools to work with

pkg/epp/plugins/typedname.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,3 @@ const (
3636
func (tn *TypedName) String() string {
3737
return tn.Type + Separator + tn.Name
3838
}
39-
40-
func (tn *TypedName) GetTypedName() TypedName {
41-
return *tn
42-
}

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.GetTypedName().Type)
315+
log.FromContext(ctx).V(logutil.DEBUG).Info("Running pre-request plugin", "plugin", plugin.TypedName().Type)
316316
before := time.Now()
317317
plugin.PreRequest(ctx, request, schedulingResult, targetPort)
318-
metrics.RecordRequestControlPluginProcessingLatency(PreRequestPluginType, plugin.GetTypedName().Type, time.Since(before))
318+
metrics.RecordRequestControlPluginProcessingLatency(PreRequestPluginType, plugin.TypedName().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.GetTypedName().Type)
324+
log.FromContext(ctx).V(logutil.DEBUG).Info("Running post-response plugin", "plugin", plugin.TypedName().Type)
325325
before := time.Now()
326326
plugin.PostResponse(ctx, request, response, targetPod)
327-
metrics.RecordRequestControlPluginProcessingLatency(PostResponsePluginType, plugin.GetTypedName().Type, time.Since(before))
327+
metrics.RecordRequestControlPluginProcessingLatency(PostResponsePluginType, plugin.TypedName().Type, time.Since(before))
328328
}
329329
}

pkg/epp/requestcontrol/director_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,17 +695,21 @@ const (
695695
)
696696

697697
type testPostResponse struct {
698-
plugins.TypedName
698+
tn plugins.TypedName
699699
lastRespOnResponse *Response
700700
lastTargetPodOnResponse string
701701
}
702702

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

709+
func (p *testPostResponse) TypedName() plugins.TypedName {
710+
return p.tn
711+
}
712+
709713
func (p *testPostResponse) PostResponse(_ context.Context, _ *schedulingtypes.LLMRequest, response *Response, targetPod *backend.Pod) {
710714
p.lastRespOnResponse = response
711715
p.lastTargetPodOnResponse = targetPod.NamespacedName.String()

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

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

136-
func (f *DecisionTreeFilter) GetTypedName() plugins.TypedName {
136+
func (f *DecisionTreeFilter) TypedName() plugins.TypedName {
137137
if f == nil {
138138
// TODO: this keeps the previous behavior ("nil"/"") - not sure
139139
// why done this way.
140140
// Change to empty TypedName or some more meaningful values?
141141
return plugins.TypedName{Type: "nil", Name: ""}
142142
}
143-
return f.Current.GetTypedName()
143+
return f.Current.TypedName()
144144
}
145145

146146
// Filter filters out pods that doesn't meet the filter criteria.
@@ -157,7 +157,7 @@ func (f *DecisionTreeFilter) Filter(ctx context.Context, cycleState *types.Cycle
157157
if f.NextOnSuccess != nil {
158158
next = f.NextOnSuccess
159159
}
160-
loggerTrace.Info("Filter succeeded", "filter", f.GetTypedName(), "next", next.GetTypedName(), "filteredPodCount", len(filteredPod))
160+
loggerTrace.Info("Filter succeeded", "filter", f.TypedName(), "next", next.TypedName(), "filteredPodCount", len(filteredPod))
161161
// On success, pass the filtered result to the next filter.
162162
return next.Filter(ctx, cycleState, request, filteredPod)
163163
} else {
@@ -168,7 +168,7 @@ func (f *DecisionTreeFilter) Filter(ctx context.Context, cycleState *types.Cycle
168168
if f.NextOnFailure != nil {
169169
next = f.NextOnFailure
170170
}
171-
loggerTrace.Info("Filter failed", "filter", f.GetTypedName(), "next", next.GetTypedName())
171+
loggerTrace.Info("Filter failed", "filter", f.TypedName(), "next", next.TypedName())
172172
// On failure, pass the initial set of pods to the next filter.
173173
return next.Filter(ctx, cycleState, request, pods)
174174
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ import (
4040
var _ framework.Filter = &filterAll{}
4141

4242
type filterAll struct {
43-
plugins.TypedName
43+
tn plugins.TypedName
44+
}
45+
46+
func (f *filterAll) TypedName() plugins.TypedName {
47+
return f.tn
4448
}
4549

4650
func newFilterAll() *filterAll {
4751
return &filterAll{
48-
TypedName: plugins.TypedName{Type: "filter-all", Name: "test-all"},
52+
tn: plugins.TypedName{Type: "filter-all", Name: "test-all"},
4953
}
5054
}
5155

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

Lines changed: 8 additions & 3 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{Type: LeastKVCacheFilterType, Name: LeastKVCacheFilterType},
44+
tn: plugins.TypedName{Type: LeastKVCacheFilterType, Name: LeastKVCacheFilterType},
4545
}
4646
}
4747

@@ -51,12 +51,17 @@ func NewLeastKVCacheFilter() *LeastKVCacheFilter {
5151
// should consider them all instead of the absolute minimum one. This worked better than picking the
5252
// least one as it gives more choices for the next filter, which on aggregate gave better results.
5353
type LeastKVCacheFilter struct {
54-
plugins.TypedName
54+
tn plugins.TypedName
55+
}
56+
57+
// TypedName returns the type and name tuple of this plugin instance.
58+
func (f *LeastKVCacheFilter) TypedName() plugins.TypedName {
59+
return f.tn
5560
}
5661

5762
// WithName sets the name of the filter.
5863
func (f *LeastKVCacheFilter) WithName(name string) *LeastKVCacheFilter {
59-
f.Name = name
64+
f.tn.Name = name
6065
return f
6166
}
6267

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

Lines changed: 8 additions & 3 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{Type: LeastQueueFilterType, Name: LeastQueueFilterType},
44+
tn: plugins.TypedName{Type: LeastQueueFilterType, Name: LeastQueueFilterType},
4545
}
4646
}
4747

@@ -51,12 +51,17 @@ func NewLeastQueueFilter() *LeastQueueFilter {
5151
// we should consider them all instead of the absolute minimum one. This worked better than picking
5252
// the least one as it gives more choices for the next filter, which on aggregate gave better results.
5353
type LeastQueueFilter struct {
54-
plugins.TypedName
54+
tn plugins.TypedName
55+
}
56+
57+
// TypedName returns the type and name tuple of this plugin instance.
58+
func (f *LeastQueueFilter) TypedName() plugins.TypedName {
59+
return f.tn
5560
}
5661

5762
// WithName sets the name of the filter.
5863
func (f *LeastQueueFilter) WithName(name string) *LeastQueueFilter {
59-
f.Name = name
64+
f.tn.Name = name
6065
return f
6166
}
6267

0 commit comments

Comments
 (0)