Skip to content

Commit d7e1b64

Browse files
authored
Enable multiple endpoints in conformance EPP (#964)
1 parent 7fd141c commit d7e1b64

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,40 @@ func TestFilter(t *testing.T) {
7979
},
8080
},
8181
},
82+
{
83+
name: "TestHeaderBasedFilter, multiple header endpoints set and multiple matches",
84+
req: &types.LLMRequest{Headers: map[string]string{headerTestEppEndPointSelectionKey: "test-endpoint3,test-endpoint2"}},
85+
filter: &HeaderBasedTestingFilter{},
86+
input: []types.Pod{
87+
&types.PodMetrics{
88+
Pod: &backend.Pod{
89+
Address: "test-endpoint1",
90+
},
91+
},
92+
&types.PodMetrics{
93+
Pod: &backend.Pod{
94+
Address: "test-endpoint2",
95+
},
96+
},
97+
&types.PodMetrics{
98+
Pod: &backend.Pod{
99+
Address: "test-endpoint3",
100+
},
101+
},
102+
},
103+
output: []types.Pod{
104+
&types.PodMetrics{
105+
Pod: &backend.Pod{
106+
Address: "test-endpoint3",
107+
},
108+
},
109+
&types.PodMetrics{
110+
Pod: &backend.Pod{
111+
Address: "test-endpoint2",
112+
},
113+
},
114+
},
115+
},
82116
}
83117

84118
for _, test := range tests {

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@ package filter
1818

1919
import (
2020
"context"
21+
"strings"
2122

2223
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
2324
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
2425
)
2526

2627
const (
28+
// headerTestEppEndPointSelectionKey is the header used for testing purposes to make EPP behavior controllable.
29+
// The header value should be a comma-separated list of endpoint IP addresses.
30+
// E.g., "test-epp-endpoint-selection": "10.0.0.7,10.0.0.8"
31+
// The returned order is the same as the order provided in the header.
2732
headerTestEppEndPointSelectionKey = "test-epp-endpoint-selection"
2833
)
2934

3035
// compile-time type assertion
3136
var _ framework.Filter = &HeaderBasedTestingFilter{}
3237

33-
// NewHeaderBasedTestingFilter initializes a new HeaderBasedTestingFilter and returns its pointer.
34-
// This should be only used in testing purpose.
38+
// NewHeaderBasedTestingFilter initializes a new HeaderBasedTestingFilter.
39+
// This should only be used for testing purposes.
3540
func NewHeaderBasedTestingFilter() *HeaderBasedTestingFilter {
3641
return &HeaderBasedTestingFilter{}
3742
}
@@ -41,20 +46,26 @@ type HeaderBasedTestingFilter struct{}
4146

4247
// Name returns the name of the filter.
4348
func (f *HeaderBasedTestingFilter) Name() string {
44-
return "test-header-based"
49+
return "header-based-testing"
4550
}
4651

47-
// Filter filters out pods that doesn't meet the filter criteria.
52+
// Filter selects pods that match the IP addresses specified in the request header.
4853
func (f *HeaderBasedTestingFilter) Filter(_ context.Context, request *types.LLMRequest, _ *types.CycleState, pods []types.Pod) []types.Pod {
49-
filteredPods := []types.Pod{}
50-
51-
endPointInReqeust, found := request.Headers[headerTestEppEndPointSelectionKey]
52-
if !found {
53-
return filteredPods
54+
headerValue, ok := request.Headers[headerTestEppEndPointSelectionKey]
55+
if !ok || headerValue == "" {
56+
return []types.Pod{}
5457
}
5558

59+
podAddressMap := make(map[string]types.Pod, len(pods))
5660
for _, pod := range pods {
57-
if pod.GetPod().Address == endPointInReqeust {
61+
podAddressMap[pod.GetPod().Address] = pod
62+
}
63+
64+
endpoints := strings.Split(headerValue, ",")
65+
filteredPods := make([]types.Pod, 0, len(endpoints))
66+
for _, endpoint := range endpoints {
67+
trimmedEndpoint := strings.TrimSpace(endpoint)
68+
if pod, found := podAddressMap[trimmedEndpoint]; found {
5869
filteredPods = append(filteredPods, pod)
5970
}
6071
}

0 commit comments

Comments
 (0)