Skip to content
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

[ISSUE #1372]🚀Add ClusterAclVersionInfo #1373

Merged
merged 1 commit into from
Nov 27, 2024
Merged

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Nov 27, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1372

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced a new module for ClusterAclVersionInfo, enabling better management of cluster access control version information.
    • Added a struct with fields for broker details and ACL configuration, facilitating easier JSON serialization and deserialization.
  • Tests

    • Implemented unit tests to ensure the correct functionality of the ClusterAclVersionInfo struct, including serialization and deserialization checks.

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Walkthrough

The changes introduce a new public module cluster_acl_version_info in the rocketmq-remoting/src/protocol/body.rs file. Additionally, a new Rust file cluster_acl_version_info.rs is created, which defines the ClusterAclVersionInfo struct with serialization and deserialization capabilities. This struct includes five fields, with one field marked as deprecated, and is accompanied by a comprehensive test module to validate its functionality.

Changes

File Path Change Summary
rocketmq-remoting/src/protocol/body.rs Added module declaration: pub mod cluster_acl_version_info;
rocketmq-remoting/src/protocol/body/cluster_acl_version_info.rs Introduced ClusterAclVersionInfo struct with fields and serialization traits, including unit tests.

Assessment against linked issues

Objective Addressed Explanation
Add ClusterAclVersionInfo struct (1372)

Possibly related PRs

Suggested labels

feature, rust, auto merge, ready to review, waiting-review, AI review first

Suggested reviewers

  • SpaceXCN
  • TeslaRustor

Poem

In the code where rabbits play,
A new struct hops in today.
With fields so bright, it takes its stand,
ClusterAclVersionInfo, oh so grand!
Tests to ensure it’s all just right,
A leap of joy in the coding night! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥

@rocketmq-rust-robot rocketmq-rust-robot added this to the v0.4.0 milestone Nov 27, 2024
@rocketmq-rust-robot rocketmq-rust-robot added the feature🚀 Suggest an idea for this project. label Nov 27, 2024
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 21.40%. Comparing base (4c65b77) to head (59976cd).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1373      +/-   ##
==========================================
+ Coverage   21.21%   21.40%   +0.18%     
==========================================
  Files         435      436       +1     
  Lines       55337    55470     +133     
==========================================
+ Hits        11741    11874     +133     
  Misses      43596    43596              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (1)
rocketmq-remoting/src/protocol/body/cluster_acl_version_info.rs (1)

36-190: Add missing test cases for better coverage.

The test suite should be enhanced with additional test cases:

  1. Validation of empty/null broker_name or broker_addr
  2. Error handling for invalid JSON deserialization
  3. Edge cases for all_acl_config_data_version map

Here's an example test to add:

#[test]
fn deserialize_invalid_json() {
    let invalid_json = r#"{
        "brokerName": null,
        "brokerAddr": "addr1",
        "aclConfigDataVersion": null,
        "allAclConfigDataVersion": {},
        "clusterName": "cluster1"
    }"#;
    let result: Result<ClusterAclVersionInfo, _> = serde_json::from_str(invalid_json);
    assert!(result.is_err());
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4c65b77 and 59976cd.

📒 Files selected for processing (2)
  • rocketmq-remoting/src/protocol/body.rs (1 hunks)
  • rocketmq-remoting/src/protocol/body/cluster_acl_version_info.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • rocketmq-remoting/src/protocol/body.rs
🔇 Additional comments (1)
rocketmq-remoting/src/protocol/body/cluster_acl_version_info.rs (1)

1-190: Verify integration with ACL functionality.

As this is a new struct for ACL version information, we should verify its integration with existing ACL-related code.

Comment on lines +25 to +34
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ClusterAclVersionInfo {
pub broker_name: CheetahString,
pub broker_addr: CheetahString,
//Deprecated
pub acl_config_data_version: Option<DataVersion>,
pub all_acl_config_data_version: HashMap<CheetahString, DataVersion>,
pub cluster_name: CheetahString,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add documentation and proper deprecation handling.

The struct definition needs the following improvements:

  1. Add struct-level documentation explaining its purpose and usage
  2. Document each field's purpose and constraints
  3. Properly mark the deprecated field with the #[deprecated] attribute and document the alternative approach

Apply this diff:

 #[derive(Serialize, Deserialize, Debug)]
 #[serde(rename_all = "camelCase")]
+/// Represents ACL version information for a broker in the cluster.
+/// This struct is used to track and manage ACL configuration versions across different brokers.
 pub struct ClusterAclVersionInfo {
+    /// Name of the broker
     pub broker_name: CheetahString,
+    /// Address of the broker
     pub broker_addr: CheetahString,
-    //Deprecated
+    /// Deprecated: Use all_acl_config_data_version instead.
+    #[deprecated(since = "1.0.0", note = "Use all_acl_config_data_version instead")]
     pub acl_config_data_version: Option<DataVersion>,
+    /// Map of ACL configuration versions for different components
     pub all_acl_config_data_version: HashMap<CheetahString, DataVersion>,
+    /// Name of the cluster this broker belongs to
     pub cluster_name: CheetahString,
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ClusterAclVersionInfo {
pub broker_name: CheetahString,
pub broker_addr: CheetahString,
//Deprecated
pub acl_config_data_version: Option<DataVersion>,
pub all_acl_config_data_version: HashMap<CheetahString, DataVersion>,
pub cluster_name: CheetahString,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
/// Represents ACL version information for a broker in the cluster.
/// This struct is used to track and manage ACL configuration versions across different brokers.
pub struct ClusterAclVersionInfo {
/// Name of the broker
pub broker_name: CheetahString,
/// Address of the broker
pub broker_addr: CheetahString,
/// Deprecated: Use all_acl_config_data_version instead.
#[deprecated(since = "1.0.0", note = "Use all_acl_config_data_version instead")]
pub acl_config_data_version: Option<DataVersion>,
/// Map of ACL configuration versions for different components
pub all_acl_config_data_version: HashMap<CheetahString, DataVersion>,
/// Name of the cluster this broker belongs to
pub cluster_name: CheetahString,
}

Comment on lines +85 to +102
#[test]
fn cluster_acl_version_info_inequality() {
let info1 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: HashMap::new(),
cluster_name: CheetahString::from("cluster1"),
};

let info2 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker2"),
broker_addr: CheetahString::from("addr2"),
acl_config_data_version: None,
all_acl_config_data_version: HashMap::new(),
cluster_name: CheetahString::from("cluster2"),
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incomplete inequality test.

The inequality test creates two different instances but doesn't assert their inequality.

Add assertions to complete the test:

     let info2 = ClusterAclVersionInfo {
         broker_name: CheetahString::from("broker2"),
         broker_addr: CheetahString::from("addr2"),
         acl_config_data_version: None,
         all_acl_config_data_version: HashMap::new(),
         cluster_name: CheetahString::from("cluster2"),
     };
+    // Assert inequality for all fields
+    assert_ne!(info1.broker_name, info2.broker_name);
+    assert_ne!(info1.broker_addr, info2.broker_addr);
+    assert_ne!(info1.acl_config_data_version, info2.acl_config_data_version);
+    assert_eq!(info1.all_acl_config_data_version, info2.all_acl_config_data_version);
+    assert_ne!(info1.cluster_name, info2.cluster_name);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
fn cluster_acl_version_info_inequality() {
let info1 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: HashMap::new(),
cluster_name: CheetahString::from("cluster1"),
};
let info2 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker2"),
broker_addr: CheetahString::from("addr2"),
acl_config_data_version: None,
all_acl_config_data_version: HashMap::new(),
cluster_name: CheetahString::from("cluster2"),
};
}
#[test]
fn cluster_acl_version_info_inequality() {
let info1 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: HashMap::new(),
cluster_name: CheetahString::from("cluster1"),
};
let info2 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker2"),
broker_addr: CheetahString::from("addr2"),
acl_config_data_version: None,
all_acl_config_data_version: HashMap::new(),
cluster_name: CheetahString::from("cluster2"),
};
// Assert inequality for all fields
assert_ne!(info1.broker_name, info2.broker_name);
assert_ne!(info1.broker_addr, info2.broker_addr);
assert_ne!(info1.acl_config_data_version, info2.acl_config_data_version);
assert_eq!(info1.all_acl_config_data_version, info2.all_acl_config_data_version);
assert_ne!(info1.cluster_name, info2.cluster_name);
}

Comment on lines +63 to +83
#[test]
fn cluster_acl_version_info_equality() {
let mut all_acl_config_data_version = HashMap::new();
all_acl_config_data_version.insert(CheetahString::from("key1"), DataVersion::default());

let info1 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: all_acl_config_data_version.clone(),
cluster_name: CheetahString::from("cluster1"),
};

let info2 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: all_acl_config_data_version,
cluster_name: CheetahString::from("cluster1"),
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incomplete equality test.

The equality test creates two identical instances but doesn't assert their equality.

Add assertion to complete the test:

     let info2 = ClusterAclVersionInfo {
         broker_name: CheetahString::from("broker1"),
         broker_addr: CheetahString::from("addr1"),
         acl_config_data_version: Some(DataVersion::default()),
         all_acl_config_data_version: all_acl_config_data_version,
         cluster_name: CheetahString::from("cluster1"),
     };
+    // Assert equality for all fields
+    assert_eq!(info1.broker_name, info2.broker_name);
+    assert_eq!(info1.broker_addr, info2.broker_addr);
+    assert_eq!(info1.acl_config_data_version, info2.acl_config_data_version);
+    assert_eq!(info1.all_acl_config_data_version, info2.all_acl_config_data_version);
+    assert_eq!(info1.cluster_name, info2.cluster_name);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
fn cluster_acl_version_info_equality() {
let mut all_acl_config_data_version = HashMap::new();
all_acl_config_data_version.insert(CheetahString::from("key1"), DataVersion::default());
let info1 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: all_acl_config_data_version.clone(),
cluster_name: CheetahString::from("cluster1"),
};
let info2 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: all_acl_config_data_version,
cluster_name: CheetahString::from("cluster1"),
};
}
#[test]
fn cluster_acl_version_info_equality() {
let mut all_acl_config_data_version = HashMap::new();
all_acl_config_data_version.insert(CheetahString::from("key1"), DataVersion::default());
let info1 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: all_acl_config_data_version.clone(),
cluster_name: CheetahString::from("cluster1"),
};
let info2 = ClusterAclVersionInfo {
broker_name: CheetahString::from("broker1"),
broker_addr: CheetahString::from("addr1"),
acl_config_data_version: Some(DataVersion::default()),
all_acl_config_data_version: all_acl_config_data_version,
cluster_name: CheetahString::from("cluster1"),
};
// Assert equality for all fields
assert_eq!(info1.broker_name, info2.broker_name);
assert_eq!(info1.broker_addr, info2.broker_addr);
assert_eq!(info1.acl_config_data_version, info2.acl_config_data_version);
assert_eq!(info1.all_acl_config_data_version, info2.all_acl_config_data_version);
assert_eq!(info1.cluster_name, info2.cluster_name);
}

@rocketmq-rust-bot rocketmq-rust-bot merged commit 32f437e into main Nov 27, 2024
25 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Nov 27, 2024
@mxsm mxsm deleted the feature-1372 branch November 27, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI review first Ai review pr first approved PR has approved auto merge feature🚀 Suggest an idea for this project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature🚀] Add ClusterAclVersionInfo
4 participants