@@ -22,6 +22,7 @@ import (
22
22
23
23
"github.com/google/go-cmp/cmp"
24
24
"github.com/google/uuid"
25
+ "google.golang.org/protobuf/types/known/structpb"
25
26
k8stypes "k8s.io/apimachinery/pkg/types"
26
27
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
27
28
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
@@ -247,3 +248,117 @@ func TestLoRASoftAffinityDistribution(t *testing.T) {
247
248
actualAvailablePercent , availableLowerBound , availableUpperBound )
248
249
}
249
250
}
251
+
252
+ func TestSubsettingFilter (t * testing.T ) {
253
+ var makeFilterMetadata = func (data interface {}) map [string ]* structpb.Struct {
254
+ structVal , _ := structpb .NewStruct (map [string ]interface {}{
255
+ "x-gateway-destination-endpoint-subset" : data ,
256
+ })
257
+
258
+ return map [string ]* structpb.Struct {
259
+ "envoy.lb.subset_hint" : structVal ,
260
+ }
261
+ }
262
+
263
+ tests := []struct {
264
+ name string
265
+ req * types.LLMRequest
266
+ filter framework.Filter
267
+ input []types.Pod
268
+ output []types.Pod
269
+ }{
270
+ {
271
+ name : "SubsetFilter, filter not present — return all pods" ,
272
+ req : & types.LLMRequest {
273
+ Headers : map [string ]string {},
274
+ FilterMetadata : map [string ]* structpb.Struct {},
275
+ },
276
+ filter : & SubsetFilter {},
277
+ input : []types.Pod {
278
+ & types.PodMetrics {
279
+ Pod : & backend.Pod {Address : "10.0.0.1" },
280
+ },
281
+ & types.PodMetrics {
282
+ Pod : & backend.Pod {Address : "10.0.0.2" },
283
+ },
284
+ },
285
+ output : []types.Pod {
286
+ & types.PodMetrics {
287
+ Pod : & backend.Pod {Address : "10.0.0.1" },
288
+ },
289
+ & types.PodMetrics {
290
+ Pod : & backend.Pod {Address : "10.0.0.2" },
291
+ },
292
+ },
293
+ },
294
+ {
295
+ name : "SubsetFilter, subset with one matching pod" ,
296
+ req : & types.LLMRequest {
297
+ FilterMetadata : makeFilterMetadata ([]interface {}{"10.0.0.1" }),
298
+ },
299
+ filter : & SubsetFilter {},
300
+ input : []types.Pod {
301
+ & types.PodMetrics {
302
+ Pod : & backend.Pod {Address : "10.0.0.1" },
303
+ },
304
+ & types.PodMetrics {
305
+ Pod : & backend.Pod {Address : "10.0.0.2" },
306
+ },
307
+ },
308
+ output : []types.Pod {
309
+ & types.PodMetrics {
310
+ Pod : & backend.Pod {Address : "10.0.0.1" },
311
+ },
312
+ },
313
+ },
314
+ {
315
+ name : "SubsetFilter, subset with multiple matching pods" ,
316
+ req : & types.LLMRequest {
317
+ FilterMetadata : makeFilterMetadata ([]interface {}{"10.0.0.1" , "10.0.0.2" , "10.0.0.3" }),
318
+ },
319
+ filter : & SubsetFilter {},
320
+ input : []types.Pod {
321
+ & types.PodMetrics {
322
+ Pod : & backend.Pod {Address : "10.0.0.1" },
323
+ },
324
+ & types.PodMetrics {
325
+ Pod : & backend.Pod {Address : "10.0.0.2" },
326
+ },
327
+ },
328
+ output : []types.Pod {
329
+ & types.PodMetrics {
330
+ Pod : & backend.Pod {Address : "10.0.0.1" },
331
+ },
332
+ & types.PodMetrics {
333
+ Pod : & backend.Pod {Address : "10.0.0.2" },
334
+ },
335
+ },
336
+ },
337
+ {
338
+ name : "SubsetFilter, subset with no matching pods" ,
339
+ req : & types.LLMRequest {
340
+ FilterMetadata : makeFilterMetadata ([]interface {}{"10.0.0.3" }),
341
+ },
342
+ filter : & SubsetFilter {},
343
+ input : []types.Pod {
344
+ & types.PodMetrics {
345
+ Pod : & backend.Pod {Address : "10.0.0.1" },
346
+ },
347
+ & types.PodMetrics {
348
+ Pod : & backend.Pod {Address : "10.0.0.2" },
349
+ },
350
+ },
351
+ output : []types.Pod {},
352
+ },
353
+ }
354
+
355
+ for _ , test := range tests {
356
+ t .Run (test .name , func (t * testing.T ) {
357
+ got := test .filter .Filter (context .Background (), test .req , types .NewCycleState (), test .input )
358
+
359
+ if diff := cmp .Diff (test .output , got ); diff != "" {
360
+ t .Errorf ("Unexpected output (-want +got): %v" , diff )
361
+ }
362
+ })
363
+ }
364
+ }
0 commit comments