-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
apiserver: decorate http.ResponseWriter correctly #104920
apiserver: decorate http.ResponseWriter correctly #104920
Conversation
8c28ee4
to
cb0df8c
Compare
e878e95
to
10be4b9
Compare
|
Yes, I think we should create and use a generic abstraction for this decoration. I tried drafting that, have a look at #104943 . |
@MikeSpreitzer thanks, I initially tried a similar pattern - I will update the PR with a reusable abstraction. |
3b3bae8
to
817c3c0
Compare
817c3c0
to
73153d5
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.
/LGTM
Thanks!
klog.InfoDepth(1, fmt.Sprintf("Unable to convert %+v into http.Flusher", rl.w)) | ||
} | ||
} | ||
|
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.
why is this removal fine?
73153d5
to
0d50c96
Compare
/lgtm |
/assign @mrunalp |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: MikeSpreitzer, mrunalp, sttts, tkashem The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
Will this pr be merged in v1.22.x? |
It's not small enough or critical enough to be back ported to 1.22.x. Is there any particular reason you want it in 1.22.x? |
My project is using |
What type of PR is this?
/kind bug
What this PR does / why we need it:
today there are four handlers that decorate
http.ResponseWriter
in apiserver filter chain:Additional interfaces like
http.Flusher
,http.Hijacker
,http.CloseNotifier
are also implemented by the basic response writer object provided to the request handler by net/http.we want to establish an invariant that the decorator extends only the interfaces implemented by the original response writer object, so that check like the following always gives the correct answer:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/watch.go#L177-L183
our decorators have logic like this (https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go#L490-L498)
for an http2 request,
if closenotifiable && flushable && hijackable
will never be true, since http2 does not implementhttp.Hijacker
. The following is from go net/http doc:closenotifiable && flushable && hijackable
is trueclosenotifiable && flushable
is trueso the decorator drops
Flusher
and we see the following error for watch request if the decorator is used:Today, watch.go works around this issue by skipping the decorators and looking at the original response writer object provided by net/http
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/watch.go#L169
This poses a couple of issues:
httplog
constructs even though log level is below3
. This is blocking apiserver: construct logger for httplog only when log level is 3 #104557. We basically want to optimizehttplog
- initialize only when we need to.WATCH
:code
is always0
(we could not tap into the status code because decorators were skipped)This PR ensures that:
flusher, ok := w.(http.Flusher)
, we won't need to retrieve the original response writer object.Which issue(s) this PR fixes:
Special notes for your reviewer:
If folks have an interest to have a reusable abstraction for this i am happy to look into it - I tried a few patterns but was not very happy with those.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: