Skip to content

Commit ca4cc1d

Browse files
committed
implement GetTypedName()
Signed-off-by: Etai Lev Ran <[email protected]>
1 parent 51b5570 commit ca4cc1d

File tree

18 files changed

+53
-183
lines changed

18 files changed

+53
-183
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.NewTypedName("header-based-testing", "header-based-testing-filter"),
43+
TypedName: plugins.TypedName{PluginType: "header-based-testing", PluginName: "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.NewTypedName(test1Type, "test-1"),
564+
TypedName: plugins.TypedName{PluginType: test1Type, PluginName: "test-1"},
565565
}
566566
}
567567

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

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

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

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

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

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

pkg/epp/plugins/plugins.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Plugin interface {
2828
Type() string
2929
// Name returns the name of this plugin instance.
3030
Name() string
31+
// GetTypedName returns the type and name of this plugin instance.
32+
GetTypedName() TypedName
3133
}
3234

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

pkg/epp/plugins/typedname.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@ 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-
objType string
25-
objName string
26-
}
27-
28-
// NewTypedName returns a new TypedName struct configured with
29-
// the given type and name.
30-
func NewTypedName(objtype, objname string) TypedName {
31-
return TypedName{
32-
objType: objtype,
33-
objName: objname,
34-
}
24+
PluginType string
25+
PluginName string
3526
}
3627

3728
// Type returns the type of the plugin.
3829
func (tn *TypedName) Type() string {
39-
return tn.objType
30+
return tn.PluginType
4031
}
4132

4233
// Name returns the name of this plugin instance.
4334
func (tn *TypedName) Name() string {
44-
return tn.objName
35+
return tn.PluginName
36+
}
37+
38+
const (
39+
Separator = "/"
40+
)
41+
42+
// String returns the type and name rendered as
43+
// "<type>/<name>".
44+
func (tn *TypedName) String() string {
45+
return tn.PluginType + Separator + tn.PluginName
4546
}
4647

47-
// SetName sets the instance name.
48-
func (tn *TypedName) SetName(name string) {
49-
tn.objName = name
48+
func (tn *TypedName) GetTypedName() TypedName {
49+
return *tn
5050
}

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.NewTypedName(testPostResponseType, name),
705+
TypedName: plugins.TypedName{PluginType: testPostResponseType, PluginName: name},
706706
}
707707
}
708708

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ func (f *DecisionTreeFilter) Name() string {
149149
return f.Current.Name()
150150
}
151151

152+
func (f *DecisionTreeFilter) GetTypedName() plugins.TypedName {
153+
return plugins.TypedName{
154+
PluginType: f.Type(),
155+
PluginName: f.Name(),
156+
}
157+
}
158+
152159
// Filter filters out pods that doesn't meet the filter criteria.
153160
func (f *DecisionTreeFilter) Filter(ctx context.Context, cycleState *types.CycleState, request *types.LLMRequest, pods []types.Pod) []types.Pod {
154161
loggerTrace := log.FromContext(ctx).V(logutil.TRACE)

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

Lines changed: 1 addition & 140 deletions
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.NewTypedName("filter-all", "test-all"),
48+
TypedName: plugins.TypedName{PluginType: "filter-all", PluginName: "test-all"},
4949
}
5050
}
5151

@@ -258,145 +258,6 @@ func TestLoRASoftAffinityDistribution(t *testing.T) {
258258
}
259259
}
260260

261-
func TestSubsettingFilter(t *testing.T) {
262-
var makeFilterMetadata = func(data []interface{}) map[string]any {
263-
return map[string]any{
264-
"envoy.lb.subset_hint": map[string]any{
265-
"x-gateway-destination-endpoint-subset": data,
266-
},
267-
}
268-
}
269-
270-
tests := []struct {
271-
name string
272-
metadata map[string]any
273-
filter framework.Filter
274-
input []types.Pod
275-
output []types.Pod
276-
}{
277-
{
278-
name: "SubsetFilter, filter not present — return all pods",
279-
filter: NewSubsetFilter(),
280-
metadata: map[string]any{},
281-
input: []types.Pod{
282-
&types.PodMetrics{
283-
Pod: &backend.Pod{Address: "10.0.0.1"},
284-
},
285-
&types.PodMetrics{
286-
Pod: &backend.Pod{Address: "10.0.0.2"},
287-
},
288-
},
289-
output: []types.Pod{
290-
&types.PodMetrics{
291-
Pod: &backend.Pod{Address: "10.0.0.1"},
292-
},
293-
&types.PodMetrics{
294-
Pod: &backend.Pod{Address: "10.0.0.2"},
295-
},
296-
},
297-
},
298-
{
299-
name: "SubsetFilter, namespace present filter not present — return all pods",
300-
filter: NewSubsetFilter(),
301-
metadata: map[string]any{"envoy.lb.subset_hint": map[string]any{}},
302-
input: []types.Pod{
303-
&types.PodMetrics{
304-
Pod: &backend.Pod{Address: "10.0.0.1"},
305-
},
306-
&types.PodMetrics{
307-
Pod: &backend.Pod{Address: "10.0.0.2"},
308-
},
309-
},
310-
output: []types.Pod{
311-
&types.PodMetrics{
312-
Pod: &backend.Pod{Address: "10.0.0.1"},
313-
},
314-
&types.PodMetrics{
315-
Pod: &backend.Pod{Address: "10.0.0.2"},
316-
},
317-
},
318-
},
319-
{
320-
name: "SubsetFilter, filter present with empty list — return no pods",
321-
filter: NewSubsetFilter(),
322-
metadata: makeFilterMetadata([]interface{}{}),
323-
input: []types.Pod{
324-
&types.PodMetrics{
325-
Pod: &backend.Pod{Address: "10.0.0.1"},
326-
},
327-
&types.PodMetrics{
328-
Pod: &backend.Pod{Address: "10.0.0.2"},
329-
},
330-
},
331-
output: []types.Pod{},
332-
},
333-
{
334-
name: "SubsetFilter, subset with one matching pod",
335-
metadata: makeFilterMetadata([]interface{}{"10.0.0.1"}),
336-
filter: NewSubsetFilter(),
337-
input: []types.Pod{
338-
&types.PodMetrics{
339-
Pod: &backend.Pod{Address: "10.0.0.1"},
340-
},
341-
&types.PodMetrics{
342-
Pod: &backend.Pod{Address: "10.0.0.2"},
343-
},
344-
},
345-
output: []types.Pod{
346-
&types.PodMetrics{
347-
Pod: &backend.Pod{Address: "10.0.0.1"},
348-
},
349-
},
350-
},
351-
{
352-
name: "SubsetFilter, subset with multiple matching pods",
353-
metadata: makeFilterMetadata([]interface{}{"10.0.0.1", "10.0.0.2", "10.0.0.3"}),
354-
filter: NewSubsetFilter(),
355-
input: []types.Pod{
356-
&types.PodMetrics{
357-
Pod: &backend.Pod{Address: "10.0.0.1"},
358-
},
359-
&types.PodMetrics{
360-
Pod: &backend.Pod{Address: "10.0.0.2"},
361-
},
362-
},
363-
output: []types.Pod{
364-
&types.PodMetrics{
365-
Pod: &backend.Pod{Address: "10.0.0.1"},
366-
},
367-
&types.PodMetrics{
368-
Pod: &backend.Pod{Address: "10.0.0.2"},
369-
},
370-
},
371-
},
372-
{
373-
name: "SubsetFilter, subset with no matching pods",
374-
metadata: makeFilterMetadata([]interface{}{"10.0.0.3"}),
375-
filter: NewSubsetFilter(),
376-
input: []types.Pod{
377-
&types.PodMetrics{
378-
Pod: &backend.Pod{Address: "10.0.0.1"},
379-
},
380-
&types.PodMetrics{
381-
Pod: &backend.Pod{Address: "10.0.0.2"},
382-
},
383-
},
384-
output: []types.Pod{},
385-
},
386-
}
387-
388-
for _, test := range tests {
389-
t.Run(test.name, func(t *testing.T) {
390-
req := types.NewLLMRequest(uuid.NewString(), "", "", nil, test.metadata)
391-
got := test.filter.Filter(context.Background(), types.NewCycleState(), req, test.input)
392-
393-
if diff := cmp.Diff(test.output, got); diff != "" {
394-
t.Errorf("Unexpected output (-want +got): %v", diff)
395-
}
396-
})
397-
}
398-
}
399-
400261
// TestDecisionTreeFilterFactory tests that the DecisionTreeFilterFactory function
401262
// properly instantiates DecisionTreeFilter instances
402263
func TestDecisionTreeFilterFactory(t *testing.T) {

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.NewTypedName(LeastKVCacheFilterType, LeastKVCacheFilterType),
44+
TypedName: plugins.TypedName{PluginType: LeastKVCacheFilterType, PluginName: 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.TypedName.SetName(name)
59+
f.PluginName = 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.NewTypedName(LeastQueueFilterType, LeastQueueFilterType),
44+
TypedName: plugins.TypedName{PluginType: LeastQueueFilterType, PluginName: 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.TypedName.SetName(name)
59+
f.PluginName = name
6060
return f
6161
}
6262

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func LoraAffinityFilterFactory(name string, rawParameters json.RawMessage, _ plu
5252
// NewLoraAffinityFilter initializes a new LoraAffinityFilter and returns its pointer.
5353
func NewLoraAffinityFilter(threshold float64) *LoraAffinityFilter {
5454
return &LoraAffinityFilter{
55-
TypedName: plugins.NewTypedName(LoraAffinityFilterType, LoraAffinityFilterType),
55+
TypedName: plugins.TypedName{PluginType: LoraAffinityFilterType, PluginName: LoraAffinityFilterType},
5656
loraAffinityThreshold: threshold,
5757
}
5858
}
@@ -71,7 +71,7 @@ type LoraAffinityFilter struct {
7171

7272
// WithName sets the type of the filter.
7373
func (f *LoraAffinityFilter) WithName(name string) *LoraAffinityFilter {
74-
f.TypedName.SetName(name)
74+
f.PluginName = name
7575
return f
7676
}
7777

0 commit comments

Comments
 (0)