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 Sep 22, 2023
1 parent 265489a commit bf9f928
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pkg/agent/protocol/http/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,26 @@ 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 {
h.metrics.Inc(protocol.MetricRequestsDisrupted)
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 {
h.metrics.Inc(protocol.MetricRequestsDisrupted)
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 bf9f928

Please sign in to comment.