Skip to content

Commit 4842c7d

Browse files
Add new test cases for gateway server (#1217)
Signed-off-by: Modi Tamam <[email protected]>
1 parent e3bb459 commit 4842c7d

File tree

8 files changed

+972
-12
lines changed

8 files changed

+972
-12
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/prometheus/common v0.55.0
2424
github.com/ray-project/kuberay/ray-operator v1.2.1
2525
github.com/redis/go-redis/v9 v9.6.1
26-
github.com/stretchr/testify v1.9.0
26+
github.com/stretchr/testify v1.10.0
2727
google.golang.org/grpc v1.65.0
2828
k8s.io/api v0.31.2
2929
k8s.io/apiextensions-apiserver v0.31.2
@@ -87,6 +87,7 @@ require (
8787
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
8888
github.com/prometheus/procfs v0.15.1 // indirect
8989
github.com/spf13/pflag v1.0.5 // indirect
90+
github.com/stretchr/objx v0.5.2 // indirect
9091
github.com/tidwall/gjson v1.14.4 // indirect
9192
github.com/tidwall/match v1.1.1 // indirect
9293
github.com/tidwall/pretty v1.2.1 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,14 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99
174174
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
175175
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
176176
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
177+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
178+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
177179
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
178180
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
179181
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
180182
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
183+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
184+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
181185
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
182186
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
183187
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=

pkg/plugins/gateway/algorithms/router.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ limitations under the License.
1717
package routingalgorithms
1818

1919
import (
20-
"github.com/vllm-project/aibrix/pkg/types"
20+
"sync"
2121

22+
"github.com/vllm-project/aibrix/pkg/types"
2223
"k8s.io/klog/v2"
2324
)
2425

26+
var routerMu sync.RWMutex
27+
2528
const (
2629
RouterNotSet = ""
2730
)
@@ -31,6 +34,8 @@ var routerConstructor = map[types.RoutingAlgorithm]types.RouterProviderRegistrat
3134

3235
// Validate validates if user provided routing routers is supported by gateway
3336
func Validate(algorithms string) (types.RoutingAlgorithm, bool) {
37+
routerMu.RLock()
38+
defer routerMu.RUnlock()
3439
if _, ok := routerFactory[types.RoutingAlgorithm(algorithms)]; ok {
3540
return types.RoutingAlgorithm(algorithms), ok
3641
} else {
@@ -41,6 +46,8 @@ func Validate(algorithms string) (types.RoutingAlgorithm, bool) {
4146
// Select the user provided router provider supported by gateway, no error reported and fallback to random router
4247
// Call Validate before this function to ensure expected behavior.
4348
func Select(algorithms types.RoutingAlgorithm) types.RouterProviderFunc {
49+
routerMu.RLock()
50+
defer routerMu.RUnlock()
4451
if provider, ok := routerFactory[algorithms]; ok {
4552
return provider
4653
} else {
@@ -50,6 +57,8 @@ func Select(algorithms types.RoutingAlgorithm) types.RouterProviderFunc {
5057
}
5158

5259
func Register(algorithm types.RoutingAlgorithm, constructor types.RouterConstructor) {
60+
routerMu.Lock()
61+
defer routerMu.Unlock()
5362
routerConstructor[algorithm] = func() types.RouterProviderFunc {
5463
router, err := constructor()
5564
if err != nil {
@@ -63,6 +72,8 @@ func Register(algorithm types.RoutingAlgorithm, constructor types.RouterConstruc
6372
}
6473

6574
func Init() {
75+
routerMu.Lock()
76+
defer routerMu.Unlock()
6677
for algorithm, constructor := range routerConstructor {
6778
routerFactory[algorithm] = constructor()
6879
klog.Infof("Registered router for %s", algorithm)

pkg/plugins/gateway/gateway_req_body.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (s *Server) HandleRequestBody(ctx context.Context, requestID string, reques
5252

5353
// early reject if no pods are ready to accept request for a model
5454
podsArr, err := s.cache.ListPodsByModel(model)
55-
if err != nil || podsArr == nil || podsArr.Len() == 0 || utils.CountRoutablePods(podsArr.All()) == 0 {
55+
if err != nil || podsArr == nil || utils.CountRoutablePods(podsArr.All()) == 0 {
5656
klog.ErrorS(err, "no ready pod available", "requestID", requestID, "model", model)
5757
return generateErrorResponse(envoyTypePb.StatusCode_ServiceUnavailable,
5858
[]*configPb.HeaderValueOption{{Header: &configPb.HeaderValue{

0 commit comments

Comments
 (0)