-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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 compression to GET and LIST requests #45666
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Hi @ilackarms. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
cc @kubernetes/sig-api-machinery-pr-reviews |
@k8s-bot ok to test |
} | ||
|
||
const ( | ||
header_AcceptEncoding = "Accept-Encoding" |
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.
kube convention doesn't use underscores in constant names.
func WithCompression(handler http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
//don't compress watches | ||
if req.URL.Query().Get("watch") == "true" { |
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.
plumb through a RequestContextMapper
from https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go#L188 and then use https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go#L229 and https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go#L35
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.
With that info, you can whitelist instead of blacklist. Or you can blacklist more effectively.
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 for the review, I'll look into this now
case encoding_deflate: | ||
compressor = zlib.NewWriter(w) | ||
default: | ||
panic(encoding + " not a valid compression type") |
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.
We prefer returning and error and letting the caller handle it. In this case, why wouldn't we degrade to a non-compressed response instead of dying?
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 shouldn't be here at all; wantsCompression
simply returns false if the user specifies a compression type that doesn't exactly match gzip
or deflate
. I'll fix this in my next commit
} | ||
|
||
func RestfulWithCompression(function restful.RouteFunction) restful.RouteFunction { | ||
return restful.RouteFunction(func(request *restful.Request, response *restful.Response) { |
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 expected this to delegate to WithCompression
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.
Does the following seem right to you? I feel like I'm messing with restful
internals here, but this was how I implemented the delegation:
func RestfulWithCompression(function restful.RouteFunction) restful.RouteFunction {
return restful.RouteFunction(func(request *restful.Request, response *restful.Response) {
handler := WithCompression(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
response.ResponseWriter = w
request.Request = req
function(request, response)
}))
handler.ServeHTTP(response.ResponseWriter, request.Request)
})
}
I didn't want to go with this as I was more comfortable being explicit with the code (despite their being code duplication)
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.
Does the following seem right to you? I
Looks like it would work. Not pretty, but workable
bdf7eda
to
0acde54
Compare
@k8s-bot gce etcd3 e2e test this |
squash, fix gofmt (verify) and I'll take another pass |
e296af3
to
20b37cb
Compare
@k8s-bot gce etcd3 e2e test this |
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
wantsCompression, encoding := wantsCompressedResponse(req) | ||
if wantsCompression { | ||
compressionWriter := NewCompressionResponseWriter(w, encoding) |
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.
@sttts I remember that this caused us problems in the general case, but here it's only getting added for get and list. Any concerns about wrapping here?
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.
looks good
@k8s-bot pull-kubernetes-unit test this |
gating issue #46963 |
go ahead and add a release note in the PR description |
@ilackarms: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
I updated links and issues, so this gets another shot in the queue. please update. |
Submit queue, pay attention. |
Automatic merge from submit-queue |
Automatic merge from submit-queue (batch tested with PRs 47883, 47179, 46966, 47982, 47945) Add feature gating to REST Compression **What this PR does / why we need it**: Adds feature gating to opt out of REST API compression **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #46963 **Special notes for your reviewer**: This PR is a fix / addendum to #45666 **Release note**: ```release-note ```
Does anyone know what version of kubernetes this made it into? I'm using minikube that contains 1.7..0 and setting the Accept-encoding to gzip but I do not see the expected Content-Encoding response header after requesting a resource list. |
Fixes #44164
Enable compressed response bodies for non-watch GET and LIST requests on API Objects.
What this PR does / why we need it: Adds compression via Accept-Encoding header, returns Content-Encoding header on responses (only supports gzip at this time). Enabled solely for GET and LIST requests which can return very large response bodies.
Special notes for your reviewer:
See #44164 for discussion.
Release note: