Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for acceptable routing strategies #352

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/plugins/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"io"
"slices"
"strings"
"time"

Expand All @@ -46,6 +47,7 @@ import (
var (
defaultRPM = 100
defaultTPMMultiplier = 1000
routingStrategies = []string{"random", "least-request", "throughput"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there source of truth or single constant we can use? I remember somewhere else have the definition

)

type Server struct {
Expand Down Expand Up @@ -159,6 +161,14 @@ func (s *Server) HandleRequestHeaders(ctx context.Context, requestID string, req
routingStrategy = utils.GetEnv("ROUTING_ALGORITHM", "")
}

if !slices.Contains(routingStrategies, routingStrategy) {
return generateErrorResponse(
envoyTypePb.StatusCode_BadRequest,
[]*configPb.HeaderValueOption{{Header: &configPb.HeaderValue{
Key: "x-incorrect-routing-strategy", RawValue: []byte(routingStrategy),
}}}, ""), utils.User{}, rpm, routingStrategy
}

if username != "" {
user, err = utils.GetUser(utils.User{Name: username}, s.redisClient)
if err != nil {
Expand Down
Loading