Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ISSUE #1379] Add ConsumeStatsList #2422

Merged
merged 4 commits into from
Jan 28, 2025
Merged

[ISSUE #1379] Add ConsumeStatsList #2422

merged 4 commits into from
Jan 28, 2025

Conversation

yuz10
Copy link
Contributor

@yuz10 yuz10 commented Jan 28, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #1379

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Added new modules for consumption statistics management in the RocketMQ remoting protocol.
    • Introduced ConsumeStatsList and ConsumeStatus structs for tracking message consumption metrics.
    • Enhanced data serialization and deserialization capabilities for consumption-related data.
  • Improvements

    • Updated visibility of ConsumeStats struct fields to improve accessibility.

Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request introduces new modules and structs in the RocketMQ remoting protocol, focusing on consumption statistics management. The changes include adding a new ConsumeStatsList struct in consume_stats_list.rs, modifying visibility of fields in ConsumeStats, introducing a ConsumeStatus struct, and updating module declarations in admin.rs and body.rs. These modifications enhance the serialization and data representation capabilities for consumption-related statistics in the RocketMQ Rust implementation.

Changes

File Change Summary
rocketmq-remoting/src/protocol/admin.rs Added new public module consume_stats_list
rocketmq-remoting/src/protocol/admin/consume_stats.rs Made offset_table and consume_tps fields public in ConsumeStats struct
rocketmq-remoting/src/protocol/admin/consume_stats_list.rs New ConsumeStatsList struct with serialization support
rocketmq-remoting/src/protocol/body.rs Added new public module consume_status
rocketmq-remoting/src/protocol/body/consume_status.rs New ConsumeStatus struct with serialization support

Assessment against linked issues

Objective Addressed Explanation
Convert ConsumeStatsList Java class to Rust struct [#1379]

Possibly related PRs

Suggested labels

approved

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🚀 Rabbit's Consumption Tale 🐰

In RocketMQ's Rust domain so bright,
Stats and structs now take their flight
Consuming messages with grace and might
Our code grows stronger, data shines light!

Hop hop hooray! 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a031685 and 1e2b7ca.

📒 Files selected for processing (2)
  • rocketmq-remoting/src/protocol/admin/consume_stats_list.rs (1 hunks)
  • rocketmq-remoting/src/protocol/body/consume_status.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • rocketmq-remoting/src/protocol/body/consume_status.rs
  • rocketmq-remoting/src/protocol/admin/consume_stats_list.rs
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: auto-approve
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: test
  • GitHub Check: build (ubuntu-latest, stable)
  • GitHub Check: build

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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-robot rocketmq-rust-robot added this to the v0.4.0 milestone Jan 28, 2025
@rocketmq-rust-robot rocketmq-rust-robot added the feature🚀 Suggest an idea for this project. label Jan 28, 2025
@rocketmq-rust-bot
Copy link
Collaborator

🔊@yuz10 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 28.65%. Comparing base (fb5227f) to head (1e2b7ca).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2422      +/-   ##
==========================================
+ Coverage   28.59%   28.65%   +0.05%     
==========================================
  Files         508      510       +2     
  Lines       73450    73505      +55     
==========================================
+ Hits        21005    21060      +55     
  Misses      52445    52445              

☔ 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: 0

🧹 Nitpick comments (4)
rocketmq-remoting/src/protocol/admin/consume_stats.rs (1)

30-31: Consider maintaining encapsulation with private fields.

The struct already provides public getters and setters for these fields. Making the fields public while maintaining getters/setters creates redundancy and weakens encapsulation. Consider:

  1. Keeping fields private and using the existing getters/setters, or
  2. Making fields public and removing the redundant getters/setters

If you choose option 1, apply this diff:

-    pub offset_table: HashMap<MessageQueue, OffsetWrapper>,
-    pub consume_tps: f64,
+    offset_table: HashMap<MessageQueue, OffsetWrapper>,
+    consume_tps: f64,
rocketmq-remoting/src/protocol/admin/consume_stats_list.rs (2)

25-38: Consider implementing Default trait.

For better ergonomics when creating new instances, consider implementing the Default trait for ConsumeStatsList.

-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Default)]
 pub struct ConsumeStatsList {
     #[serde(rename = "consume_stats_list")]
     pub consume_stats_list: Vec<HashMap<CheetahString, Vec<ConsumeStats>>>,
 
     #[serde(rename = "brokerAddr")]
     pub broker_addr: Option<CheetahString>,
 
     #[serde(rename = "total_diff")]
     pub total_diff: i64,
 
     #[serde(rename = "total_inflight_diff")]
     pub total_inflight_diff: i64,
 }
+
+impl ConsumeStatsList {
+    pub fn new() -> Self {
+        Self::default()
+    }
+}

46-73: Consider adding more test cases.

While the current test is good, consider adding tests for:

  1. Default instance creation
  2. Empty consume_stats_list
  3. Multiple groups in the HashMap
  4. None broker_addr
#[test]
fn test_default_instance() {
    let list = ConsumeStatsList::default();
    assert!(list.consume_stats_list.is_empty());
    assert!(list.broker_addr.is_none());
    assert_eq!(list.total_diff, 0);
    assert_eq!(list.total_inflight_diff, 0);
}

#[test]
fn test_multiple_groups() {
    let mut map = HashMap::new();
    map.insert(CheetahString::from("group1"), vec![ConsumeStats::default()]);
    map.insert(CheetahString::from("group2"), vec![ConsumeStats::default()]);
    let list = ConsumeStatsList {
        consume_stats_list: vec![map],
        broker_addr: None,
        total_diff: 0,
        total_inflight_diff: 0,
    };
    let serialized = serde_json::to_string(&list).unwrap();
    let deserialized: ConsumeStatsList = serde_json::from_str(&serialized).unwrap();
    assert_eq!(deserialized.consume_stats_list[0].len(), 2);
}
rocketmq-remoting/src/protocol/body/consume_status.rs (1)

41-78: Consider adding edge case tests.

While the current tests cover the basic scenarios, consider adding tests for edge cases:

  1. Zero values
  2. Negative values for failed messages
  3. Very large numbers
  4. Very small (close to zero) TPS values
#[test]
fn test_edge_cases() {
    let cases = vec![
        ConsumeStatus {
            pull_rt: 0.0,
            pull_tps: 0.0,
            consume_rt: 0.0,
            consume_ok_tps: 0.0,
            consume_failed_tps: 0.0,
            consume_failed_msgs: 0,
        },
        ConsumeStatus {
            pull_rt: 0.000001,
            pull_tps: 999999.9,
            consume_rt: f64::MAX,
            consume_ok_tps: f64::MIN_POSITIVE,
            consume_failed_tps: 0.0,
            consume_failed_msgs: i64::MAX,
        },
    ];
    
    for case in cases {
        let serialized = serde_json::to_string(&case).unwrap();
        let deserialized: ConsumeStatus = serde_json::from_str(&serialized).unwrap();
        assert_eq!(case.pull_rt, deserialized.pull_rt);
        assert_eq!(case.consume_failed_msgs, deserialized.consume_failed_msgs);
    }
}
🧰 Tools
🪛 GitHub Actions: CI

[error] 75-75: Code formatting error: Extra blank line detected that doesn't conform to rustfmt standards

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e6c826 and a031685.

📒 Files selected for processing (5)
  • rocketmq-remoting/src/protocol/admin.rs (1 hunks)
  • rocketmq-remoting/src/protocol/admin/consume_stats.rs (1 hunks)
  • rocketmq-remoting/src/protocol/admin/consume_stats_list.rs (1 hunks)
  • rocketmq-remoting/src/protocol/body.rs (1 hunks)
  • rocketmq-remoting/src/protocol/body/consume_status.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • rocketmq-remoting/src/protocol/admin.rs
🧰 Additional context used
🪛 GitHub Actions: CI
rocketmq-remoting/src/protocol/body/consume_status.rs

[error] 75-75: Code formatting error: Extra blank line detected that doesn't conform to rustfmt standards

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: auto-approve
🔇 Additional comments (2)
rocketmq-remoting/src/protocol/body.rs (1)

37-37: LGTM!

The new consume_status module is correctly placed in alphabetical order within the module declarations.

rocketmq-remoting/src/protocol/body/consume_status.rs (1)

75-75: ⚠️ Potential issue

Fix formatting: Remove extra blank line.

The CI pipeline indicates a formatting error. Remove the extra blank line to conform to rustfmt standards.

         assert_eq!(deserialized.consume_failed_tps, 1.5);
         assert_eq!(deserialized.consume_failed_msgs, 6);
     }
-

 }

Likely invalid or redundant comment.

🧰 Tools
🪛 GitHub Actions: CI

[error] 75-75: Code formatting error: Extra blank line detected that doesn't conform to rustfmt standards

@rocketmq-rust-bot
Copy link
Collaborator

🔊@yuz10 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Owner

@mxsm mxsm left a comment

Choose a reason for hiding this comment

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

LGTM

@mxsm mxsm added the approved PR has approved label Jan 28, 2025
@rocketmq-rust-bot rocketmq-rust-bot merged commit 840d3a6 into mxsm:main Jan 28, 2025
19 of 21 checks passed
# for free to join this conversation on GitHub. Already have an account? # 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 ConsumeStatsList
4 participants