Skip to content

Commit b6fc802

Browse files
committed
Add additional header to BBR for debugging purposes
1 parent b7d35b6 commit b6fc802

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

pkg/body-based-routing/handlers/request.go

+23-17
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import (
2929
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
3030
)
3131

32-
const modelHeader = "X-Gateway-Model-Name"
32+
const (
33+
modelHeader = "X-Gateway-Model-Name"
34+
processedHeader = "X-Gateway-BBR"
35+
)
3336

3437
// HandleRequestBody handles request bodies.
3538
func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]*eppb.ProcessingResponse, error) {
@@ -79,14 +82,7 @@ func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]
7982
Response: &eppb.CommonResponse{
8083
ClearRouteCache: true,
8184
HeaderMutation: &eppb.HeaderMutation{
82-
SetHeaders: []*basepb.HeaderValueOption{
83-
{
84-
Header: &basepb.HeaderValue{
85-
Key: modelHeader,
86-
RawValue: []byte(modelStr),
87-
},
88-
},
89-
},
85+
SetHeaders: headersToAdd(modelStr),
9086
},
9187
},
9288
},
@@ -104,14 +100,7 @@ func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]
104100
// Necessary so that the new headers are used in the routing decision.
105101
ClearRouteCache: true,
106102
HeaderMutation: &eppb.HeaderMutation{
107-
SetHeaders: []*basepb.HeaderValueOption{
108-
{
109-
Header: &basepb.HeaderValue{
110-
Key: modelHeader,
111-
RawValue: []byte(modelStr),
112-
},
113-
},
114-
},
103+
SetHeaders: headersToAdd(modelStr),
115104
},
116105
},
117106
},
@@ -120,6 +109,23 @@ func (s *Server) HandleRequestBody(ctx context.Context, data map[string]any) ([]
120109
}, nil
121110
}
122111

112+
func headersToAdd(model string) []*basepb.HeaderValueOption {
113+
return []*basepb.HeaderValueOption{
114+
{
115+
Header: &basepb.HeaderValue{
116+
Key: modelHeader,
117+
RawValue: []byte(model),
118+
},
119+
},
120+
{
121+
Header: &basepb.HeaderValue{
122+
Key: processedHeader,
123+
RawValue: []byte("true"),
124+
},
125+
},
126+
}
127+
}
128+
123129
func addStreamedBodyResponse(responses []*eppb.ProcessingResponse, requestBodyBytes []byte) []*eppb.ProcessingResponse {
124130
return append(responses, &extProcPb.ProcessingResponse{
125131
Response: &extProcPb.ProcessingResponse_RequestBody{

pkg/body-based-routing/handlers/request_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ func TestHandleRequestBody(t *testing.T) {
117117
RawValue: []byte("foo"),
118118
},
119119
},
120+
{
121+
Header: &basepb.HeaderValue{
122+
Key: "X-Gateway-BBR",
123+
RawValue: []byte("true"),
124+
},
125+
},
120126
},
121127
},
122128
},
@@ -146,6 +152,12 @@ func TestHandleRequestBody(t *testing.T) {
146152
RawValue: []byte("foo"),
147153
},
148154
},
155+
{
156+
Header: &basepb.HeaderValue{
157+
Key: "X-Gateway-BBR",
158+
RawValue: []byte("true"),
159+
},
160+
},
149161
},
150162
},
151163
},

test/integration/bbr/hermetic_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ func TestBodyBasedRouting(t *testing.T) {
5454
RawValue: []byte("llama"),
5555
},
5656
},
57+
{
58+
Header: &configPb.HeaderValue{
59+
Key: "X-Gateway-BBR",
60+
RawValue: []byte("true"),
61+
},
62+
},
5763
},
5864
wantErr: false,
5965
},

0 commit comments

Comments
 (0)