Skip to content

Commit bf9f928

Browse files
committed
Do not add delay on top of response time
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
1 parent 265489a commit bf9f928

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

pkg/agent/protocol/http/proxy.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,26 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
171171

172172
// writer is used to write the response
173173
var writer func(rw http.ResponseWriter)
174-
if h.disruption.ErrorRate > 0 && rand.Float32() <= h.disruption.ErrorRate {
175-
h.metrics.Inc(protocol.MetricRequestsDisrupted)
176-
writer = h.injectError
177-
} else {
178-
//nolint:contextcheck // Unclear which context the linter requires us to propagate here.
179-
writer = h.forward(req)
180-
}
174+
175+
// forward request
176+
done := make(chan struct{})
177+
go func() {
178+
if h.disruption.ErrorRate > 0 && rand.Float32() <= h.disruption.ErrorRate {
179+
h.metrics.Inc(protocol.MetricRequestsDisrupted)
180+
writer = h.injectError
181+
} else {
182+
writer = h.forward(req)
183+
}
184+
185+
done <- struct{}{}
186+
}()
181187

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

191+
// wait for upstream request
192+
<-done
193+
185194
// return response
186195
writer(rw)
187196
}

0 commit comments

Comments
 (0)