implement qlogging of the congestion_state_updated event

This commit is contained in:
Marten Seemann
2020-07-22 15:19:45 +07:00
parent 0b7efe10d1
commit 5cf72e2f34
5 changed files with 51 additions and 1 deletions

View File

@@ -422,3 +422,15 @@ func (e eventLossTimerCanceled) IsNil() bool { return false }
func (e eventLossTimerCanceled) MarshalJSONObject(enc *gojay.Encoder) {
enc.StringKey("event_type", "cancelled")
}
type eventCongestionStateUpdated struct {
state congestionState
}
func (e eventCongestionStateUpdated) Category() category { return categoryRecovery }
func (e eventCongestionStateUpdated) Name() string { return "congestion_state_updated" }
func (e eventCongestionStateUpdated) IsNil() bool { return false }
func (e eventCongestionStateUpdated) MarshalJSONObject(enc *gojay.Encoder) {
enc.StringKey("new", e.state.String())
}

View File

@@ -316,7 +316,11 @@ func (t *connectionTracer) LostPacket(encLevel protocol.EncryptionLevel, pn prot
t.mutex.Unlock()
}
func (t *connectionTracer) UpdatedCongestionState(logging.CongestionState) {}
func (t *connectionTracer) UpdatedCongestionState(state logging.CongestionState) {
t.mutex.Lock()
t.recordEvent(time.Now(), &eventCongestionStateUpdated{state: congestionState(state)})
t.mutex.Unlock()
}
func (t *connectionTracer) UpdatedPTOCount(value uint32) {
t.mutex.Lock()

View File

@@ -527,6 +527,16 @@ var _ = Describe("Tracing", func() {
Expect(ev).To(HaveKeyWithValue("trigger", "reordering_threshold"))
})
It("records congestion state updates", func() {
tracer.UpdatedCongestionState(logging.CongestionStateCongestionAvoidance)
entry := exportAndParseSingle()
Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond)))
Expect(entry.Category).To(Equal("recovery"))
Expect(entry.Name).To(Equal("congestion_state_updated"))
ev := entry.Event
Expect(ev).To(HaveKeyWithValue("new", "congestion_avoidance"))
})
It("records PTO changes", func() {
tracer.UpdatedPTOCount(42)
entry := exportAndParseSingle()

View File

@@ -308,3 +308,20 @@ func (r timeoutReason) String() string {
panic("unknown close reason")
}
}
type congestionState logging.CongestionState
func (s congestionState) String() string {
switch logging.CongestionState(s) {
case logging.CongestionStateSlowStart:
return "slow_start"
case logging.CongestionStateCongestionAvoidance:
return "congestion_avoidance"
case logging.CongestionStateRecovery:
return "recovery"
case logging.CongestionStateApplicationLimited:
return "application_limited"
default:
panic("unknown congestion state")
}
}

View File

@@ -124,4 +124,11 @@ var _ = Describe("Types", func() {
Expect(transportError(1337).String()).To(BeEmpty())
})
})
It("has a string representation for congestion state updates", func() {
Expect(congestionState(logging.CongestionStateSlowStart).String()).To(Equal("slow_start"))
Expect(congestionState(logging.CongestionStateCongestionAvoidance).String()).To(Equal("congestion_avoidance"))
Expect(congestionState(logging.CongestionStateApplicationLimited).String()).To(Equal("application_limited"))
Expect(congestionState(logging.CongestionStateRecovery).String()).To(Equal("recovery"))
})
})