From 3a7a53fdb919aeedef7441cb7a1618e1b88596c4 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 2 Feb 2024 17:17:56 +0700 Subject: [PATCH] qlog: log packet drops outside of a QUIC connection --- qlog/tracer.go | 11 ++++++++++- qlog/tracer_test.go | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/qlog/tracer.go b/qlog/tracer.go index 4d567875..85398f9f 100644 --- a/qlog/tracer.go +++ b/qlog/tracer.go @@ -2,8 +2,10 @@ package qlog import ( "io" + "net" "time" + "github.com/quic-go/quic-go/internal/protocol" "github.com/quic-go/quic-go/logging" ) @@ -17,7 +19,14 @@ func NewTracer(w io.WriteCloser) *logging.Tracer { return &logging.Tracer{ SentPacket: nil, SentVersionNegotiationPacket: nil, - DroppedPacket: nil, + DroppedPacket: func(addr net.Addr, p logging.PacketType, count logging.ByteCount, reason logging.PacketDropReason) { + wr.RecordEvent(time.Now(), eventPacketDropped{ + PacketType: p, + PacketNumber: protocol.InvalidPacketNumber, + PacketSize: count, + Trigger: packetDropReason(reason), + }) + }, Debug: func(name, msg string) { wr.RecordEvent(time.Now(), &eventGeneric{ name: name, diff --git a/qlog/tracer_test.go b/qlog/tracer_test.go index 46f41522..990e4165 100644 --- a/qlog/tracer_test.go +++ b/qlog/tracer_test.go @@ -3,6 +3,7 @@ package qlog import ( "bytes" "encoding/json" + "net" "time" "github.com/quic-go/quic-go/logging" @@ -45,6 +46,23 @@ var _ = Describe("Tracing", func() { }) Context("Events", func() { + It("records dropped packets", func() { + addr := net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234} + tracer.DroppedPacket(&addr, logging.PacketTypeInitial, 1337, logging.PacketDropPayloadDecryptError) + tracer.Close() + entry := exportAndParseSingle(buf) + Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond))) + Expect(entry.Name).To(Equal("transport:packet_dropped")) + ev := entry.Event + Expect(ev).To(HaveKey("raw")) + Expect(ev["raw"].(map[string]interface{})).To(HaveKeyWithValue("length", float64(1337))) + Expect(ev).To(HaveKey("header")) + hdr := ev["header"].(map[string]interface{}) + Expect(hdr).To(HaveLen(1)) + Expect(hdr).To(HaveKeyWithValue("packet_type", "initial")) + Expect(ev).To(HaveKeyWithValue("trigger", "payload_decrypt_error")) + }) + It("records a generic event", func() { tracer.Debug("foo", "bar") tracer.Close()