forked from quic-go/quic-go
metrics: measure the handshake duration
This commit is contained in:
@@ -37,6 +37,15 @@ var (
|
|||||||
},
|
},
|
||||||
[]string{"dir"},
|
[]string{"dir"},
|
||||||
)
|
)
|
||||||
|
connHandshakeDuration = prometheus.NewHistogramVec(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Namespace: metricNamespace,
|
||||||
|
Name: "handshake_duration_seconds",
|
||||||
|
Help: "Duration of the QUIC Handshake",
|
||||||
|
Buckets: prometheus.ExponentialBuckets(0.001, 1.3, 35),
|
||||||
|
},
|
||||||
|
[]string{"dir"},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultTracer returns a callback that creates a metrics ConnectionTracer.
|
// DefaultTracer returns a callback that creates a metrics ConnectionTracer.
|
||||||
@@ -76,6 +85,7 @@ func NewServerConnectionTracerWithRegisterer(registerer prometheus.Registerer) *
|
|||||||
func newConnectionTracerWithRegisterer(registerer prometheus.Registerer, isClient bool) *logging.ConnectionTracer {
|
func newConnectionTracerWithRegisterer(registerer prometheus.Registerer, isClient bool) *logging.ConnectionTracer {
|
||||||
for _, c := range [...]prometheus.Collector{
|
for _, c := range [...]prometheus.Collector{
|
||||||
connStarted,
|
connStarted,
|
||||||
|
connHandshakeDuration,
|
||||||
connClosed,
|
connClosed,
|
||||||
connDuration,
|
connDuration,
|
||||||
} {
|
} {
|
||||||
@@ -91,7 +101,10 @@ func newConnectionTracerWithRegisterer(registerer prometheus.Registerer, isClien
|
|||||||
direction = "outgoing"
|
direction = "outgoing"
|
||||||
}
|
}
|
||||||
|
|
||||||
var startTime time.Time
|
var (
|
||||||
|
startTime time.Time
|
||||||
|
handshakeComplete bool
|
||||||
|
)
|
||||||
return &logging.ConnectionTracer{
|
return &logging.ConnectionTracer{
|
||||||
StartedConnection: func(_, _ net.Addr, _, _ logging.ConnectionID) {
|
StartedConnection: func(_, _ net.Addr, _, _ logging.ConnectionID) {
|
||||||
tags := getStringSlice()
|
tags := getStringSlice()
|
||||||
@@ -107,8 +120,24 @@ func newConnectionTracerWithRegisterer(registerer prometheus.Registerer, isClien
|
|||||||
defer putStringSlice(tags)
|
defer putStringSlice(tags)
|
||||||
|
|
||||||
*tags = append(*tags, direction)
|
*tags = append(*tags, direction)
|
||||||
connDuration.WithLabelValues(*tags...).Observe(time.Since(startTime).Seconds())
|
|
||||||
connClosed.WithLabelValues(*tags...).Inc()
|
connClosed.WithLabelValues(*tags...).Inc()
|
||||||
|
if handshakeComplete {
|
||||||
|
connDuration.WithLabelValues(*tags...).Observe(time.Since(startTime).Seconds())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
UpdatedKeyFromTLS: func(l logging.EncryptionLevel, p logging.Perspective) {
|
||||||
|
// The client derives both 1-RTT keys when the handshake completes.
|
||||||
|
// The server derives the 1-RTT read key when the handshake completes.
|
||||||
|
if l != logging.Encryption1RTT || p != logging.PerspectiveClient {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
handshakeComplete = true
|
||||||
|
|
||||||
|
tags := getStringSlice()
|
||||||
|
defer putStringSlice(tags)
|
||||||
|
|
||||||
|
*tags = append(*tags, direction)
|
||||||
|
connHandshakeDuration.WithLabelValues(*tags...).Observe(time.Since(startTime).Seconds())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user