@@ -10,104 +10,60 @@ import (
10
10
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend"
11
11
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics" // Import config for thresholds
12
12
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
13
- "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
14
13
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
15
14
16
15
"github.com/llm-d/llm-d-inference-scheduler/pkg/plugins/scorer"
17
16
)
18
17
19
18
func TestLoadBasedScorer (t * testing.T ) {
19
+ podA := & types.PodMetrics {
20
+ Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod-a" }},
21
+ MetricsState : & backendmetrics.MetricsState {
22
+ WaitingQueueSize : 2 ,
23
+ },
24
+ }
25
+ podB := & types.PodMetrics {
26
+ Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod-b" }},
27
+ MetricsState : & backendmetrics.MetricsState {
28
+ WaitingQueueSize : 0 ,
29
+ },
30
+ }
31
+ podC := & types.PodMetrics {
32
+ Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod-c" }},
33
+ MetricsState : & backendmetrics.MetricsState {
34
+ WaitingQueueSize : 15 ,
35
+ },
36
+ }
37
+
20
38
tests := []struct {
21
- name string
22
- scorer framework.Scorer
23
- req * types.LLMRequest
24
- input []types.Pod
25
- wantRes * types.ProfileRunResult
26
- err bool
39
+ name string
40
+ scorer framework.Scorer
41
+ req * types.LLMRequest
42
+ input []types.Pod
43
+ wantScores map [types.Pod ]float64
27
44
}{
28
45
{
29
46
name : "load based scorer" ,
30
47
scorer : scorer .NewLoadAwareScorer (context .Background (), 10 ),
31
-
32
48
req : & types.LLMRequest {
33
49
TargetModel : "critical" ,
34
50
},
35
- // pod2 will be picked because it has the shortest queue
36
51
input : []types.Pod {
37
- & types.PodMetrics {
38
- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod1" }},
39
- MetricsState : & backendmetrics.MetricsState {
40
- WaitingQueueSize : 2 ,
41
- KVCacheUsagePercent : 0.2 ,
42
- MaxActiveModels : 2 ,
43
- ActiveModels : map [string ]int {
44
- "foo" : 1 ,
45
- "bar" : 1 ,
46
- },
47
- },
48
- },
49
-
50
- & types.PodMetrics {
51
- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod2" }},
52
- MetricsState : & backendmetrics.MetricsState {
53
- WaitingQueueSize : 0 ,
54
- KVCacheUsagePercent : 0.2 ,
55
- MaxActiveModels : 2 ,
56
- ActiveModels : map [string ]int {
57
- "foo" : 1 ,
58
- "bar" : 1 ,
59
- },
60
- },
61
- },
62
- & types.PodMetrics {
63
- Pod : & backend.Pod {NamespacedName : k8stypes.NamespacedName {Name : "pod3" }},
64
- MetricsState : & backendmetrics.MetricsState {
65
- WaitingQueueSize : 5 ,
66
- KVCacheUsagePercent : 0.2 ,
67
- MaxActiveModels : 2 ,
68
- ActiveModels : map [string ]int {
69
- "foo" : 1 ,
70
- "bar" : 1 ,
71
- },
72
- },
73
- },
52
+ podA , podB , podC ,
74
53
},
75
- wantRes : & types.ProfileRunResult {
76
- TargetPods : []types.Pod {& types.ScoredPod {
77
- Pod : & types.PodMetrics {
78
- Pod : & backend.Pod {
79
- NamespacedName : k8stypes.NamespacedName {Name : "pod2" },
80
- },
81
- MetricsState : & backendmetrics.MetricsState {
82
- WaitingQueueSize : 0 ,
83
- KVCacheUsagePercent : 0.2 ,
84
- MaxActiveModels : 2 ,
85
- ActiveModels : map [string ]int {
86
- "foo" : 1 ,
87
- "bar" : 1 ,
88
- },
89
- },
90
- },
91
- Score : 0.5 ,
92
- },
93
- },
54
+ wantScores : map [types.Pod ]float64 {
55
+ podA : 0.4 ,
56
+ podB : 0.5 ,
57
+ podC : 0 ,
94
58
},
95
59
},
96
60
}
97
61
98
62
for _ , test := range tests {
99
63
t .Run (test .name , func (t * testing.T ) {
100
- schedulerProfile := framework .NewSchedulerProfile ().
101
- WithScorers (framework .NewWeightedScorer (test .scorer , 1 )).
102
- WithPicker (picker .NewMaxScorePicker (picker .DefaultMaxNumOfEndpoints ))
103
-
104
- got , err := schedulerProfile .Run (context .Background (), test .req , nil , test .input )
105
-
106
- if test .err != (err != nil ) {
107
- t .Errorf ("Unexpected error, got %v, want %v" , err , test .err )
108
- }
64
+ got := test .scorer .Score (context .Background (), nil , nil , test .input )
109
65
110
- if diff := cmp .Diff (test .wantRes , got ); diff != "" {
66
+ if diff := cmp .Diff (test .wantScores , got ); diff != "" {
111
67
t .Errorf ("Unexpected output (-want +got): %v" , diff )
112
68
}
113
69
})
0 commit comments