TUN-6280: Don't wrap qlog connection tracer for gatethering QUIC metrics since we're not writing qlog files.

This commit is contained in:
Igor Postelnik 2022-05-24 13:41:42 -05:00
parent 32739e9f98
commit 2c480a72db
1 changed files with 65 additions and 24 deletions

View File

@ -3,9 +3,9 @@ package quic
import ( import (
"context" "context"
"net" "net"
"time"
"github.com/lucas-clemente/quic-go/logging" "github.com/lucas-clemente/quic-go/logging"
"github.com/lucas-clemente/quic-go/qlog"
"github.com/rs/zerolog" "github.com/rs/zerolog"
) )
@ -40,75 +40,116 @@ func NewServerTracer(logger *zerolog.Logger) logging.Tracer {
} }
} }
func (t *tracer) TracerForConnection(_ context.Context, p logging.Perspective, odcid logging.ConnectionID) logging.ConnectionTracer { func (t *tracer) TracerForConnection(_ctx context.Context, _p logging.Perspective, _odcid logging.ConnectionID) logging.ConnectionTracer {
connID := logging.ConnectionID(odcid).String()
ql := &quicLogger{
logger: t.logger,
connectionID: connID,
}
if t.config.isClient { if t.config.isClient {
return newConnTracer(ql, p, odcid, newClientCollector(t.config.index)) return newConnTracer(newClientCollector(t.config.index))
} }
return newConnTracer(ql, p, odcid, newServiceCollector()) return newConnTracer(newServiceCollector())
} }
func (*tracer) SentPacket(net.Addr, *logging.Header, logging.ByteCount, []logging.Frame) {} func (*tracer) SentPacket(net.Addr, *logging.Header, logging.ByteCount, []logging.Frame) {}
func (*tracer) DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount, logging.PacketDropReason) { func (*tracer) DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount, logging.PacketDropReason) {
} }
// connTracer is a wrapper around https://pkg.go.dev/github.com/lucas-clemente/quic-go@v0.23.0/qlog#NewConnectionTracer to collect metrics var _ logging.Tracer = (*tracer)(nil)
// connTracer collects connection level metrics
type connTracer struct { type connTracer struct {
logging.ConnectionTracer
metricsCollector MetricsCollector metricsCollector MetricsCollector
connectionID string
} }
func newConnTracer(ql *quicLogger, p logging.Perspective, odcid logging.ConnectionID, metricsCollector MetricsCollector) logging.ConnectionTracer { var _ logging.ConnectionTracer = (*connTracer)(nil)
func newConnTracer(metricsCollector MetricsCollector) logging.ConnectionTracer {
return &connTracer{ return &connTracer{
qlog.NewConnectionTracer(ql, p, odcid), metricsCollector: metricsCollector,
metricsCollector,
logging.ConnectionID(odcid).String(),
} }
} }
func (ct *connTracer) StartedConnection(local, remote net.Addr, srcConnID, destConnID logging.ConnectionID) { func (ct *connTracer) StartedConnection(local, remote net.Addr, srcConnID, destConnID logging.ConnectionID) {
ct.metricsCollector.startedConnection() ct.metricsCollector.startedConnection()
ct.ConnectionTracer.StartedConnection(local, remote, srcConnID, destConnID)
} }
func (ct *connTracer) ClosedConnection(err error) { func (ct *connTracer) ClosedConnection(err error) {
ct.metricsCollector.closedConnection(err) ct.metricsCollector.closedConnection(err)
ct.ConnectionTracer.ClosedConnection(err)
} }
func (ct *connTracer) SentPacket(hdr *logging.ExtendedHeader, packetSize logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { func (ct *connTracer) SentPacket(hdr *logging.ExtendedHeader, packetSize logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) {
ct.metricsCollector.sentPackets(packetSize) ct.metricsCollector.sentPackets(packetSize)
ct.ConnectionTracer.SentPacket(hdr, packetSize, ack, frames)
} }
func (ct *connTracer) ReceivedPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, frames []logging.Frame) { func (ct *connTracer) ReceivedPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, frames []logging.Frame) {
ct.metricsCollector.receivedPackets(size) ct.metricsCollector.receivedPackets(size)
ct.ConnectionTracer.ReceivedPacket(hdr, size, frames)
} }
func (ct *connTracer) BufferedPacket(pt logging.PacketType) { func (ct *connTracer) BufferedPacket(pt logging.PacketType) {
ct.metricsCollector.bufferedPackets(pt) ct.metricsCollector.bufferedPackets(pt)
ct.ConnectionTracer.BufferedPacket(pt)
} }
func (ct *connTracer) DroppedPacket(pt logging.PacketType, size logging.ByteCount, reason logging.PacketDropReason) { func (ct *connTracer) DroppedPacket(pt logging.PacketType, size logging.ByteCount, reason logging.PacketDropReason) {
ct.metricsCollector.droppedPackets(pt, size, reason) ct.metricsCollector.droppedPackets(pt, size, reason)
ct.ConnectionTracer.DroppedPacket(pt, size, reason)
} }
func (ct *connTracer) LostPacket(level logging.EncryptionLevel, number logging.PacketNumber, reason logging.PacketLossReason) { func (ct *connTracer) LostPacket(level logging.EncryptionLevel, number logging.PacketNumber, reason logging.PacketLossReason) {
ct.metricsCollector.lostPackets(reason) ct.metricsCollector.lostPackets(reason)
ct.ConnectionTracer.LostPacket(level, number, reason)
} }
func (ct *connTracer) UpdatedMetrics(rttStats *logging.RTTStats, cwnd, bytesInFlight logging.ByteCount, packetsInFlight int) { func (ct *connTracer) UpdatedMetrics(rttStats *logging.RTTStats, cwnd, bytesInFlight logging.ByteCount, packetsInFlight int) {
ct.metricsCollector.updatedRTT(rttStats) ct.metricsCollector.updatedRTT(rttStats)
ct.ConnectionTracer.UpdatedMetrics(rttStats, cwnd, bytesInFlight, packetsInFlight) }
func (ct *connTracer) NegotiatedVersion(chosen logging.VersionNumber, clientVersions, serverVersions []logging.VersionNumber) {
}
func (ct *connTracer) SentTransportParameters(parameters *logging.TransportParameters) {
}
func (ct *connTracer) ReceivedTransportParameters(parameters *logging.TransportParameters) {
}
func (ct *connTracer) RestoredTransportParameters(parameters *logging.TransportParameters) {
}
func (ct *connTracer) ReceivedVersionNegotiationPacket(header *logging.Header, numbers []logging.VersionNumber) {
}
func (ct *connTracer) ReceivedRetry(header *logging.Header) {
}
func (ct *connTracer) AcknowledgedPacket(level logging.EncryptionLevel, number logging.PacketNumber) {
}
func (ct *connTracer) UpdatedCongestionState(state logging.CongestionState) {
}
func (ct *connTracer) UpdatedPTOCount(value uint32) {
}
func (ct *connTracer) UpdatedKeyFromTLS(level logging.EncryptionLevel, perspective logging.Perspective) {
}
func (ct *connTracer) UpdatedKey(generation logging.KeyPhase, remote bool) {
}
func (ct *connTracer) DroppedEncryptionLevel(level logging.EncryptionLevel) {
}
func (ct *connTracer) DroppedKey(generation logging.KeyPhase) {
}
func (ct *connTracer) SetLossTimer(timerType logging.TimerType, level logging.EncryptionLevel, time time.Time) {
}
func (ct *connTracer) LossTimerExpired(timerType logging.TimerType, level logging.EncryptionLevel) {
}
func (ct *connTracer) LossTimerCanceled() {
}
func (ct *connTracer) Close() {
}
func (ct *connTracer) Debug(name, msg string) {
} }
type quicLogger struct { type quicLogger struct {