[ISSUE #4634] 🚀Add InvocationStatus enum for metrics tracking#4635
[ISSUE #4634] 🚀Add InvocationStatus enum for metrics tracking#4635rocketmq-rust-bot merged 1 commit intomainfrom
Conversation
|
🔊@mxsm 🚀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💥. |
WalkthroughIntroduces a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR introduces an InvocationStatus enum for tracking the success or failure status of operations in the broker's metrics system. This addresses issue #4634 by providing a reusable type for metrics invocation status tracking.
- Added new
InvocationStatusenum withSuccessandFailurevariants - Implemented
Displaytrait and serialization support - Added basic unit tests for the enum
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| rocketmq-broker/src/metrics/invocation_status.rs | New file defining the InvocationStatus enum with Success and Failure variants, including string conversion methods and basic tests |
| rocketmq-broker/src/metrics.rs | Added module declaration for invocation_status to expose the new enum |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| impl InvocationStatus { | ||
| /// Get the name of the invocation status | ||
| pub fn get_name(&self) -> &'static str { |
There was a problem hiding this comment.
The method name get_name is inconsistent with similar enums in this codebase. Other metrics enums like PopReviveMessageType (line 37 in pop_revive_message_type.rs) and enums in pop_metrics_constant.rs (lines 209, 243) use as_str as the method name. For consistency across the metrics module, this method should be renamed to as_str.
| /// Invocation status for metrics tracking | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
| pub enum InvocationStatus { | ||
| Success, | ||
| Failure, | ||
| } | ||
|
|
||
| impl InvocationStatus { | ||
| /// Get the name of the invocation status |
There was a problem hiding this comment.
The enum lacks comprehensive documentation. Comparing to similar enums in this codebase (e.g., PopReviveMessageType in pop_revive_message_type.rs lines 19-27), you should add:
- Documentation for each enum variant explaining what Success and Failure represent
- Documentation for the
get_namemethod (oras_strif renamed) explaining its purpose and return values, similar to lines 29-36 in pop_revive_message_type.rs
| /// Invocation status for metrics tracking | |
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] | |
| pub enum InvocationStatus { | |
| Success, | |
| Failure, | |
| } | |
| impl InvocationStatus { | |
| /// Get the name of the invocation status | |
| /// Invocation status for metrics tracking. | |
| /// | |
| /// Represents the result of an invocation, used for metrics collection. | |
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] | |
| pub enum InvocationStatus { | |
| /// Indicates that the invocation was successful and completed without errors. | |
| Success, | |
| /// Indicates that the invocation failed due to an error or unexpected condition. | |
| Failure, | |
| } | |
| impl InvocationStatus { | |
| /// Returns the string representation of the invocation status. | |
| /// | |
| /// This method is used to obtain a lowercase string corresponding to the | |
| /// status variant, which can be used for metrics labeling, logging, or serialization. | |
| /// | |
| /// # Returns | |
| /// | |
| /// * `"success"` if the status is [`InvocationStatus::Success`] | |
| /// * `"failure"` if the status is [`InvocationStatus::Failure`] |
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_invocation_status_name() { | ||
| assert_eq!(InvocationStatus::Success.get_name(), "success"); | ||
| assert_eq!(InvocationStatus::Failure.get_name(), "failure"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_invocation_status_display() { | ||
| assert_eq!(format!("{}", InvocationStatus::Success), "success"); | ||
| assert_eq!(format!("{}", InvocationStatus::Failure), "failure"); | ||
| } |
There was a problem hiding this comment.
The test coverage is incomplete compared to similar enums in the codebase. Looking at PopReviveMessageType tests (lines 62-76 in pop_revive_message_type.rs), you should add tests for:
- Enum variants being distinct and comparable (similar to
enum_variants_are_distinct_and_comparable) - Testing that the return value is static and can be used as a key in collections like HashMap (similar to
as_str_output_is_static_and_can_be_used_as_key)
These tests ensure the enum can be properly used in metrics tracking scenarios.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
rocketmq-broker/src/metrics/invocation_status.rs (1)
30-38: Consider using a trait or making this private.The
get_name()method is public but returns the same value as theDisplayimplementation. Having both public may be redundant unless there's a specific reason to expose the name accessor separately.If
get_name()is only needed internally forDisplay, consider making it private:- pub fn get_name(&self) -> &'static str { + fn get_name(&self) -> &'static str {Alternatively, if external code needs structured access to names, this is fine as-is.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
rocketmq-broker/src/metrics.rs(1 hunks)rocketmq-broker/src/metrics/invocation_status.rs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Upload results
- GitHub Check: auto-approve
🔇 Additional comments (3)
rocketmq-broker/src/metrics/invocation_status.rs (2)
23-28: Well-structured enum definition.The enum is cleanly defined with appropriate derives for metrics tracking. The combination of
Copy,Hash, and serde traits makes it suitable for use as a metrics label or tag.
40-44: Clean Display implementation.The Display trait delegates to
get_name()for consistency, which is a good pattern.rocketmq-broker/src/metrics.rs (1)
20-20: Module declaration follows existing patterns.The
pub(crate)visibility correctly restricts theInvocationStatusenum to crate-internal use, which is appropriate for metrics infrastructure.
| #[test] | ||
| fn test_invocation_status_name() { | ||
| assert_eq!(InvocationStatus::Success.get_name(), "success"); | ||
| assert_eq!(InvocationStatus::Failure.get_name(), "failure"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_invocation_status_display() { | ||
| assert_eq!(format!("{}", InvocationStatus::Success), "success"); | ||
| assert_eq!(format!("{}", InvocationStatus::Failure), "failure"); | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Find usage of InvocationStatus enum across the codebase
# Search for InvocationStatus references (excluding the definition file)
rg -n --type rust -C3 'InvocationStatus' -g '!invocation_status.rs'Repository: mxsm/rocketmq-rust
Length of output: 1273
InvocationStatus enum is not actually used in the metrics system.
The search reveals only a commented-out TODO in subscription_group_handler.rs (lines 81-86) that shows where this enum should be used, but it is never integrated into active code. This enum definition and its tests exist without any real integration into metrics collection, making them unused code.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4635 +/- ##
==========================================
+ Coverage 31.02% 31.04% +0.01%
==========================================
Files 679 680 +1
Lines 99832 99848 +16
==========================================
+ Hits 30977 30993 +16
Misses 68855 68855 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rocketmq-rust-bot
left a comment
There was a problem hiding this comment.
LGTM - All CI checks passed ✅
Which Issue(s) This PR Fixes(Closes)
Fixes #4634
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.