Skip to content

Commit

Permalink
server: populate WireLength on stats.InPayload for unary RPCs (grpc#2932
Browse files Browse the repository at this point in the history
)

Fixes grpc#2692 which was incompletely fixed by grpc#2711.

Also adds updates stats/stat_test.go to sanity check WireLength.
  • Loading branch information
ajwerner committed Jul 25, 2019
1 parent ace6945 commit 359d7c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 5 additions & 4 deletions server.go
Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions stats/stats_test.go
Expand Up @@ -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 <non-zero>",
st.WireLength)
}
if st.RecvTime.IsZero() {
t.Fatalf("st.ReceivedTime = %v, want <non-zero>", st.RecvTime)
}
Expand Down Expand Up @@ -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 <non-zero>",
st.WireLength)
}
if st.SentTime.IsZero() {
t.Fatalf("st.SentTime = %v, want <non-zero>", st.SentTime)
}
Expand Down

0 comments on commit 359d7c2

Please sign in to comment.