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

feat: add gzip to http responses for query/batch-query #232

Merged
merged 4 commits into from
Jan 27, 2023

Conversation

michaelx11
Copy link
Contributor

@michaelx11 michaelx11 commented Jan 27, 2023

Goal

This PR implements gzip compression for HTTP responses of the JSON interface of our node gRPC API. This happens for responses to query and batch-query methods. As of now, clients already send: Accept-Encoding: gzip, deflate but server responses are not currently compressed. Given 1) base64 encoding and 2) redundant structure and fields, our responses are pretty compressible even though the envelope contents are high entropy.

(encrypted contents of test accounts, no sweat that I'm pasting here)

Screen Shot 2023-01-27 at 12 58 44 PM

Changes

One issue is that our clients currently send Accept-Encoding: gzip even for long-lived /subscribe requests, which our server will happily attempt to gzip before sending a response. To combat this I've implemented our gzip handler with standard libraries and gated it to just /query && /batch-query responses.

Testing

  • unit tests
  • e2e tests
  • manual compression check

@@ -118,7 +118,7 @@ func Test_QueryNoTopics(t *testing.T) {
require.Equal(t, codes.InvalidArgument, grpcErr.Code())
require.EqualError(t, err, `rpc error: code = InvalidArgument desc = content topics required`)
} else {
require.EqualError(t, err, "400 Bad Request: {\"code\":3, \"message\":\"content topics required\", \"details\":[]}")
require.Regexp(t, `400 Bad Request: {"code\":3,\s?"message":"content topics required",\s?"details":\[\]}`, err.Error())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

somehow the whitespaces get stripped now? I noticed the test above already accounts for this via regexp so did the same here

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right I think this is what's happening golang/protobuf#1121

Copy link
Contributor

@mkobetic mkobetic left a comment

Choose a reason for hiding this comment

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

Looks like a good idea. 👍

@@ -0,0 +1,39 @@
package api
Copy link
Contributor

Choose a reason for hiding this comment

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

Want to just call this file gzip.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, will make that change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up renaming to gzip_handler.go, I balked at gzip.go since it seemed like a name that could be used a lot elsewhere.

@michaelx11 michaelx11 merged commit 84b0788 into main Jan 27, 2023
@michaelx11 michaelx11 deleted the add-gzip-to-http-responses-queryonly branch January 27, 2023 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants