Skip to content

Defining snapshop api for MSD#3210

Merged
havetisyan merged 1 commit intoAthenZ:masterfrom
psasidhar:msd-api
Mar 3, 2026
Merged

Defining snapshop api for MSD#3210
havetisyan merged 1 commit intoAthenZ:masterfrom
psasidhar:msd-api

Conversation

@psasidhar
Copy link
Copy Markdown
Contributor

Description

Introducing a Snapshot api to take a named snapshot of the TransportPolicy at a given time.

Contribution Checklist:

  • The pull request does not introduce any breaking changes
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Attach Screenshots (Optional)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 TransportPolicy configurations. This functionality provides a mechanism to capture the state of network policies at specific points in time, which is crucial for auditing, version control, and potential rollback scenarios. The changes encompass API definitions, client implementations for both Go and Java, and associated model and test classes.

Highlights

  • New Transport Policy Snapshot API: Introduced a comprehensive API for managing named snapshots of TransportPolicy configurations, including operations for creation, update, retrieval, listing, and deletion.
  • Go Client Implementation: Added new client methods in the Go MSD client to interact with the newly defined Transport Policy Snapshot API endpoints.
  • Java Client Implementation: Implemented new client methods in the Java MSD client to support the new Transport Policy Snapshot API, ensuring compatibility and functionality across client languages.
  • RDL Schema and Model Definitions: Defined new RDL types and resources for TransportPolicySnapshotRequest, TransportPolicySnapshotUpdateRequest, TransportPolicySnapshotMetadata, TransportPolicySnapshot, and TransportPolicySnapshots to formally describe the new API entities.
  • Java Model Classes and Tests: Generated corresponding Java model classes for the new snapshot types and added unit tests to ensure their correctness and proper serialization/deserialization.
Changelog
  • clients/go/msd/client.go
    • Added CreateTransportPolicySnapshot function to create a new policy snapshot.
    • Added UpdateTransportPolicySnapshot function to modify an existing policy snapshot.
    • Added GetTransportPolicySnapshots function to retrieve a list of policy snapshots.
    • Added GetTransportPolicySnapshot function to fetch a specific policy snapshot by name.
    • Added DeleteTransportPolicySnapshot function to remove a policy snapshot.
  • clients/go/msd/model.go
    • Defined TransportPolicySnapshotRequest struct for creating snapshots.
    • Defined TransportPolicySnapshotUpdateRequest struct for updating snapshots.
    • Defined TransportPolicySnapshotMetadata struct for snapshot metadata.
    • Defined TransportPolicySnapshot struct for full policy snapshot details.
    • Defined TransportPolicySnapshots struct for a list of snapshot metadata.
  • clients/go/msd/msd_schema.go
    • Added RDL type definitions for TransportPolicySnapshotRequest, TransportPolicySnapshotUpdateRequest, TransportPolicySnapshotMetadata, TransportPolicySnapshot, and TransportPolicySnapshots.
    • Added RDL resource definitions for createTransportPolicySnapshot, updateTransportPolicySnapshot, getTransportPolicySnapshots, getTransportPolicySnapshot, and deleteTransportPolicySnapshot.
  • clients/java/msd/src/main/java/com/yahoo/athenz/msd/MSDRDLGeneratedClient.java
    • Added createTransportPolicySnapshot method for creating snapshots.
    • Added updateTransportPolicySnapshot method for updating snapshots.
    • Added getTransportPolicySnapshots method for retrieving a list of snapshots.
    • Added getTransportPolicySnapshot method for fetching a specific snapshot.
    • Added deleteTransportPolicySnapshot method for deleting snapshots.
  • core/msd/src/main/java/com/yahoo/athenz/msd/MSDSchema.java
    • Added RDL schema definitions for TransportPolicySnapshotRequest, TransportPolicySnapshotUpdateRequest, TransportPolicySnapshotMetadata, TransportPolicySnapshot, and TransportPolicySnapshots.
    • Added RDL resource definitions for snapshot API endpoints.
  • core/msd/src/main/java/com/yahoo/athenz/msd/TransportPolicySnapshot.java
    • Added new Java class TransportPolicySnapshot with fields for domain, service, name, timestamps, active status, and transport policy rules.
  • core/msd/src/main/java/com/yahoo/athenz/msd/TransportPolicySnapshotMetadata.java
    • Added new Java class TransportPolicySnapshotMetadata with fields for domain, service, name, timestamps, and active status.
  • core/msd/src/main/java/com/yahoo/athenz/msd/TransportPolicySnapshotRequest.java
    • Added new Java class TransportPolicySnapshotRequest with fields for name and active status.
  • core/msd/src/main/java/com/yahoo/athenz/msd/TransportPolicySnapshotUpdateRequest.java
    • Added new Java class TransportPolicySnapshotUpdateRequest with a field for active status.
  • core/msd/src/main/java/com/yahoo/athenz/msd/TransportPolicySnapshots.java
    • Added new Java class TransportPolicySnapshots containing a list of TransportPolicySnapshotMetadata.
  • core/msd/src/main/rdl/MSD.rdl
    • Included the new Snapshot.rdli file to incorporate snapshot definitions.
  • core/msd/src/main/rdl/Snapshot.rdli
    • Defined RDL resources for createTransportPolicySnapshot, updateTransportPolicySnapshot, getTransportPolicySnapshots, getTransportPolicySnapshot, and deleteTransportPolicySnapshot.
  • core/msd/src/main/rdl/Snapshot.tdl
    • Defined RDL types for TransportPolicySnapshotRequest, TransportPolicySnapshotUpdateRequest, TransportPolicySnapshotMetadata, TransportPolicySnapshot, and TransportPolicySnapshots.
  • core/msd/src/test/java/com/yahoo/athenz/msd/TransportPolicySnapshotMetadataTest.java
    • Added unit tests for the TransportPolicySnapshotMetadata class, covering field assignments, equality, and null handling.
  • core/msd/src/test/java/com/yahoo/athenz/msd/TransportPolicySnapshotRequestTest.java
    • Added unit tests for the TransportPolicySnapshotRequest class, covering field assignments, equality, and active status toggling.
  • core/msd/src/test/java/com/yahoo/athenz/msd/TransportPolicySnapshotTest.java
    • Added unit tests for the TransportPolicySnapshot class, covering field assignments, equality, and null handling.
  • core/msd/src/test/java/com/yahoo/athenz/msd/TransportPolicySnapshotUpdateRequestTest.java
    • Added unit tests for the TransportPolicySnapshotUpdateRequest class, covering field assignments, equality, and active status toggling.
  • core/msd/src/test/java/com/yahoo/athenz/msd/TransportPolicySnapshotsTest.java
    • Added unit tests for the TransportPolicySnapshots class, covering list manipulation and equality.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1128 to +1140
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autogenerated code

Comment on lines +1091 to +1102
.exception("BAD_REQUEST", "ResourceError", "")

.exception("CONFLICT", "ResourceError", "")

.exception("FORBIDDEN", "ResourceError", "")

.exception("NOT_FOUND", "ResourceError", "")

.exception("TOO_MANY_REQUESTS", "ResourceError", "")

.exception("UNAUTHORIZED", "ResourceError", "")
;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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", "");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autogenerated

Signed-off-by: Sasi Palaka <palakas@yahooinc.com>
Copy link
Copy Markdown
Contributor

@yosrixp yosrixp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@havetisyan havetisyan merged commit f0fc13d into AthenZ:master Mar 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants