Repository: quic-go/quic-go
Pull request #4895 (2025-01-20 15:50:57)

qlog: fix logging of packets_in_flight on the metrics_updated event
Resetting this value to 0 needs to be logged.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/quic-go/quic-go/pull/4895?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 83.59%. Comparing base [(`88501cc`)](https://app.codecov.io/gh/quic-go/quic-go/commit/88501cc02a6a00d959154a137cf813a4d6d53e86?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) to head [(`825ed31`)](https://app.codecov.io/gh/quic-go/quic-go/commit/825ed31994b949252636da0231f6716a35f43da4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4895      +/-   ##
==========================================
+ Coverage   83.55%   83.59%   +0.04%     
==========================================
  Files         151      148       -3     
  Lines       16223    16173      -50     
==========================================
- Hits        13554    13519      -35     
+ Misses       2138     2127      -11     
+ Partials      531      527       -4     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/quic-go/quic-go/pull/4895?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).


Patch:
diff --git a/qlog/event.go b/qlog/event.go
index 90a642af..e97b057b 100644
--- a/qlog/event.go
+++ b/qlog/event.go
@@ -336,7 +336,7 @@ func (e eventMetricsUpdated) MarshalJSONObject(enc *gojay.Encoder) {
 		enc.Uint64Key("bytes_in_flight", uint64(e.Current.BytesInFlight))
 	}
 	if e.Last == nil || e.Last.PacketsInFlight != e.Current.PacketsInFlight {
-		enc.Uint64KeyOmitEmpty("packets_in_flight", uint64(e.Current.PacketsInFlight))
+		enc.Uint64Key("packets_in_flight", uint64(e.Current.PacketsInFlight))
 	}
 }
 


Test patch:
diff --git a/qlog/connection_tracer_test.go b/qlog/connection_tracer_test.go
index 5b7adf60..1ec0e63e 100644
--- a/qlog/connection_tracer_test.go
+++ b/qlog/connection_tracer_test.go
@@ -624,7 +624,7 @@ func TestUpdatedMetrics(t *testing.T) {
 	require.Equal(t, float64(42), ev["packets_in_flight"])
 }
 
-func TestDiffForOnlyChangedMetrics(t *testing.T) {
+func TestUpdatedMetricsDiff(t *testing.T) {
 	var rttStats utils.RTTStats
 	rttStats.UpdateRTT(15*time.Millisecond, 0)
 	rttStats.UpdateRTT(20*time.Millisecond, 0)
@@ -638,9 +638,10 @@ func TestDiffForOnlyChangedMetrics(t *testing.T) {
 	tracer, buf := newConnectionTracer()
 	tracer.UpdatedMetrics(&rttStats, 4321, 1234, 42)
 	tracer.UpdatedMetrics(&rttStats2, 4321, 12345 /* changed */, 42)
+	tracer.UpdatedMetrics(&rttStats2, 0, 0, 0)
 	tracer.Close()
 	entries := exportAndParse(t, buf)
-	require.Len(t, entries, 2)
+	require.Len(t, entries, 3)
 	require.WithinDuration(t, time.Now(), entries[0].Time, scaleDuration(10*time.Millisecond))
 	require.Equal(t, "recovery:metrics_updated", entries[0].Name)
 	require.Len(t, entries[0].Event, 7)
@@ -652,6 +653,13 @@ func TestDiffForOnlyChangedMetrics(t *testing.T) {
 	require.NotContains(t, ev, "packets_in_flight")
 	require.Equal(t, float64(12345), ev["bytes_in_flight"])
 	require.Equal(t, float64(15), ev["smoothed_rtt"])
+	ev = entries[2].Event
+	require.Contains(t, ev, "congestion_window")
+	require.Contains(t, ev, "packets_in_flight")
+	require.Contains(t, ev, "bytes_in_flight")
+	require.Zero(t, ev["bytes_in_flight"])
+	require.Zero(t, ev["packets_in_flight"])
+	require.Zero(t, ev["congestion_window"])
 }
 
 func TestLostPackets(t *testing.T) {