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
add gzip brotli compression to http responses (close #2674) #2751
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. |
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
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 |
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 |
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/query
and/v1/graphql
endpoints. The server chooses either brotli or gzip based onAccept-Encoding
client header. If both are requested then the server picksbrotli
.Affected components
Related Issues
close #2674
Solution and Design
Hasura.Server.Compression
module 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_compression
is introduced which is a boolean value.A new
content_encoding
field is added tohttp_info
ofhttp-log
. It is eitherbrotli
orgzip
andnull
if the encoding is not enabled or not requested by the client. See the example below.Steps to test and verify
In the console, make any query with the
network
tab opened in developer options. Check the size of response received when compression enabled and disabled.Limitations, known bugs & workarounds