Skip to content

Commit 0b25c88

Browse files
authored
Added port header to response (#232)
* Added port header to response Signed-off-by: irar2 <[email protected]> * Fixed lint error Signed-off-by: irar2 <[email protected]> * Updated readme Signed-off-by: irar2 <[email protected]> --------- Signed-off-by: irar2 <[email protected]>
1 parent 56aed1f commit 0b25c88

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ In addition, as we are using klog, the following parameters are available:
182182
- `vmodule`: comma-separated list of pattern=N settings for file-filtered logging
183183

184184
## Environment variables
185-
- `POD_NAME`: the simulator pod name. If defined, the response will contain the HTTP header `x-inference-pod` with this value
185+
- `POD_NAME`: the simulator pod name. If defined, the response will contain the HTTP header `x-inference-pod` with this value, and the HTTP header `x-inference-port` with the port that the request was received on
186186
- `POD_NAMESPACE`: the simulator pod namespace. If defined, the response will contain the HTTP header `x-inference-namespace` with this value
187187

188188
## Migrating from releases prior to v0.2.0

pkg/llm-d-inference-sim/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"net"
25+
"strconv"
2526

2627
"github.com/buaazp/fasthttprouter"
2728
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -256,6 +257,7 @@ func (s *VllmSimulator) sendCompletionResponse(ctx *fasthttp.RequestCtx, resp op
256257
// Add pod and namespace information to response headers for testing/debugging
257258
if s.pod != "" {
258259
ctx.Response.Header.Add(podHeader, s.pod)
260+
ctx.Response.Header.Add(portHeader, strconv.Itoa(s.config.Port))
259261
}
260262
if s.namespace != "" {
261263
ctx.Response.Header.Add(namespaceHeader, s.namespace)

pkg/llm-d-inference-sim/simulator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
chatCompletionChunkObject = "chat.completion.chunk"
4949

5050
podHeader = "x-inference-pod"
51+
portHeader = "x-inference-port"
5152
namespaceHeader = "x-inference-namespace"
5253
podNameEnv = "POD_NAME"
5354
podNsEnv = "POD_NAMESPACE"

pkg/llm-d-inference-sim/simulator_test.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,20 @@ var _ = Describe("Simulator", func() {
360360
)
361361

362362
Context("namespace and pod headers", func() {
363-
It("Should not include namespace and pod headers in chat completion response when env is not set", func() {
363+
It("Should not include namespace, pod and port headers in chat completion response when env is not set", func() {
364364
httpResp := sendSimpleChatRequest(nil, false)
365365

366-
// Check for namespace and pod headers
366+
// Check for namespace, pod and port headers
367367
namespaceHeader := httpResp.Header.Get(namespaceHeader)
368368
podHeader := httpResp.Header.Get(podHeader)
369+
portHeader := httpResp.Header.Get(portHeader)
369370

370371
Expect(namespaceHeader).To(BeEmpty(), "Expected namespace header not to be present")
371372
Expect(podHeader).To(BeEmpty(), "Expected pod header not to be present")
373+
Expect(portHeader).To(BeEmpty(), "Expected port header not to be present")
372374
})
373375

374-
It("Should include namespace and pod headers in chat completion response", func() {
376+
It("Should include namespace, pod and port headers in chat completion response", func() {
375377
testNamespace := "test-namespace"
376378
testPod := "test-pod"
377379
envs := map[string]string{
@@ -380,15 +382,17 @@ var _ = Describe("Simulator", func() {
380382
}
381383
httpResp := sendSimpleChatRequest(envs, false)
382384

383-
// Check for namespace and pod headers
385+
// Check for namespace, pod and port headers
384386
namespaceHeader := httpResp.Header.Get(namespaceHeader)
385387
podHeader := httpResp.Header.Get(podHeader)
388+
portHeader := httpResp.Header.Get(portHeader)
386389

387390
Expect(namespaceHeader).To(Equal(testNamespace), "Expected namespace header to be present")
388391
Expect(podHeader).To(Equal(testPod), "Expected pod header to be present")
392+
Expect(portHeader).To(Equal("8000"), "Expected port header to be present")
389393
})
390394

391-
It("Should include namespace and pod headers in chat completion streaming response", func() {
395+
It("Should include namespace, pod and port headers in chat completion streaming response", func() {
392396
testNamespace := "stream-test-namespace"
393397
testPod := "stream-test-pod"
394398
envs := map[string]string{
@@ -397,26 +401,30 @@ var _ = Describe("Simulator", func() {
397401
}
398402
httpResp := sendSimpleChatRequest(envs, true)
399403

400-
// Check for namespace and pod headers
404+
// Check for namespace, pod and port headers
401405
namespaceHeader := httpResp.Header.Get(namespaceHeader)
402406
podHeader := httpResp.Header.Get(podHeader)
407+
portHeader := httpResp.Header.Get(portHeader)
403408

404409
Expect(namespaceHeader).To(Equal(testNamespace), "Expected namespace header to be present")
405410
Expect(podHeader).To(Equal(testPod), "Expected pod header to be present")
411+
Expect(portHeader).To(Equal("8000"), "Expected port header to be present")
406412
})
407413

408-
It("Should not include namespace and pod headers in chat completion streaming response when env is not set", func() {
414+
It("Should not include namespace, pod and port headers in chat completion streaming response when env is not set", func() {
409415
httpResp := sendSimpleChatRequest(nil, true)
410416

411-
// Check for namespace and pod headers
417+
// Check for namespace, pod and port headers
412418
namespaceHeader := httpResp.Header.Get(namespaceHeader)
413419
podHeader := httpResp.Header.Get(podHeader)
420+
portHeader := httpResp.Header.Get(portHeader)
414421

415422
Expect(namespaceHeader).To(BeEmpty(), "Expected namespace header not to be present")
416423
Expect(podHeader).To(BeEmpty(), "Expected pod header not to be present")
424+
Expect(portHeader).To(BeEmpty(), "Expected port header not to be present")
417425
})
418426

419-
It("Should include namespace and pod headers in completion response", func() {
427+
It("Should include namespace, pod and port headers in completion response", func() {
420428
ctx := context.TODO()
421429

422430
testNamespace := "test-namespace"
@@ -434,15 +442,17 @@ var _ = Describe("Simulator", func() {
434442
Expect(err).NotTo(HaveOccurred())
435443
Expect(resp).NotTo(BeNil())
436444

437-
// Check for namespace and pod headers
445+
// Check for namespace, pod and port headers
438446
namespaceHeader := httpResp.Header.Get(namespaceHeader)
439447
podHeader := httpResp.Header.Get(podHeader)
448+
portHeader := httpResp.Header.Get(portHeader)
440449

441450
Expect(namespaceHeader).To(Equal(testNamespace), "Expected namespace header to be present")
442451
Expect(podHeader).To(Equal(testPod), "Expected pod header to be present")
452+
Expect(portHeader).To(Equal("8000"), "Expected port header to be present")
443453
})
444454

445-
It("Should include namespace and pod headers in completion streaming response", func() {
455+
It("Should include namespace, pod and port headers in completion streaming response", func() {
446456
ctx := context.TODO()
447457

448458
testNamespace := "stream-test-namespace"
@@ -460,12 +470,14 @@ var _ = Describe("Simulator", func() {
460470
Expect(err).NotTo(HaveOccurred())
461471
Expect(resp).NotTo(BeNil())
462472

463-
// Check for namespace and pod headers
473+
// Check for namespace, pod and port headers
464474
namespaceHeader := httpResp.Header.Get(namespaceHeader)
465475
podHeader := httpResp.Header.Get(podHeader)
476+
portHeader := httpResp.Header.Get(portHeader)
466477

467478
Expect(namespaceHeader).To(Equal(testNamespace), "Expected namespace header to be present")
468479
Expect(podHeader).To(Equal(testPod), "Expected pod header to be present")
480+
Expect(portHeader).To(Equal("8000"), "Expected port header to be present")
469481
})
470482
})
471483

pkg/llm-d-inference-sim/streaming.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bufio"
2121
"encoding/json"
2222
"fmt"
23+
"strconv"
2324
"time"
2425

2526
"github.com/llm-d/llm-d-inference-sim/pkg/common"
@@ -51,6 +52,7 @@ func (s *VllmSimulator) sendStreamingResponse(context *streamingContext, respons
5152
// Add pod and namespace information to response headers for testing/debugging
5253
if s.pod != "" {
5354
context.ctx.Response.Header.Add(podHeader, s.pod)
55+
context.ctx.Response.Header.Add(portHeader, strconv.Itoa(s.config.Port))
5456
}
5557
if s.namespace != "" {
5658
context.ctx.Response.Header.Add(namespaceHeader, s.namespace)

0 commit comments

Comments
 (0)