mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 15:53:17 +00:00
reverseproxy: Add _ms
placeholders for proxy durations (#4666)
* reverseproxy: Add `_ms` placeholders for proxy durations * Add http.request.duration_ms Also add comments, and change duration_sec to duration_ms * Add response.duration_ms for consistency * Add missing godoc comment Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
e4ce40f8ff
commit
3e3bb00265
4 changed files with 11 additions and 0 deletions
|
@ -58,8 +58,11 @@ func init() {
|
|||
// `{http.reverse_proxy.upstream.max_requests}` | The maximum approximate number of requests allowed to the upstream
|
||||
// `{http.reverse_proxy.upstream.fails}` | The number of recent failed requests to the upstream
|
||||
// `{http.reverse_proxy.upstream.latency}` | How long it took the proxy upstream to write the response header.
|
||||
// `{http.reverse_proxy.upstream.latency_ms}` | Same as 'latency', but in milliseconds.
|
||||
// `{http.reverse_proxy.upstream.duration}` | Time spent proxying to the upstream, including writing response body to client.
|
||||
// `{http.reverse_proxy.upstream.duration_ms}` | Same as 'upstream.duration', but in milliseconds.
|
||||
// `{http.reverse_proxy.duration}` | Total time spent proxying, including selecting an upstream, retries, and writing response.
|
||||
// `{http.reverse_proxy.duration_ms}` | Same as 'duration', but in milliseconds.
|
||||
type Handler struct {
|
||||
// Configures the method of transport for the proxy. A transport
|
||||
// is what performs the actual "round trip" to the backend.
|
||||
|
@ -400,6 +403,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
|
|||
defer func() {
|
||||
// total proxying duration, including time spent on LB and retries
|
||||
repl.Set("http.reverse_proxy.duration", time.Since(start))
|
||||
repl.Set("http.reverse_proxy.duration_ms", time.Since(start).Seconds()*1e3) // multiply seconds to preserve decimal (see #4666)
|
||||
}()
|
||||
|
||||
// in the proxy loop, each iteration is an attempt to proxy the request,
|
||||
|
@ -724,6 +728,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, repl *
|
|||
|
||||
// duration until upstream wrote response headers (roundtrip duration)
|
||||
repl.Set("http.reverse_proxy.upstream.latency", duration)
|
||||
repl.Set("http.reverse_proxy.upstream.latency_ms", duration.Seconds()*1e3) // multiply seconds to preserve decimal (see #4666)
|
||||
|
||||
// update circuit breaker on current conditions
|
||||
if di.Upstream.cb != nil {
|
||||
|
@ -909,6 +914,7 @@ func (h Handler) finalizeResponse(
|
|||
|
||||
// total duration spent proxying, including writing response body
|
||||
repl.Set("http.reverse_proxy.upstream.duration", time.Since(start))
|
||||
repl.Set("http.reverse_proxy.upstream.duration_ms", time.Since(start).Seconds()*1e3)
|
||||
|
||||
if len(res.Trailer) == announcedTrailers {
|
||||
copyHeader(rw.Header(), res.Trailer)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue