From e93189dc2bccc43c254229613da20892930144a1 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 2 Feb 2024 06:11:02 +0700 Subject: [PATCH] logging: add a Debug function to the Tracer --- internal/mocks/logging/internal/tracer.go | 36 +++++++++++++++++++++++ internal/mocks/logging/mockgen.go | 1 + internal/mocks/logging/tracer.go | 3 ++ logging/multiplex_test.go | 6 ++++ logging/tracer.go | 8 +++++ 5 files changed, 54 insertions(+) diff --git a/internal/mocks/logging/internal/tracer.go b/internal/mocks/logging/internal/tracer.go index e11764c2110..88c3b64570c 100644 --- a/internal/mocks/logging/internal/tracer.go +++ b/internal/mocks/logging/internal/tracer.go @@ -41,6 +41,42 @@ func (m *MockTracer) EXPECT() *MockTracerMockRecorder { return m.recorder } +// Debug mocks base method. +func (m *MockTracer) Debug(arg0, arg1 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Debug", arg0, arg1) +} + +// Debug indicates an expected call of Debug. +func (mr *MockTracerMockRecorder) Debug(arg0, arg1 any) *TracerDebugCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debug", reflect.TypeOf((*MockTracer)(nil).Debug), arg0, arg1) + return &TracerDebugCall{Call: call} +} + +// TracerDebugCall wrap *gomock.Call +type TracerDebugCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *TracerDebugCall) Return() *TracerDebugCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *TracerDebugCall) Do(f func(string, string)) *TracerDebugCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *TracerDebugCall) DoAndReturn(f func(string, string)) *TracerDebugCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + // DroppedPacket mocks base method. func (m *MockTracer) DroppedPacket(arg0 net.Addr, arg1 logging.PacketType, arg2 protocol.ByteCount, arg3 logging.PacketDropReason) { m.ctrl.T.Helper() diff --git a/internal/mocks/logging/mockgen.go b/internal/mocks/logging/mockgen.go index a86be9b1a1d..fb58e1174a9 100644 --- a/internal/mocks/logging/mockgen.go +++ b/internal/mocks/logging/mockgen.go @@ -14,6 +14,7 @@ type Tracer interface { SentPacket(net.Addr, *logging.Header, logging.ByteCount, []logging.Frame) SentVersionNegotiationPacket(_ net.Addr, dest, src logging.ArbitraryLenConnectionID, _ []logging.VersionNumber) DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount, logging.PacketDropReason) + Debug(name, msg string) } //go:generate sh -c "go run go.uber.org/mock/mockgen -typed -build_flags=\"-tags=gomock\" -package internal -destination internal/connection_tracer.go github.com/quic-go/quic-go/internal/mocks/logging ConnectionTracer" diff --git a/internal/mocks/logging/tracer.go b/internal/mocks/logging/tracer.go index 115f578a2c7..66e210a53f9 100644 --- a/internal/mocks/logging/tracer.go +++ b/internal/mocks/logging/tracer.go @@ -25,5 +25,8 @@ func NewMockTracer(ctrl *gomock.Controller) (*logging.Tracer, *MockTracer) { DroppedPacket: func(remote net.Addr, typ logging.PacketType, size logging.ByteCount, reason logging.PacketDropReason) { t.DroppedPacket(remote, typ, size, reason) }, + Debug: func(name, msg string) { + t.Debug(name, msg) + }, }, t } diff --git a/logging/multiplex_test.go b/logging/multiplex_test.go index 946040963a2..96cd1185361 100644 --- a/logging/multiplex_test.go +++ b/logging/multiplex_test.go @@ -64,6 +64,12 @@ var _ = Describe("Tracing", func() { tr2.EXPECT().DroppedPacket(remote, PacketTypeRetry, ByteCount(1024), PacketDropDuplicate) tracer.DroppedPacket(remote, PacketTypeRetry, 1024, PacketDropDuplicate) }) + + It("traces the Debug event", func() { + tr1.EXPECT().Debug("foo", "bar") + tr2.EXPECT().Debug("foo", "bar") + tracer.Debug("foo", "bar") + }) }) }) diff --git a/logging/tracer.go b/logging/tracer.go index 5918f30f842..735ec3de05c 100644 --- a/logging/tracer.go +++ b/logging/tracer.go @@ -7,6 +7,7 @@ type Tracer struct { SentPacket func(net.Addr, *Header, ByteCount, []Frame) SentVersionNegotiationPacket func(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber) DroppedPacket func(net.Addr, PacketType, ByteCount, PacketDropReason) + Debug func(name, msg string) } // NewMultiplexedTracer creates a new tracer that multiplexes events to multiple tracers. @@ -39,5 +40,12 @@ func NewMultiplexedTracer(tracers ...*Tracer) *Tracer { } } }, + Debug: func(name, msg string) { + for _, t := range tracers { + if t.Debug != nil { + t.Debug(name, msg) + } + } + }, } }