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

qlog: add support for alpn_information event #4216

Merged
merged 3 commits into from
Dec 26, 2023
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
6 changes: 6 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,12 @@ func (s *connection) handleHandshakeConfirmed() error {
}
s.mtuDiscoverer.Start(utils.Min(maxPacketSize, protocol.MaxPacketBufferSize))
}

// do not log earlier to not apply additional pressure on the handshake mutex
if s.tracer != nil && s.tracer.ChoseAlpn != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to log this earlier, at the very latest on handshake completion.

s.tracer.ChoseAlpn(s.cryptoStreamHandler.ConnectionState().NegotiatedProtocol)
}

return nil
}

Expand Down
12 changes: 12 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,7 @@ var _ = Describe("Connection", func() {
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
conn.sentPacketHandler = sph
tracer.EXPECT().DroppedEncryptionLevel(protocol.EncryptionHandshake)
tracer.EXPECT().ChoseAlpn(gomock.Any())
sph.EXPECT().GetLossDetectionTimeout().AnyTimes()
sph.EXPECT().TimeUntilSend().AnyTimes()
sph.EXPECT().SendMode(gomock.Any()).AnyTimes()
Expand All @@ -1954,6 +1955,7 @@ var _ = Describe("Connection", func() {
connRunner.EXPECT().Retire(clientDestConnID)
cryptoSetup.EXPECT().SetHandshakeConfirmed()
cryptoSetup.EXPECT().GetSessionTicket()
cryptoSetup.EXPECT().ConnectionState()
handshakeCtx := conn.HandshakeComplete()
Consistently(handshakeCtx).ShouldNot(BeClosed())
Expect(conn.handleHandshakeComplete()).To(Succeed())
Expand All @@ -1966,8 +1968,10 @@ var _ = Describe("Connection", func() {
connRunner.EXPECT().Retire(clientDestConnID)
conn.sentPacketHandler.DropPackets(protocol.EncryptionInitial)
tracer.EXPECT().DroppedEncryptionLevel(protocol.EncryptionHandshake)
tracer.EXPECT().ChoseAlpn(gomock.Any())
cryptoSetup.EXPECT().SetHandshakeConfirmed()
cryptoSetup.EXPECT().GetSessionTicket().Return(make([]byte, size), nil)
cryptoSetup.EXPECT().ConnectionState()

handshakeCtx := conn.HandshakeComplete()
Consistently(handshakeCtx).ShouldNot(BeClosed())
Expand Down Expand Up @@ -2021,6 +2025,7 @@ var _ = Describe("Connection", func() {
sph.EXPECT().SentPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
mconn.EXPECT().Write(gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().SentShortHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
tracer.EXPECT().ChoseAlpn(gomock.Any())
conn.sentPacketHandler = sph
done := make(chan struct{})
connRunner.EXPECT().Retire(clientDestConnID)
Expand All @@ -2041,6 +2046,7 @@ var _ = Describe("Connection", func() {
cryptoSetup.EXPECT().NextEvent().Return(handshake.Event{Kind: handshake.EventNoEvent})
cryptoSetup.EXPECT().SetHandshakeConfirmed()
cryptoSetup.EXPECT().GetSessionTicket()
cryptoSetup.EXPECT().ConnectionState()
mconn.EXPECT().Write(gomock.Any(), gomock.Any(), gomock.Any())
Expect(conn.handleHandshakeComplete()).To(Succeed())
conn.run()
Expand Down Expand Up @@ -2352,6 +2358,7 @@ var _ = Describe("Connection", func() {
cryptoSetup.EXPECT().Close()
gomock.InOrder(
tracer.EXPECT().DroppedEncryptionLevel(protocol.EncryptionHandshake),
tracer.EXPECT().ChoseAlpn(gomock.Any()),
tracer.EXPECT().ClosedConnection(gomock.Any()).Do(func(e error) {
Expect(e).To(MatchError(&IdleTimeoutError{}))
}),
Expand All @@ -2366,6 +2373,7 @@ var _ = Describe("Connection", func() {
cryptoSetup.EXPECT().NextEvent().Return(handshake.Event{Kind: handshake.EventNoEvent})
cryptoSetup.EXPECT().GetSessionTicket().MaxTimes(1)
cryptoSetup.EXPECT().SetHandshakeConfirmed().MaxTimes(1)
cryptoSetup.EXPECT().ConnectionState()
Expect(conn.handleHandshakeComplete()).To(Succeed())
err := conn.run()
nerr, ok := err.(net.Error)
Expand Down Expand Up @@ -2652,9 +2660,11 @@ var _ = Describe("Client Connection", func() {
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
conn.sentPacketHandler = sph
tracer.EXPECT().DroppedEncryptionLevel(protocol.EncryptionHandshake)
tracer.EXPECT().ChoseAlpn(gomock.Any())
sph.EXPECT().DropPackets(protocol.EncryptionHandshake)
sph.EXPECT().SetHandshakeConfirmed()
cryptoSetup.EXPECT().SetHandshakeConfirmed()
cryptoSetup.EXPECT().ConnectionState()
Expect(conn.handleHandshakeDoneFrame()).To(Succeed())
})

Expand All @@ -2664,11 +2674,13 @@ var _ = Describe("Client Connection", func() {
conn.sentPacketHandler = sph
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 3}}}
tracer.EXPECT().DroppedEncryptionLevel(protocol.EncryptionHandshake)
tracer.EXPECT().ChoseAlpn(gomock.Any())
sph.EXPECT().ReceivedAck(ack, protocol.Encryption1RTT, gomock.Any()).Return(true, nil)
sph.EXPECT().DropPackets(protocol.EncryptionHandshake)
sph.EXPECT().SetHandshakeConfirmed()
cryptoSetup.EXPECT().SetLargest1RTTAcked(protocol.PacketNumber(3))
cryptoSetup.EXPECT().SetHandshakeConfirmed()
cryptoSetup.EXPECT().ConnectionState()
Expect(conn.handleAckFrame(ack, protocol.Encryption1RTT)).To(Succeed())
})

Expand Down
3 changes: 3 additions & 0 deletions internal/mocks/logging/connection_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func NewMockConnectionTracer(ctrl *gomock.Controller) (*logging.ConnectionTracer
ECNStateUpdated: func(state logging.ECNState, trigger logging.ECNStateTrigger) {
t.ECNStateUpdated(state, trigger)
},
ChoseAlpn: func(protocol string) {
t.ChoseAlpn(protocol)
},
Close: func() {
t.Close()
},
Expand Down
36 changes: 36 additions & 0 deletions internal/mocks/logging/internal/connection_tracer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/mocks/logging/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ConnectionTracer interface {
LossTimerExpired(logging.TimerType, logging.EncryptionLevel)
LossTimerCanceled()
ECNStateUpdated(state logging.ECNState, trigger logging.ECNStateTrigger)
ChoseAlpn(protocol string)
// Close is called when the connection is closed.
Close()
Debug(name, msg string)
Expand Down
8 changes: 8 additions & 0 deletions logging/connection_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ConnectionTracer struct {
LossTimerExpired func(TimerType, EncryptionLevel)
LossTimerCanceled func()
ECNStateUpdated func(state ECNState, trigger ECNStateTrigger)
ChoseAlpn func(protocol string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Go naming conventions would tell us to write it this way:

Suggested change
ChoseAlpn func(protocol string)
ChoseALPN func(protocol string)

// Close is called when the connection is closed.
Close func()
Debug func(name, msg string)
Expand Down Expand Up @@ -237,6 +238,13 @@ func NewMultiplexedConnectionTracer(tracers ...*ConnectionTracer) *ConnectionTra
}
}
},
ChoseAlpn: func(protocol string) {
for _, t := range tracers {
if t.ChoseAlpn != nil {
t.ChoseAlpn(protocol)
}
}
},
Close: func() {
for _, t := range tracers {
if t.Close != nil {
Expand Down
12 changes: 12 additions & 0 deletions qlog/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,15 @@ func (e eventGeneric) IsNil() bool { return false }
func (e eventGeneric) MarshalJSONObject(enc *gojay.Encoder) {
enc.StringKey("details", e.msg)
}

type eventAlpnInformation struct {
marten-seemann marked this conversation as resolved.
Show resolved Hide resolved
chosenAlpn string
marten-seemann marked this conversation as resolved.
Show resolved Hide resolved
}

func (e eventAlpnInformation) Category() category { return categoryTransport }
func (e eventAlpnInformation) Name() string { return "alpn_information" }
func (e eventAlpnInformation) IsNil() bool { return false }

func (e eventAlpnInformation) MarshalJSONObject(enc *gojay.Encoder) {
enc.StringKeyOmitEmpty("chosen_alpn", e.chosenAlpn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not omit the empty value.

Suggested change
enc.StringKeyOmitEmpty("chosen_alpn", e.chosenAlpn)
enc.StringKey"chosen_alpn", e.chosenAlpn)

}
5 changes: 5 additions & 0 deletions qlog/qlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func NewConnectionTracer(w io.WriteCloser, p protocol.Perspective, odcid protoco
ECNStateUpdated: func(state logging.ECNState, trigger logging.ECNStateTrigger) {
t.ECNStateUpdated(state, trigger)
},
ChoseAlpn: func(protocol string) {
t.mutex.Lock()
t.recordEvent(time.Now(), eventAlpnInformation{chosenAlpn: protocol})
marten-seemann marked this conversation as resolved.
Show resolved Hide resolved
t.mutex.Unlock()
},
Debug: func(name, msg string) {
t.Debug(name, msg)
},
Expand Down
Loading