-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracer.go
88 lines (68 loc) · 2.19 KB
/
tracer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package artemis
import (
"crypto/tls"
"net/http/httptrace"
"time"
)
type HttpTracer struct {
RequestStartTime time.Time
GetConnTime time.Time
DNSStartTime time.Time
DNSHost string
ConnectStartTime time.Time
TLSHandshakeStartTime time.Time
Metrics *TracingMetrics
ReqMethod string
ReqURL string
}
func NewHttpTracer(requestStart time.Time, metrics *TracingMetrics, method, reqUrl string) *HttpTracer {
return &HttpTracer{
RequestStartTime: requestStart,
Metrics: metrics,
ReqMethod: method,
ReqURL: reqUrl,
}
}
func (ht *HttpTracer) GetConn(hostPort string) {
ht.GetConnTime = time.Now()
}
func (ht *HttpTracer) GotConn(info httptrace.GotConnInfo) {
ht.Metrics.GetConnectionDurationSecondsMetric(ht.GetConnTime, ht.ReqMethod, ht.ReqURL)
if info.Reused {
ht.Metrics.ReuseConnectionsMetric()
}
if info.WasIdle {
ht.Metrics.ReuseIdleConnectionsMetric()
}
}
func (ht *HttpTracer) GotFirstResponseByte() {
ht.Metrics.FirstByteReceiveDurationSecondsMetric(ht.RequestStartTime, ht.ReqMethod, ht.ReqURL)
}
func (ht *HttpTracer) DNSStart(info httptrace.DNSStartInfo) {
ht.DNSStartTime = time.Now()
ht.DNSHost = info.Host
}
func (ht *HttpTracer) DNSDone(info httptrace.DNSDoneInfo) {
ht.Metrics.DNSLookupDurationSecondsMetric(ht.DNSStartTime, ht.DNSHost)
if info.Coalesced {
ht.Metrics.DNSCoalescedMetric(ht.DNSHost)
}
}
func (ht *HttpTracer) ConnStart(network, addr string) {
ht.ConnectStartTime = time.Now()
}
func (ht *HttpTracer) ConnDone(network, addr string, err error) {
ht.Metrics.ConnectionHandshakeDurationSecondsMetric(ht.ConnectStartTime, ht.ReqMethod, ht.ReqURL)
}
func (ht *HttpTracer) TLSHandshakeStart() {
ht.TLSHandshakeStartTime = time.Now()
}
func (ht *HttpTracer) TLSHandshakeDone(tls.ConnectionState, error) {
ht.Metrics.TLSHandshakeDurationSecondsMetric(ht.TLSHandshakeStartTime, ht.ReqMethod, ht.ReqURL)
}
func (ht *HttpTracer) WroteHeaders() {
ht.Metrics.HeaderWriteDrurationSecondsMetric(ht.RequestStartTime, ht.ReqMethod, ht.ReqURL)
}
func (ht *HttpTracer) WroteRequest(info httptrace.WroteRequestInfo) {
ht.Metrics.RequestWriteDurationSecondsMetric(ht.RequestStartTime, ht.ReqMethod, ht.ReqURL)
}