mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 01:39:39 +08:00
feat: stat HTTP request latencies (DNSLookup, TCP Connection and so on)
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/hrp/internal/httpstat"
|
||||
"github.com/httprunner/httprunner/hrp/internal/json"
|
||||
)
|
||||
|
||||
@@ -311,6 +312,13 @@ func runStepRequest(r *SessionRunner, step *TStep) (stepResult *StepResult, err
|
||||
}
|
||||
}
|
||||
|
||||
// stat HTTP request
|
||||
var httpStat httpstat.Stat
|
||||
if r.HTTPStatOn() {
|
||||
ctx := httpstat.WithHTTPStat(rb.req.Context(), &httpStat)
|
||||
rb.req = rb.req.WithContext(ctx)
|
||||
}
|
||||
|
||||
// do request action
|
||||
start := time.Now()
|
||||
var resp *http.Response
|
||||
@@ -339,6 +347,14 @@ func runStepRequest(r *SessionRunner, step *TStep) (stepResult *StepResult, err
|
||||
}
|
||||
}
|
||||
|
||||
if r.HTTPStatOn() {
|
||||
httpStat.Finish()
|
||||
stepResult.HttpStat = httpStat.Durations()
|
||||
log.Info().
|
||||
Interface("httpstat(ms)", httpStat.Durations()).
|
||||
Msg("HTTP latency statistics")
|
||||
}
|
||||
|
||||
// new response object
|
||||
respObj, err := newHttpResponseObject(r.hrpRunner.t, parser, resp)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user