-
Notifications
You must be signed in to change notification settings - Fork 797
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 support for gzip content-encoding #776
Conversation
5b2c4c4
to
129f2ff
Compare
Signed-off-by: ivan-valkov <iv.v.valkov@gmail.com>
129f2ff
to
291894f
Compare
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.
Thanks! Generally this looks reasonable though I have not fully tested it yet.
One thing to note, the golang client allows disabling compression as part of the options passed to the handler. I am wondering if we should do something similar here? The reason being, in some cases the cpu usage required to compress a large response can slow everything down too much.
Yeah, definitely, this makes sense. What would be the preferred semantic? GZIP compression enabled or disabled by default? I am conscious that if we enable it by default, some existing users of the client might see unexpected CPU spikes when using the new version of the client, so maybe we should require enabling GZIP compression explicitly? |
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 would say let's default to negotiating gzip as most use cases will not see much of a CPU spike, and advanced users can turn it off. This also aligns us with client_golang (enabled by default) and client_java (always enabled).
Signed-off-by: ivan-valkov <iv.v.valkov@gmail.com>
b3b2bf6
to
c2dc1aa
Compare
Signed-off-by: ivan-valkov <iv.v.valkov@gmail.com>
prometheus_client/exposition.py
Outdated
@@ -38,6 +39,13 @@ | |||
PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5) | |||
|
|||
|
|||
def _get_disable_compression() -> bool: |
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.
Instead of an environment variable what would you think of passing an additional argument to make_(w|a)sgi_app
? My thought is that most users should have control over creating the apps so an env var is not necessary. We try to only use env vars in places where users might not have access to the code, such as registering metrics.
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.
Yeah, makes sense. I suppose we need to expose this option in start_http_server
as well?
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 think that would be nice, though not completely required as start_http_server
doesn't need to support all configuration for advanced user.
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.
awesome, yeah, this makes sense. I have updated the PR now and added documentation to the README. PTAL when you get some time. I don't think there is a release notes file we need to update but maybe worth mentioning this change when releasing the next version of the client (:
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.
Thanks! I plan to review this early next week. I will definitely mention it in the release notes for the next version!
Signed-off-by: ivan-valkov <iv.v.valkov@gmail.com>
Signed-off-by: ivan-valkov <iv.v.valkov@gmail.com>
Signed-off-by: ivan-valkov <iv.v.valkov@gmail.com>
9ce658e
to
245c3be
Compare
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.
This looks great, thanks a lot!
Resolves #775
If an
Accept-Encoding:gzip
header is present, will compress the output and set the correctContent-Encoding
header in the response. Added tests for both the wsgi and asgi implementations.