Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jan 18, 2024
1 parent 5fb2e66 commit 9011105
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
8 changes: 3 additions & 5 deletions pkg/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func newEndpointGroup() *endpointGroup {
}

type endpoint struct {
inFlight *atomic.Int64
terminated chan struct{}
inFlight *atomic.Int64
}

type endpointGroup struct {
Expand Down Expand Up @@ -107,13 +106,12 @@ func (g *endpointGroup) setIPs(ips map[string]struct{}, ports map[string]int32)
g.ports = ports
for ip := range ips {
if _, ok := g.endpoints[ip]; !ok {
g.endpoints[ip] = endpoint{inFlight: &atomic.Int64{}, terminated: make(chan struct{})}
g.endpoints[ip] = endpoint{inFlight: &atomic.Int64{}}
}
}
for ip, endpoint := range g.endpoints {
for ip := range g.endpoints {
if _, ok := ips[ip]; !ok {
delete(g.endpoints, ip)
close(endpoint.terminated)
}
}
g.mtx.Unlock()
Expand Down
1 change: 1 addition & 0 deletions pkg/proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func parseModel(r *http.Request) (string, *http.Request, error) {
}
var body []byte
if mb, ok := r.Body.(*lazyBodyCapturer); ok && mb.capturedBody != nil {
// reuse buffer
body = mb.capturedBody
} else {
// parse request body for model name, ignore errors
Expand Down
4 changes: 1 addition & 3 deletions pkg/proxy/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var _ http.Handler = &RetryMiddleware{}
type RetryMiddleware struct {
nextHandler http.Handler
maxRetries int
rSource *rand.Rand
retryStatusCodes map[int]struct{}
}

Expand All @@ -39,7 +38,6 @@ func NewRetryMiddleware(maxRetries int, other http.Handler, optRetryStatusCodes
nextHandler: other,
maxRetries: maxRetries,
retryStatusCodes: statusCodeIndex,
rSource: rand.New(rand.NewSource(time.Now().UnixNano())),
}
}

Expand Down Expand Up @@ -72,7 +70,7 @@ func (r RetryMiddleware) ServeHTTP(writer http.ResponseWriter, request *http.Req

totalRetries.Inc()
// exponential backoff
jitter := time.Duration(r.rSource.Intn(50))
jitter := time.Duration(rand.Intn(50))
time.Sleep(time.Millisecond*time.Duration(1<<uint(i)) + jitter)
}
}
Expand Down

0 comments on commit 9011105

Please sign in to comment.