Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a qlog tracer for events outside of QUIC connections #4305

Merged
merged 5 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
qlog: log packet drops outside of a QUIC connection
  • Loading branch information
marten-seemann committed Mar 9, 2024
commit 3a7a53fdb919aeedef7441cb7a1618e1b88596c4
11 changes: 10 additions & 1 deletion qlog/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions qlog/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package qlog
import (
"bytes"
"encoding/json"
"net"
"time"

"github.com/quic-go/quic-go/logging"
Expand Down Expand Up @@ -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()
Expand Down