feat: stat HTTP request latencies (DNSLookup, TCP Connection and so on)

This commit is contained in:
debugtalk
2022-05-03 23:37:23 +08:00
parent 8455f739a4
commit edd04bdf92
14 changed files with 223 additions and 16 deletions

View File

@@ -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 {