From 2c480a72db4dd9fe3046ce3913d719f00a793fd7 Mon Sep 17 00:00:00 2001 From: Igor Postelnik Date: Tue, 24 May 2022 13:41:42 -0500 Subject: [PATCH] TUN-6280: Don't wrap qlog connection tracer for gatethering QUIC metrics since we're not writing qlog files. --- quic/tracing.go | 89 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/quic/tracing.go b/quic/tracing.go index e0e57ab1..ca14100f 100644 --- a/quic/tracing.go +++ b/quic/tracing.go @@ -3,9 +3,9 @@ package quic import ( "context" "net" + "time" "github.com/lucas-clemente/quic-go/logging" - "github.com/lucas-clemente/quic-go/qlog" "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 { - connID := logging.ConnectionID(odcid).String() - ql := &quicLogger{ - logger: t.logger, - connectionID: connID, - } +func (t *tracer) TracerForConnection(_ctx context.Context, _p logging.Perspective, _odcid logging.ConnectionID) logging.ConnectionTracer { 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) 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 { - logging.ConnectionTracer 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{ - qlog.NewConnectionTracer(ql, p, odcid), - metricsCollector, - logging.ConnectionID(odcid).String(), + metricsCollector: metricsCollector, } } func (ct *connTracer) StartedConnection(local, remote net.Addr, srcConnID, destConnID logging.ConnectionID) { ct.metricsCollector.startedConnection() - ct.ConnectionTracer.StartedConnection(local, remote, srcConnID, destConnID) } func (ct *connTracer) ClosedConnection(err error) { ct.metricsCollector.closedConnection(err) - ct.ConnectionTracer.ClosedConnection(err) } func (ct *connTracer) SentPacket(hdr *logging.ExtendedHeader, packetSize logging.ByteCount, ack *logging.AckFrame, frames []logging.Frame) { ct.metricsCollector.sentPackets(packetSize) - ct.ConnectionTracer.SentPacket(hdr, packetSize, ack, frames) } func (ct *connTracer) ReceivedPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, frames []logging.Frame) { ct.metricsCollector.receivedPackets(size) - ct.ConnectionTracer.ReceivedPacket(hdr, size, frames) } func (ct *connTracer) BufferedPacket(pt logging.PacketType) { ct.metricsCollector.bufferedPackets(pt) - ct.ConnectionTracer.BufferedPacket(pt) } func (ct *connTracer) DroppedPacket(pt logging.PacketType, size logging.ByteCount, reason logging.PacketDropReason) { 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) { ct.metricsCollector.lostPackets(reason) - ct.ConnectionTracer.LostPacket(level, number, reason) } func (ct *connTracer) UpdatedMetrics(rttStats *logging.RTTStats, cwnd, bytesInFlight logging.ByteCount, packetsInFlight int) { 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 {