stats: set response compression codec on stats.InHeader and stats.OutHeader (#3390)
This commit is contained in:
@ -296,7 +296,8 @@ func (ht *serverHandlerTransport) WriteHeader(s *Stream, md metadata.MD) error {
|
|||||||
// Note: The header fields are compressed with hpack after this call returns.
|
// Note: The header fields are compressed with hpack after this call returns.
|
||||||
// No WireLength field is set here.
|
// No WireLength field is set here.
|
||||||
ht.stats.HandleRPC(s.Context(), &stats.OutHeader{
|
ht.stats.HandleRPC(s.Context(), &stats.OutHeader{
|
||||||
Header: md.Copy(),
|
Header: md.Copy(),
|
||||||
|
Compression: s.sendCompress,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1195,9 +1195,10 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) {
|
|||||||
if t.statsHandler != nil {
|
if t.statsHandler != nil {
|
||||||
if isHeader {
|
if isHeader {
|
||||||
inHeader := &stats.InHeader{
|
inHeader := &stats.InHeader{
|
||||||
Client: true,
|
Client: true,
|
||||||
WireLength: int(frame.Header().Length),
|
WireLength: int(frame.Header().Length),
|
||||||
Header: s.header.Copy(),
|
Header: s.header.Copy(),
|
||||||
|
Compression: s.recvCompress,
|
||||||
}
|
}
|
||||||
t.statsHandler.HandleRPC(s.ctx, inHeader)
|
t.statsHandler.HandleRPC(s.ctx, inHeader)
|
||||||
} else {
|
} else {
|
||||||
|
@ -816,7 +816,8 @@ func (t *http2Server) writeHeaderLocked(s *Stream) error {
|
|||||||
// Note: Headers are compressed with hpack after this call returns.
|
// Note: Headers are compressed with hpack after this call returns.
|
||||||
// No WireLength field is set here.
|
// No WireLength field is set here.
|
||||||
outHeader := &stats.OutHeader{
|
outHeader := &stats.OutHeader{
|
||||||
Header: s.header.Copy(),
|
Header: s.header.Copy(),
|
||||||
|
Compression: s.sendCompress,
|
||||||
}
|
}
|
||||||
t.stats.HandleRPC(s.Context(), outHeader)
|
t.stats.HandleRPC(s.Context(), outHeader)
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,10 @@ type InHeader struct {
|
|||||||
Client bool
|
Client bool
|
||||||
// WireLength is the wire length of header.
|
// WireLength is the wire length of header.
|
||||||
WireLength int
|
WireLength int
|
||||||
|
// Compression is the compression algorithm used for the RPC.
|
||||||
|
Compression string
|
||||||
|
// Header contains the header metadata received.
|
||||||
|
Header metadata.MD
|
||||||
|
|
||||||
// The following fields are valid only if Client is false.
|
// The following fields are valid only if Client is false.
|
||||||
// FullMethod is the full RPC method string, i.e., /package.service/method.
|
// FullMethod is the full RPC method string, i.e., /package.service/method.
|
||||||
@ -89,10 +93,6 @@ type InHeader struct {
|
|||||||
RemoteAddr net.Addr
|
RemoteAddr net.Addr
|
||||||
// LocalAddr is the local address of the corresponding connection.
|
// LocalAddr is the local address of the corresponding connection.
|
||||||
LocalAddr net.Addr
|
LocalAddr net.Addr
|
||||||
// Compression is the compression algorithm used for the RPC.
|
|
||||||
Compression string
|
|
||||||
// Header contains the header metadata received.
|
|
||||||
Header metadata.MD
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsClient indicates if the stats information is from client side.
|
// IsClient indicates if the stats information is from client side.
|
||||||
@ -141,6 +141,10 @@ func (s *OutPayload) isRPCStats() {}
|
|||||||
type OutHeader struct {
|
type OutHeader struct {
|
||||||
// Client is true if this OutHeader is from client side.
|
// Client is true if this OutHeader is from client side.
|
||||||
Client bool
|
Client bool
|
||||||
|
// Compression is the compression algorithm used for the RPC.
|
||||||
|
Compression string
|
||||||
|
// Header contains the header metadata sent.
|
||||||
|
Header metadata.MD
|
||||||
|
|
||||||
// The following fields are valid only if Client is true.
|
// The following fields are valid only if Client is true.
|
||||||
// FullMethod is the full RPC method string, i.e., /package.service/method.
|
// FullMethod is the full RPC method string, i.e., /package.service/method.
|
||||||
@ -149,10 +153,6 @@ type OutHeader struct {
|
|||||||
RemoteAddr net.Addr
|
RemoteAddr net.Addr
|
||||||
// LocalAddr is the local address of the corresponding connection.
|
// LocalAddr is the local address of the corresponding connection.
|
||||||
LocalAddr net.Addr
|
LocalAddr net.Addr
|
||||||
// Compression is the compression algorithm used for the RPC.
|
|
||||||
Compression string
|
|
||||||
// Header contains the header metadata sent.
|
|
||||||
Header metadata.MD
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsClient indicates if this stats information is from client side.
|
// IsClient indicates if this stats information is from client side.
|
||||||
|
@ -446,6 +446,9 @@ func checkInHeader(t *testing.T, d *gotData, e *expectedData) {
|
|||||||
if d.ctx == nil {
|
if d.ctx == nil {
|
||||||
t.Fatalf("d.ctx = nil, want <non-nil>")
|
t.Fatalf("d.ctx = nil, want <non-nil>")
|
||||||
}
|
}
|
||||||
|
if st.Compression != e.compression {
|
||||||
|
t.Fatalf("st.Compression = %v, want %v", st.Compression, e.compression)
|
||||||
|
}
|
||||||
if d.client {
|
if d.client {
|
||||||
// additional headers might be injected so instead of testing equality, test that all the
|
// additional headers might be injected so instead of testing equality, test that all the
|
||||||
// expected headers keys have the expected header values.
|
// expected headers keys have the expected header values.
|
||||||
@ -461,9 +464,6 @@ func checkInHeader(t *testing.T, d *gotData, e *expectedData) {
|
|||||||
if st.LocalAddr.String() != e.serverAddr {
|
if st.LocalAddr.String() != e.serverAddr {
|
||||||
t.Fatalf("st.LocalAddr = %v, want %v", st.LocalAddr, e.serverAddr)
|
t.Fatalf("st.LocalAddr = %v, want %v", st.LocalAddr, e.serverAddr)
|
||||||
}
|
}
|
||||||
if st.Compression != e.compression {
|
|
||||||
t.Fatalf("st.Compression = %v, want %v", st.Compression, e.compression)
|
|
||||||
}
|
|
||||||
// additional headers might be injected so instead of testing equality, test that all the
|
// additional headers might be injected so instead of testing equality, test that all the
|
||||||
// expected headers keys have the expected header values.
|
// expected headers keys have the expected header values.
|
||||||
for key := range testMetadata {
|
for key := range testMetadata {
|
||||||
@ -575,6 +575,9 @@ func checkOutHeader(t *testing.T, d *gotData, e *expectedData) {
|
|||||||
if d.ctx == nil {
|
if d.ctx == nil {
|
||||||
t.Fatalf("d.ctx = nil, want <non-nil>")
|
t.Fatalf("d.ctx = nil, want <non-nil>")
|
||||||
}
|
}
|
||||||
|
if st.Compression != e.compression {
|
||||||
|
t.Fatalf("st.Compression = %v, want %v", st.Compression, e.compression)
|
||||||
|
}
|
||||||
if d.client {
|
if d.client {
|
||||||
if st.FullMethod != e.method {
|
if st.FullMethod != e.method {
|
||||||
t.Fatalf("st.FullMethod = %s, want %v", st.FullMethod, e.method)
|
t.Fatalf("st.FullMethod = %s, want %v", st.FullMethod, e.method)
|
||||||
@ -582,9 +585,6 @@ func checkOutHeader(t *testing.T, d *gotData, e *expectedData) {
|
|||||||
if st.RemoteAddr.String() != e.serverAddr {
|
if st.RemoteAddr.String() != e.serverAddr {
|
||||||
t.Fatalf("st.RemoteAddr = %v, want %v", st.RemoteAddr, e.serverAddr)
|
t.Fatalf("st.RemoteAddr = %v, want %v", st.RemoteAddr, e.serverAddr)
|
||||||
}
|
}
|
||||||
if st.Compression != e.compression {
|
|
||||||
t.Fatalf("st.Compression = %v, want %v", st.Compression, e.compression)
|
|
||||||
}
|
|
||||||
// additional headers might be injected so instead of testing equality, test that all the
|
// additional headers might be injected so instead of testing equality, test that all the
|
||||||
// expected headers keys have the expected header values.
|
// expected headers keys have the expected header values.
|
||||||
for key := range testMetadata {
|
for key := range testMetadata {
|
||||||
|
Reference in New Issue
Block a user