Defining snapshop api for MSD#3210
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new Snapshot API for the MSD system, enabling users to create and manage named snapshots of Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new Snapshot API for MSD, including RDL definitions, generated Go and Java clients, models, and new unit tests. The changes are extensive and well-structured. The identified opportunities for improvement regarding code duplication and style consistency remain valid, as they do not conflict with the provided rules. Overall, this is a solid contribution.
| var errobj rdl.ResourceError | ||
| contentBytes, err = io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return data, err | ||
| } | ||
| json.Unmarshal(contentBytes, &errobj) | ||
| if errobj.Code == 0 { | ||
| errobj.Code = resp.StatusCode | ||
| } | ||
| if errobj.Message == "" { | ||
| errobj.Message = string(contentBytes) | ||
| } | ||
| return data, errobj |
There was a problem hiding this comment.
This error handling logic is duplicated across all the new snapshot-related functions (CreateTransportPolicySnapshot, UpdateTransportPolicySnapshot, GetTransportPolicySnapshots, GetTransportPolicySnapshot, DeleteTransportPolicySnapshot). To improve maintainability and reduce code duplication, consider extracting this logic into a private helper method on MSDClient.
For example, you could create a helper like this:
func (client MSDClient) unmarshalError(resp *http.Response) error {
contentBytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
var errobj rdl.ResourceError
_ = json.Unmarshal(contentBytes, &errobj) // Error ignored intentionally to handle non-JSON error bodies
if errobj.Code == 0 {
errobj.Code = resp.StatusCode
}
if errobj.Message == "" {
errobj.Message = string(contentBytes)
}
return errobj
}Then you can simplify the default case in each function, for example:
default:
return data, client.unmarshalError(resp)(Adjusting the return values as needed for functions with different signatures).
There was a problem hiding this comment.
autogenerated code
| .exception("BAD_REQUEST", "ResourceError", "") | ||
|
|
||
| .exception("CONFLICT", "ResourceError", "") | ||
|
|
||
| .exception("FORBIDDEN", "ResourceError", "") | ||
|
|
||
| .exception("NOT_FOUND", "ResourceError", "") | ||
|
|
||
| .exception("TOO_MANY_REQUESTS", "ResourceError", "") | ||
|
|
||
| .exception("UNAUTHORIZED", "ResourceError", "") | ||
| ; |
There was a problem hiding this comment.
These extra blank lines between the .exception() calls are inconsistent with the formatting of other resource definitions in this file (e.g., postKubernetesNetworkPolicyRequest). Please remove them here and in the other new resource definitions (updateTransportPolicySnapshot, getTransportPolicySnapshots, getTransportPolicySnapshot, deleteTransportPolicySnapshot) to maintain a consistent style.
.exception("BAD_REQUEST", "ResourceError", "")
.exception("CONFLICT", "ResourceError", "")
.exception("FORBIDDEN", "ResourceError", "")
.exception("NOT_FOUND", "ResourceError", "")
.exception("TOO_MANY_REQUESTS", "ResourceError", "")
.exception("UNAUTHORIZED", "ResourceError", "");
core/msd/src/test/java/com/yahoo/athenz/msd/TransportPolicySnapshotUpdateRequestTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Sasi Palaka <palakas@yahooinc.com>
Description
Introducing a Snapshot api to take a named snapshot of the TransportPolicy at a given time.
Contribution Checklist:
Attach Screenshots (Optional)