Skip to content

[WIP] Add X-Gateway-BBR header to BBR processing #576

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
40 changes: 23 additions & 17 deletions pkg/body-based-routing/handlers/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
)

const modelHeader = "X-Gateway-Model-Name"
const (
modelHeader = "X-Gateway-Model-Name"
processedHeader = "X-Gateway-BBR"
)

// HandleRequestBody handles request bodies.
func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]*eppb.ProcessingResponse, error) {
Expand Down Expand Up @@ -79,14 +82,7 @@ func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]
Response: &eppb.CommonResponse{
ClearRouteCache: true,
HeaderMutation: &eppb.HeaderMutation{
SetHeaders: []*basepb.HeaderValueOption{
{
Header: &basepb.HeaderValue{
Key: modelHeader,
RawValue: []byte(modelStr),
},
},
},
SetHeaders: headersToAdd(modelStr),
},
},
},
Expand All @@ -104,14 +100,7 @@ func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]
// Necessary so that the new headers are used in the routing decision.
ClearRouteCache: true,
HeaderMutation: &eppb.HeaderMutation{
SetHeaders: []*basepb.HeaderValueOption{
{
Header: &basepb.HeaderValue{
Key: modelHeader,
RawValue: []byte(modelStr),
},
},
},
SetHeaders: headersToAdd(modelStr),
},
},
},
Expand All @@ -120,6 +109,23 @@ func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]
}, nil
}

func headersToAdd(model string) []*basepb.HeaderValueOption {
return []*basepb.HeaderValueOption{
{
Header: &basepb.HeaderValue{
Key: modelHeader,
RawValue: []byte(model),
},
},
{
Header: &basepb.HeaderValue{
Key: processedHeader,
RawValue: []byte("true"),
},
},
}
}

func addStreamedBodyResponse(responses []*eppb.ProcessingResponse, requestBodyBytes []byte) []*eppb.ProcessingResponse {
return append(responses, &extProcPb.ProcessingResponse{
Response: &extProcPb.ProcessingResponse_RequestBody{
Expand Down
12 changes: 12 additions & 0 deletions pkg/body-based-routing/handlers/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func TestHandleRequestBody(t *testing.T) {
RawValue: []byte("foo"),
},
},
{
Header: &basepb.HeaderValue{
Key: "X-Gateway-BBR",
RawValue: []byte("true"),
},
},
},
},
},
Expand Down Expand Up @@ -146,6 +152,12 @@ func TestHandleRequestBody(t *testing.T) {
RawValue: []byte("foo"),
},
},
{
Header: &basepb.HeaderValue{
Key: "X-Gateway-BBR",
RawValue: []byte("true"),
},
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions test/integration/bbr/hermetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func TestBodyBasedRouting(t *testing.T) {
RawValue: []byte("llama"),
},
},
{
Header: &configPb.HeaderValue{
Key: "X-Gateway-BBR",
RawValue: []byte("true"),
},
},
},
wantErr: false,
},
Expand Down