Skip to content

Commit

Permalink
Do not add delay on top of response time
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Aug 8, 2023
1 parent bb6e46a commit f2e8b3d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pkg/agent/protocol/http/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,25 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

// writer is used to write the response
var writer func(rw http.ResponseWriter)
if h.disruption.ErrorRate > 0 && rand.Float32() <= h.disruption.ErrorRate {
writer = h.injectError
} else {
//nolint:contextcheck // Unclear which context the linter requires us to propagate here.
writer = h.forward(req)
}

// forward request
done := make(chan struct{})
go func() {
if h.disruption.ErrorRate > 0 && rand.Float32() <= h.disruption.ErrorRate {
writer = h.injectError
} else {
writer = h.forward(req)
}

done <- struct{}{}
}()

// wait for delay
<-time.After(h.delay())

// wait for upstream request
<-done

// return response
writer(rw)
}
Expand Down

0 comments on commit f2e8b3d

Please sign in to comment.