2021-10-15 11:05:54 +00:00
|
|
|
package quic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
|
2023-05-06 00:42:41 +00:00
|
|
|
"github.com/quic-go/quic-go/logging"
|
2021-10-15 11:05:54 +00:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
|
|
|
// QUICTracer is a wrapper to create new quicConnTracer
|
|
|
|
type tracer struct {
|
2024-06-06 20:02:18 +00:00
|
|
|
index string
|
2021-10-15 11:05:54 +00:00
|
|
|
logger *zerolog.Logger
|
|
|
|
}
|
|
|
|
|
2023-12-04 09:49:00 +00:00
|
|
|
func NewClientTracer(logger *zerolog.Logger, index uint8) func(context.Context, logging.Perspective, logging.ConnectionID) *logging.ConnectionTracer {
|
2023-05-06 00:42:41 +00:00
|
|
|
t := &tracer{
|
2024-06-06 20:02:18 +00:00
|
|
|
index: uint8ToString(index),
|
2021-10-15 11:05:54 +00:00
|
|
|
logger: logger,
|
|
|
|
}
|
2023-05-06 00:42:41 +00:00
|
|
|
return t.TracerForConnection
|
2021-10-15 11:05:54 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 09:49:00 +00:00
|
|
|
func (t *tracer) TracerForConnection(_ctx context.Context, _p logging.Perspective, _odcid logging.ConnectionID) *logging.ConnectionTracer {
|
2024-06-06 20:02:18 +00:00
|
|
|
return newConnTracer(newClientCollector(t.index, t.logger))
|
2021-10-15 11:05:54 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 18:41:42 +00:00
|
|
|
// connTracer collects connection level metrics
|
2021-10-15 11:05:54 +00:00
|
|
|
type connTracer struct {
|
2024-02-16 11:28:59 +00:00
|
|
|
metricsCollector *clientCollector
|
2021-10-15 11:05:54 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 11:28:59 +00:00
|
|
|
func newConnTracer(metricsCollector *clientCollector) *logging.ConnectionTracer {
|
2023-12-04 09:49:00 +00:00
|
|
|
tracer := connTracer{
|
2022-05-24 18:41:42 +00:00
|
|
|
metricsCollector: metricsCollector,
|
2021-10-15 11:05:54 +00:00
|
|
|
}
|
2023-12-04 09:49:00 +00:00
|
|
|
return &logging.ConnectionTracer{
|
2024-06-06 20:02:18 +00:00
|
|
|
StartedConnection: tracer.StartedConnection,
|
|
|
|
ClosedConnection: tracer.ClosedConnection,
|
|
|
|
ReceivedTransportParameters: tracer.ReceivedTransportParameters,
|
|
|
|
SentLongHeaderPacket: tracer.SentLongHeaderPacket,
|
|
|
|
SentShortHeaderPacket: tracer.SentShortHeaderPacket,
|
|
|
|
ReceivedLongHeaderPacket: tracer.ReceivedLongHeaderPacket,
|
|
|
|
ReceivedShortHeaderPacket: tracer.ReceivedShortHeaderPacket,
|
|
|
|
BufferedPacket: tracer.BufferedPacket,
|
|
|
|
DroppedPacket: tracer.DroppedPacket,
|
|
|
|
UpdatedMetrics: tracer.UpdatedMetrics,
|
|
|
|
LostPacket: tracer.LostPacket,
|
2024-06-07 15:24:19 +00:00
|
|
|
UpdatedMTU: tracer.UpdatedMTU,
|
|
|
|
UpdatedCongestionState: tracer.UpdatedCongestionState,
|
2023-12-04 09:49:00 +00:00
|
|
|
}
|
2021-10-15 11:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ct *connTracer) StartedConnection(local, remote net.Addr, srcConnID, destConnID logging.ConnectionID) {
|
|
|
|
ct.metricsCollector.startedConnection()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ct *connTracer) ClosedConnection(err error) {
|
|
|
|
ct.metricsCollector.closedConnection(err)
|
|
|
|
}
|
|
|
|
|
2024-06-06 20:02:18 +00:00
|
|
|
func (ct *connTracer) ReceivedTransportParameters(params *logging.TransportParameters) {
|
|
|
|
ct.metricsCollector.receivedTransportParameters(params)
|
|
|
|
}
|
|
|
|
|
2023-05-06 00:42:41 +00:00
|
|
|
func (ct *connTracer) BufferedPacket(pt logging.PacketType, size logging.ByteCount) {
|
2021-10-15 11:05:54 +00:00
|
|
|
ct.metricsCollector.bufferedPackets(pt)
|
|
|
|
}
|
|
|
|
|
2023-12-04 09:49:00 +00:00
|
|
|
func (ct *connTracer) DroppedPacket(pt logging.PacketType, number logging.PacketNumber, size logging.ByteCount, reason logging.PacketDropReason) {
|
2021-10-15 11:05:54 +00:00
|
|
|
ct.metricsCollector.droppedPackets(pt, size, reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ct *connTracer) LostPacket(level logging.EncryptionLevel, number logging.PacketNumber, reason logging.PacketLossReason) {
|
|
|
|
ct.metricsCollector.lostPackets(reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ct *connTracer) UpdatedMetrics(rttStats *logging.RTTStats, cwnd, bytesInFlight logging.ByteCount, packetsInFlight int) {
|
|
|
|
ct.metricsCollector.updatedRTT(rttStats)
|
2024-06-07 15:24:19 +00:00
|
|
|
ct.metricsCollector.updateCongestionWindow(cwnd)
|
2022-05-24 18:41:42 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 09:49:00 +00:00
|
|
|
func (ct *connTracer) SentLongHeaderPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, ecn logging.ECN, ack *logging.AckFrame, frames []logging.Frame) {
|
2024-02-16 11:28:59 +00:00
|
|
|
ct.metricsCollector.sentPackets(size, frames)
|
2023-05-06 00:42:41 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 09:49:00 +00:00
|
|
|
func (ct *connTracer) SentShortHeaderPacket(hdr *logging.ShortHeader, size logging.ByteCount, ecn logging.ECN, ack *logging.AckFrame, frames []logging.Frame) {
|
2024-02-16 11:28:59 +00:00
|
|
|
ct.metricsCollector.sentPackets(size, frames)
|
2022-05-24 18:41:42 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 09:49:00 +00:00
|
|
|
func (ct *connTracer) ReceivedLongHeaderPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, ecn logging.ECN, frames []logging.Frame) {
|
2024-02-16 11:28:59 +00:00
|
|
|
ct.metricsCollector.receivedPackets(size, frames)
|
2023-05-06 00:42:41 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 09:49:00 +00:00
|
|
|
func (ct *connTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, size logging.ByteCount, ecn logging.ECN, frames []logging.Frame) {
|
2024-02-16 11:28:59 +00:00
|
|
|
ct.metricsCollector.receivedPackets(size, frames)
|
2021-10-15 11:05:54 +00:00
|
|
|
}
|
2024-06-07 15:24:19 +00:00
|
|
|
|
|
|
|
func (ct *connTracer) UpdatedMTU(mtu logging.ByteCount, done bool) {
|
|
|
|
ct.metricsCollector.updateMTU(mtu)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ct *connTracer) UpdatedCongestionState(state logging.CongestionState) {
|
|
|
|
ct.metricsCollector.updatedCongestionState(state)
|
|
|
|
}
|