From f0893a591d7f4afad240c60e195cdb280db38807 Mon Sep 17 00:00:00 2001 From: ajwerner Date: Wed, 24 Jul 2019 19:24:45 -0400 Subject: [PATCH] server: populate WireLength on stats.InPayload for unary RPCs (#2932) Fixes #2692 which was incompletely fixed by #2711. Also adds updates stats/stat_test.go to sanity check WireLength. --- server.go | 9 +++++---- stats/stats_test.go | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index 1766136253b..617289e2e36 100644 --- a/server.go +++ b/server.go @@ -978,10 +978,11 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport. } if sh != nil { sh.HandleRPC(stream.Context(), &stats.InPayload{ - RecvTime: time.Now(), - Payload: v, - Data: d, - Length: len(d), + RecvTime: time.Now(), + Payload: v, + WireLength: payInfo.wireLength, + Data: d, + Length: len(d), }) } if binlog != nil { diff --git a/stats/stats_test.go b/stats/stats_test.go index d97904bc5c1..98829035b71 100644 --- a/stats/stats_test.go +++ b/stats/stats_test.go @@ -511,7 +511,12 @@ func checkInPayload(t *testing.T, d *gotData, e *expectedData) { t.Fatalf("st.Lenght = %v, want %v", st.Length, len(b)) } } - // TODO check WireLength and ReceivedTime. + // Below are sanity checks that WireLength and RecvTime are populated. + // TODO: check values of WireLength and RecvTime. + if len(st.Data) > 0 && st.WireLength == 0 { + t.Fatalf("st.WireLength = %v with non-empty data, want ", + st.WireLength) + } if st.RecvTime.IsZero() { t.Fatalf("st.ReceivedTime = %v, want ", st.RecvTime) } @@ -603,7 +608,12 @@ func checkOutPayload(t *testing.T, d *gotData, e *expectedData) { t.Fatalf("st.Lenght = %v, want %v", st.Length, len(b)) } } - // TODO check WireLength and ReceivedTime. + // Below are sanity checks that WireLength and SentTime are populated. + // TODO: check values of WireLength and SentTime. + if len(st.Data) > 0 && st.WireLength == 0 { + t.Fatalf("st.WireLength = %v with non-empty data, want ", + st.WireLength) + } if st.SentTime.IsZero() { t.Fatalf("st.SentTime = %v, want ", st.SentTime) }