Skip to content

Commit

Permalink
remove each time initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
varungupta authored and varungupta committed Sep 11, 2024
1 parent 893ca64 commit 0755f3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions pkg/plugins/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
)

type Server struct {
routers map[string]routing.Router
ratelimiter ratelimiter.AccountRateLimiter
client kubernetes.Interface
requestCountTracker map[string]int
Expand All @@ -55,8 +56,14 @@ func NewServer(r ratelimiter.AccountRateLimiter, c kubernetes.Interface) *Server
if err != nil {
panic(err)
}
routers := map[string]routing.Router{
"random": routing.NewRandomRouter(),
"least-request": routing.NewLeastRequestRouter(r),
"throughput": routing.NewThroughputRouter(r),
}

return &Server{
routers: routers,
ratelimiter: r,
client: c,
requestCountTracker: map[string]int{},
Expand Down Expand Up @@ -464,17 +471,16 @@ func (s *Server) checkTPM(ctx context.Context, user string) (envoyTypePb.StatusC
}

func (s *Server) SelectTargetPod(ctx context.Context, routingStrategy string, pods []corev1.Pod) (string, error) {
// TODO (varun): evaluate how to enable selection of routing algorithm
var route routing.Router
switch routingStrategy {
case "random":
route = routing.NewRandomRouter()
route = s.routers[routingStrategy]
case "least-request":
route = routing.NewLeastRequestRouter(s.ratelimiter)
route = s.routers[routingStrategy]
case "throughput":
route = routing.NewThroughputRouter(s.ratelimiter)
route = s.routers[routingStrategy]
default:
return "", nil
route = s.routers["random"]
}

return route.Get(ctx, pods)
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/gateway/routing_algorithms/least_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r leastRequestRouter) Get(ctx context.Context, pods []v1.Pod) (string, err
reqCount := podRequestCounts[podRequestCount]
klog.Infof("PodIP: %s, PodRequestCount: %v", podIP, reqCount)
if reqCount <= minCount {
minCount = int(reqCount)
minCount = reqCount
targetPodIP = podIP
}
}
Expand Down

0 comments on commit 0755f3a

Please sign in to comment.