middleware/proxy: add request duration monitoring (#362)
Add a separate request duration metrics specially for proxying requests upstream. Fixes #259
This commit is contained in:
parent
ba26f47d5c
commit
54964653d1
5 changed files with 52 additions and 2 deletions
|
@ -74,6 +74,9 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
|||
for time.Now().Sub(start) < tryDuration {
|
||||
host := upstream.Select()
|
||||
if host == nil {
|
||||
|
||||
RequestDuration.WithLabelValues(upstream.From()).Observe(float64(time.Since(start) / time.Millisecond))
|
||||
|
||||
return dns.RcodeServerFailure, errUnreachable
|
||||
}
|
||||
|
||||
|
@ -85,6 +88,9 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
|||
|
||||
if backendErr == nil {
|
||||
w.WriteMsg(reply)
|
||||
|
||||
RequestDuration.WithLabelValues(upstream.From()).Observe(float64(time.Since(start) / time.Millisecond))
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
timeout := host.FailTimeout
|
||||
|
@ -97,6 +103,9 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
|||
atomic.AddInt32(&host.Fails, -1)
|
||||
}(host, timeout)
|
||||
}
|
||||
|
||||
RequestDuration.WithLabelValues(upstream.From()).Observe(float64(time.Since(start) / time.Millisecond))
|
||||
|
||||
return dns.RcodeServerFailure, errUnreachable
|
||||
}
|
||||
return p.Next.ServeDNS(ctx, w, r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue