-
Notifications
You must be signed in to change notification settings - Fork 303
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 statusCodeHandler to 404-server-with-metrics which serves status code given in URL path #1844
Conversation
Hi @yiyangy. 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. |
/cc @bowei |
/ok-to-test |
p := strings.TrimPrefix(r.URL.Path, statusCodePrefix) | ||
code, err := strconv.Atoi(p) | ||
if err != nil { | ||
code = http.StatusNotFound |
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 should return an error message here instead of dropping through...
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.
func (s *server) statusCodeHandler() http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
p := strings.TrimPrefix(r.URL.Path, statusCodePrefix) | ||
code, err := strconv.Atoi(p) |
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 should only allow codes between [400, 599] to avoid potential for any abuse use case.
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.
statusText = http.StatusText(code) | ||
} | ||
w.WriteHeader(code) | ||
fmt.Fprintf(w, "response %d (%s) \n", code, statusText) |
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 probably don't need the text...
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.
/cc @swetharepakula |
…code given in URL path
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bowei, yiyangy 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 |
…ge to release 1.20
[Cherrypick #1844] cherry pick 404-server-with-metrics change to release 1.20
Add to 404 server with metrics the functionality to return status code. The status code to return is given in the URL path of request in the format of /statuscode/
, e.g. /statuscode/500 .