-
Notifications
You must be signed in to change notification settings - Fork 2.8k
add gzip brotli compression to http responses (close #2674) #2751
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
Conversation
|
Deploy preview for hasura-docs ready! Built with commit 15fe9eb |
|
There is a wai middleware which does gzip https://hackage.haskell.org/package/wai-extra-3.0.28/docs/Network-Wai-Middleware-Gzip.html . Shouldn't we use this directly? |
@rakeshkky pointed out that we wanted to support Brotli compression as well (the wai middleware only does gzip), hence we rolled our own implementation. |
marionschleifer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments 🙂
docs/graphql/manual/deployment/graphql-engine-flags/config-examples.rst
Outdated
Show resolved
Hide resolved
docs/graphql/manual/deployment/graphql-engine-flags/config-examples.rst
Outdated
Show resolved
Hide resolved
docs/graphql/manual/deployment/graphql-engine-flags/config-examples.rst
Outdated
Show resolved
Hide resolved
docs/graphql/manual/deployment/graphql-engine-flags/config-examples.rst
Outdated
Show resolved
Hide resolved
docs/graphql/manual/deployment/graphql-engine-flags/config-examples.rst
Outdated
Show resolved
Hide resolved
Suggested by @marionschleifer
Resolve Conflicts: .circleci/config.yml server/stack.yaml.lock
marionschleifer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
|
Review app for commit d66c417 deployed to Heroku: https://hge-ci-pull-2751.herokuapp.com |
Resolve Conflicts: server/src-lib/Hasura/Server/App.hs server/src-lib/Hasura/Server/Init.hs
|
Review app for commit 7d4ac90 deployed to Heroku: https://hge-ci-pull-2751.herokuapp.com |
|
Review app for commit befabf8 deployed to Heroku: https://hge-ci-pull-2751.herokuapp.com |
shahidhk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling that ENABLE_COMPRESSION can be confusing with data compression in the database etc. Should we call it ENABLE_API_RESPONSE_COMPRESSION or ENABLE_API_COMPRESSION to be as explicit as we can?
|
I don’t have strong feelings about it either way, but how about |
|
Also, why do we need a flag to enable this? The response is only compressed if the right |
Not that I know of. I’d have no problem enabling it by default, but I’ll defer to @rakeshkky’s judgement on that. |
The server compresses the response based on `Accept-Encoding` header value
15fe9eb
befabf8 to
15fe9eb
Compare
|
@shahidhk @lexi-lambda I've removed the |
|
Review app for commit 15fe9eb deployed to Heroku: https://hge-ci-pull-2751.herokuapp.com |
shahidhk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Review app https://hge-ci-pull-2751.herokuapp.com is deleted |
Add brotli library dependencies to the server docker image. The compression feature introduced in #2751 requires brotli shared libraries at runtime. In original PR, adding them to server packager image was missing.
Add brotli library dependencies to the server docker image. The compression feature introduced in hasura#2751 requires brotli shared libraries at runtime. In original PR, adding them to server packager image was missing.
## Description ✍️ This PR fixes the config status update when the `Service configured successfully` message is written before the server is actually spawned. Now the status is updated only when the server is spawned successfully. To be specific, this change posts the status closer to where we log `starting API server`. ### Related Issues ✍ #2751 ### Solution and Design ✍ We update the status inside `runHGEServer` function. This helps in adding the message only when the server is started. If any exception is thrown before the server is spawned, only that message is written to `config_status` table instead of the `Service configured successfully` message. ## Affected components ✍️ - ✅ Server PR-URL: hasura/graphql-engine-mono#5179 Co-authored-by: Naveen Naidu <30195193+Naveenaidu@users.noreply.github.com> Co-authored-by: Anon Ray <616387+ecthiender@users.noreply.github.com> GitOrigin-RevId: 7860008403aa0645583e26915f620b66a5bbc531
Description
The server compresses the responses (success only) from
/v1/queryand/v1/graphqlendpoints. The server chooses either brotli or gzip based onAccept-Encodingclient header. If both are requested then the server picksbrotli.Affected components
Related Issues
close #2674
Solution and Design
Hasura.Server.Compressionmodule which exposes the compression type and function to compress.New things
Compression details are added to the logs. In the start-up log, the new field
enable_compressionis introduced which is a boolean value.A new
content_encodingfield is added tohttp_infoofhttp-log. It is eitherbrotliorgzipandnullif the encoding is not enabled or not requested by the client. See the example below.{ "timestamp": "2019-08-23T02:05:28.059-05:00", "level": "info", "type": "http-log", "detail": { "operation": { "query_execution_time": 0.018795933, "user_vars": { "x-hasura-role": "admin" }, "error": null, "request_id": "6283add2-db7b-4eec-9b1e-d14781893b2f", "response_size": 45, "query": null }, "http_info": { "status": 200, "http_version": "HTTP/1.1", "url": "/v1/query", "ip": "127.0.0.1", "method": "POST", "content_encoding": "brotli" } } }Steps to test and verify
In the console, make any query with the
networktab opened in developer options. Check the size of response received when compression enabled and disabled.Limitations, known bugs & workarounds