Skip to content

Commit

Permalink
Get latency just after reading body
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
  • Loading branch information
rsevilla87 committed Oct 26, 2023
1 parent f84546c commit 96e3f33
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ out:
for {
select {
case <-signalCh:
os.Stderr.Write([]byte("Interrupt signal received, exiting gracefully"))
os.Stderr.Write([]byte("Interrupt signal received, exiting gracefully\n"))
break out
case <-time.After(l.duration):
break out
Expand Down Expand Up @@ -98,8 +98,8 @@ func (l *Loader) sendRequest(httpClient *http.Client, req *http.Request) {
l.results = append(l.results, result)
l.Unlock()
}()
result.timestamp = time.Now()
l.limiter.Wait(context.TODO())
result.timestamp = time.Now()
resp, err := httpClient.Do(req)
if err != nil {
if os.IsTimeout(err) {
Expand All @@ -112,11 +112,11 @@ func (l *Loader) sendRequest(httpClient *http.Client, req *http.Request) {
}
defer resp.Body.Close()
bytesRead, err := io.ReadAll(resp.Body)
result.latency = time.Since(result.timestamp).Microseconds()
if err != nil {
result.readError = true
} else {
result.bytesRead = int64(len(bytesRead))
}
result.code = resp.StatusCode
result.latency = time.Since(result.timestamp).Microseconds()
}

0 comments on commit 96e3f33

Please sign in to comment.