-
Notifications
You must be signed in to change notification settings - Fork 287
Optimize the handling of the return messages of the extender scheduler #908
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: learner0810 <[email protected]>
e69abdc
to
5886aca
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.
PR Overview
This PR optimizes the handling of return messages in the extender scheduler by refactoring manual JSON marshalling and response writing to use the unrolled render package. Key changes include:
- Removal of redundant fmt import.
- Updated PredicateRoute and Bind handlers to use render.New(...).JSON.
- Consistent logging of JSON rendering errors.
Reviewed Changes
File | Description |
---|---|
pkg/scheduler/routes/route.go | Refactored JSON response construction in two routes using render for cleaner code |
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
w.Write(resultBody) | ||
klog.V(5).InfoS("Returning predicate response", "result", extenderFilterResult) | ||
|
||
err := render.New(render.Options{IndentJSON: true}).JSON(w, http.StatusOK, extenderFilterResult) |
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.
If render.New(...).JSON fails, the client receives no fallback error response, which may lead to unexpected behavior. Consider adding a mechanism to send an appropriate error message to the client.
Copilot uses AI. Check for mistakes.
w.Write(response) | ||
klog.V(5).InfoS("Returning bind response", "result", extenderBindingResult) | ||
|
||
err := render.New(render.Options{IndentJSON: true}).JSON(w, http.StatusOK, extenderBindingResult) |
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.
In the Bind handler, if JSON rendering fails, no error response is sent to the client. It is recommended to include fallback error handling, similar to how errors were handled in the previous implementation.
Copilot uses AI. Check for mistakes.
err := render.New(render.Options{IndentJSON: true}).JSON(w, http.StatusOK, extenderFilterResult) | ||
if err != nil { | ||
klog.ErrorS(err, "Failed to write JSON response") | ||
return |
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.
When render.New(...).JSON fails, should write error info to client. like before code:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
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.
Pull Request Overview
This PR optimizes the handling of return messages in the extender scheduler by replacing manual JSON marshalling with a unified JSON rendering approach.
- Replaces custom JSON marshalling and manual response writing with unrolled/render for both predicate and binding endpoints.
- Removes unused fmt import and streamlines error handling for JSON responses.
Files not reviewed (1)
- go.mod: Language not supported
|
||
err := render.New(render.Options{IndentJSON: true}).JSON(w, http.StatusOK, extenderFilterResult) | ||
if err != nil { | ||
klog.ErrorS(err, "Failed to write JSON 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.
If render.New().JSON fails to write the response, it logs the error but does not set an appropriate HTTP error status or write an error message to the response body. Consider adding error handling that also sends an HTTP error code and message to the client.
klog.ErrorS(err, "Failed to write JSON response") | |
klog.ErrorS(err, "Failed to write JSON response") | |
http.Error(w, "Failed to write JSON response", http.StatusInternalServerError) |
Copilot uses AI. Check for mistakes.
|
||
err := render.New(render.Options{IndentJSON: true}).JSON(w, http.StatusOK, extenderBindingResult) | ||
if err != nil { | ||
klog.ErrorS(err, "Failed to write JSON 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.
If render.New().JSON fails here, the error is only logged; the client is not informed via an HTTP error status or message. Consider handling the error by setting a proper HTTP error response.
klog.ErrorS(err, "Failed to write JSON response") | |
klog.ErrorS(err, "Failed to write JSON response") | |
http.Error(w, "Failed to process the response", http.StatusInternalServerError) |
Copilot uses AI. Check for mistakes.
What type of PR is this?
/kind flake
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Optimize the handling of the return messages of the extender scheduler
Does this PR introduce a user-facing change?: