Skip to content

Commit bf1f080

Browse files
committed
Don't store the port number with the pods
1 parent f9113b3 commit bf1f080

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Diff for: pkg/ext-proc/backend/datastore.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"math/rand"
7-
"strconv"
87
"sync"
98

109
"github.com/go-logr/logr"
@@ -150,14 +149,12 @@ func (ds *datastore) PodDelete(namespacedName types.NamespacedName) {
150149
}
151150

152151
func (ds *datastore) PodAddIfNotExist(pod *corev1.Pod) bool {
153-
// new pod, add to the store for probing
154-
pool, _ := ds.PoolGet()
155152
new := &PodMetrics{
156153
NamespacedName: types.NamespacedName{
157154
Name: pod.Name,
158155
Namespace: pod.Namespace,
159156
},
160-
Address: pod.Status.PodIP + ":" + strconv.Itoa(int(pool.Spec.TargetPortNumber)),
157+
Address: pod.Status.PodIP,
161158
Metrics: Metrics{
162159
ActiveModels: make(map[string]int),
163160
},

Diff for: pkg/ext-proc/handlers/request.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,29 @@ func (s *Server) HandleRequestBody(
8282
if err != nil {
8383
return nil, fmt.Errorf("failed to find target pod: %w", err)
8484
}
85+
8586
logger.V(logutil.DEFAULT).Info("Request handled",
8687
"model", llmReq.Model, "targetModel", llmReq.ResolvedTargetModel, "endpoint", targetPod)
8788

89+
// Insert target endpoint to instruct Envoy to route requests to the specified target pod.
90+
// Attach the port port number
91+
pool, err := s.datastore.PoolGet()
92+
if err != nil {
93+
return nil, err
94+
}
95+
endpoint := targetPod.Address + ":" + strconv.Itoa(int(pool.Spec.TargetPortNumber))
96+
8897
reqCtx.Model = llmReq.Model
8998
reqCtx.ResolvedTargetModel = llmReq.ResolvedTargetModel
9099
reqCtx.RequestSize = len(v.RequestBody.Body)
91100
reqCtx.TargetPod = targetPod.NamespacedName.String()
92-
reqCtx.TargetPodAddress = targetPod.Address
101+
reqCtx.TargetEndpoint = endpoint
93102

94-
// Insert target endpoint to instruct Envoy to route requests to the specified target pod.
95103
headers := []*configPb.HeaderValueOption{
96104
{
97105
Header: &configPb.HeaderValue{
98106
Key: s.targetEndpointKey,
99-
RawValue: []byte(targetPod.Address),
107+
RawValue: []byte(endpoint),
100108
},
101109
},
102110
// We need to update the content length header if the body is mutated, see Envoy doc:
@@ -135,7 +143,7 @@ func (s *Server) HandleRequestBody(
135143
Fields: map[string]*structpb.Value{
136144
s.targetEndpointKey: {
137145
Kind: &structpb.Value_StringValue{
138-
StringValue: targetPod.Address,
146+
StringValue: endpoint,
139147
},
140148
},
141149
},

Diff for: pkg/ext-proc/handlers/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (s *Server) Process(srv extProcPb.ExternalProcessor_ProcessServer) error {
128128
// RequestContext stores context information during the life time of an HTTP request.
129129
type RequestContext struct {
130130
TargetPod string
131-
TargetPodAddress string
131+
TargetEndpoint string
132132
Model string
133133
ResolvedTargetModel string
134134
RequestReceivedTimestamp time.Time

0 commit comments

Comments
 (0)