-
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
GET should be transformed to watch in kube-Apiserver #105648
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://git.k8s.io/community/CLA.md#the-contributor-license-agreement 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. |
Welcome @kkkkun! |
Hi @kkkkun. 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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
done! |
/release-note-none |
/ok-to-test |
/assign @yliaog |
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.
/hold
@@ -544,7 +544,7 @@ func CanonicalVerb(verb string, scope string) string { | |||
// LIST and APPLY from PATCH. | |||
func CleanVerb(verb string, request *http.Request) string { | |||
reportedVerb := verb | |||
if verb == "LIST" { | |||
if verb == "LIST" || verb == "GET" { |
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 isn't correct.
We don't support watch on GET verb (well - with verb in the meaning of how we treat that in kube-apiserver, because the actual http verb is GET - but it's not what we get here).
watch is only supported for LIST requests.
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.
Here we have a kubelet's watch request just like.
/api/v1/nodes?allowWatchBookmarks=true&fieldSelector=metadata.name=test-01&resourceVersion=53658191&timeout=8m40s&timeoutSeconds=520&watch=true.
It will be recorded to GET longrunning request because It has metadata.name. But actually it is a WATCH request.
How to fix this?
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.
OK - I forgot that we're transforming to LIST verb only based on scope.
I'm thinking how to change that to avoid doing that for every single GET call, which we already know that is not watch.
Given that this is problematic only for:
- RecordRequestAbort
- RecordRequestTermination
- RecordLongRunning
I think it's better to do that detection there and avoid this check here.
So in other words:
- add a function:
// better name needed
string getVerbIfWatch(request *http.Request) {
}
that returns watch if the request is watch, "" otherwise
- call it in those places
- leave as is here (call that method, but only on LIST)
45ef21c
to
38af553
Compare
@wojtek-t Please review. |
reportedVerb := cleanVerb(CanonicalVerb(strings.ToUpper(req.Method), scope), "", req) | ||
reportedVerb := getVerbIfWatch(req) | ||
if reportedVerb != "WATCH" { | ||
reportedVerb = cleanVerb(CanonicalVerb(strings.ToUpper(req.Method), scope), "", req) |
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.
Let's unify the calls across all calls and change to:
reportedVerb := cleanVerb(CanonicalVerb(strings.ToUpper(req.Method), scope), getVerbIfWatch(req), req)
[Same everywhere below]
//getVerbIfWatch additionally ensures that GET or List would be transformed to WATCH | ||
func getVerbIfWatch(req *http.Request) string { | ||
if strings.ToUpper(req.Method) == "GET" || strings.ToUpper(req.Method) == "LIST" { | ||
// see apimachinery/pkg/runtime/conversion.go Convert_Slice_string_To_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.
Let's split this part into a separate function:
func checkIfWatch(req *http.Request) bool {
if values := req.URL.Query()["watch"]; len(values) > 0 {
if value := strings.ToLower(values[0]); value != "0" && value != "false" {
return true
}
}
return false
}
And use that function both here and in line 557
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.
done!
38af553
to
d9896a2
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.
One last comment - other than that LGTM
7a4fc78
to
c0b6cf5
Compare
c0b6cf5
to
5f98d8f
Compare
/lgtm |
/hold cancel |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kkkkun, wojtek-t 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 |
What type of PR is this?
/kind bug
What this PR does / why we need it:
We set apiserver_longrunning_gauge's threshould to 400 which not contain watch request. When the cluster scales to 600 node, we receive a alarm which exceeds the threshould. And it show that the request is 'GET Node'. However, the 'GET Node' request should not record to apiserver_longrunning_gauge.
And then, We add log to
kubernetes/staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go
Line 429 in e054181
When kubelet watch apiserver, it request contains self's 'metadata.name'. The scope would be set 'resource' and the reportedVerb finially would be set 'GET'. but requestInfo's Verb is watch. We should record this request to 'WATCH' rather than 'GET'. So here we should transform 'GET' or 'LIST' to watch when query has 'watch=true'
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?