From 5cf72e2f34221c6c076f19e1a4d406e22986fb5e Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 22 Jul 2020 15:19:45 +0700 Subject: [PATCH] implement qlogging of the congestion_state_updated event --- qlog/event.go | 12 ++++++++++++ qlog/qlog.go | 6 +++++- qlog/qlog_test.go | 10 ++++++++++ qlog/types.go | 17 +++++++++++++++++ qlog/types_test.go | 7 +++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/qlog/event.go b/qlog/event.go index 8c1935dd6..ddb7a012c 100644 --- a/qlog/event.go +++ b/qlog/event.go @@ -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()) +} diff --git a/qlog/qlog.go b/qlog/qlog.go index 03107a775..96cada2cf 100644 --- a/qlog/qlog.go +++ b/qlog/qlog.go @@ -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() diff --git a/qlog/qlog_test.go b/qlog/qlog_test.go index 0128429db..ef1b53cc6 100644 --- a/qlog/qlog_test.go +++ b/qlog/qlog_test.go @@ -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() diff --git a/qlog/types.go b/qlog/types.go index e38d77247..3ff09c554 100644 --- a/qlog/types.go +++ b/qlog/types.go @@ -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") + } +} diff --git a/qlog/types_test.go b/qlog/types_test.go index 46ccf35f6..434398beb 100644 --- a/qlog/types_test.go +++ b/qlog/types_test.go @@ -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")) + }) })