Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: set response compression codec on stats.InHeader and stats.OutHeader #3390

Merged
merged 2 commits into from Mar 20, 2020

Conversation

MatthewDolan
Copy link
Contributor

Currently, the request compression is recorded (on stats.OutHeader client-side and stats.InHeader server-side), but the response compression is never recorded. Although these compression codecs are often the same, the gRPC compression specification (https://github.com/grpc/grpc/blob/master/doc/compression.md) states that it's valid for them to be different.

  • The pull request captures the response compression (on stats.InHeader client-side and stats.OutHeader server-side).
  • This pull request moves the two fields (Compression and Header) above the comment The following fields are valid only if Client is true. because they are now both valid on the server-side and client-side.

@dfawley dfawley self-assigned this Feb 27, 2020
@dfawley dfawley added this to the 1.28 Release milestone Feb 27, 2020
@easwars easwars assigned menghanl and unassigned dfawley Mar 5, 2020
@dfawley dfawley modified the milestones: 1.28 Release, 1.29 Release Mar 5, 2020
@menghanl menghanl changed the title Set response compression codec on stats.InHeader and stats.OutHeader stats: set response compression codec on stats.InHeader and stats.OutHeader Mar 19, 2020
Copy link
Contributor

@menghanl menghanl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Can you change the tests to cover the new field as well? The following diff should work.

Also, I think you might have missed http2_server.go. The test hopefully should catch that.

Thanks!

diff --git a/stats/stats_test.go b/stats/stats_test.go
index ff16c182..d047d48b 100644
--- a/stats/stats_test.go
+++ b/stats/stats_test.go
@@ -446,6 +446,9 @@ func checkInHeader(t *testing.T, d *gotData, e *expectedData) {
        if d.ctx == 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 {
                // additional headers might be injected so instead of testing equality, test that all the
                // 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 {
                        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
                // expected headers keys have the expected header values.
                for key := range testMetadata {
@@ -575,6 +575,9 @@ func checkOutHeader(t *testing.T, d *gotData, e *expectedData) {
        if d.ctx == 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 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 {
                        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
                // expected headers keys have the expected header values.
                for key := range testMetadata {

@MatthewDolan
Copy link
Contributor Author

Thank you for the feedback, @menghanl.

You were right about the tests and missed case. I have updated both, rebased on latest, and updated the pull request.

Copy link
Contributor

@menghanl menghanl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the changes!

@menghanl menghanl merged commit b3dcc68 into grpc:master Mar 20, 2020
MatthewDolan added a commit to MatthewDolan/grpc-go that referenced this pull request Mar 31, 2020
MatthewDolan added a commit to lightstep/grpc-go that referenced this pull request Apr 8, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants