-
Notifications
You must be signed in to change notification settings - Fork 759
feat(storage): refactor audit and notification with OperationHelper #825
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
Conversation
This commit introduces a significant refactoring of the audit logging and event notification mechanisms within `ecfs.rs`. The core of this change is the new `OperationHelper` struct, which encapsulates and simplifies the logic for both concerns. It replaces the previous `AuditHelper` and manual event dispatching. Key improvements include: - **Unified Handling**: `OperationHelper` manages both audit and notification builders, providing a single, consistent entry point for S3 operations. - **RAII for Automation**: By leveraging the `Drop` trait, the helper automatically dispatches logs and notifications when it goes out of scope. This simplifies S3 method implementations and ensures cleanup even on early returns. - **Fluent API**: A builder-like pattern with methods such as `.object()`, `.version_id()`, and `.suppress_event()` makes the code more readable and expressive. - **Context-Aware Logic**: The helper's `.complete()` method intelligently populates log details based on the operation's `S3Result` and only triggers notifications on success. - **Modular Design**: All helper logic is now isolated in `rustfs/src/storage/helper.rs`, improving separation of concerns and making `ecfs.rs` cleaner. This refactoring significantly enhances code clarity, reduces boilerplate, and improves the robustness of logging and notification handling across the storage layer.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a unified helper structure to streamline audit logging and event notification for S3 operations, replacing the previous ad-hoc approach with a RAII-based pattern. It also refactors the notification and audit systems to use builder patterns and improves error handling.
- Introduces
OperationHelperfor centralized audit and event management via RAII - Refactors notification system from instance-based to module-based API
- Replaces manual audit/event creation with builder patterns throughout
- Removes dependencies on
scopeguardandonce_celllibraries
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| rustfs/src/storage/mod.rs | Adds the new helper module to the storage module exports |
| rustfs/src/storage/helper.rs | Implements the new OperationHelper RAII pattern for unified audit and event handling |
| rustfs/src/storage/ecfs.rs | Integrates OperationHelper into S3 operations, replacing manual audit/event code |
| crates/notify/src/lib.rs | Updates exports to expose builder and refactored global API |
| crates/notify/src/global.rs | Refactors from instance-based to module-based API (notifier_global) |
| crates/notify/src/event.rs | Adds EventArgsBuilder for fluent event construction |
| crates/notify/src/error.rs | Introduces LifecycleError enum for better error categorization |
| crates/notify/Cargo.toml | Removes once_cell dependency |
| crates/audit/src/registry.rs | Updates error variants to use new error types |
| crates/audit/src/lib.rs | Removes unused LogRecord from public exports |
| crates/audit/src/global.rs | Adds macro for cleaner system operations and improves comments |
| crates/audit/src/error.rs | Refactors error types with better source error handling |
| crates/audit/src/entity.rs | Replaces setter methods with builder pattern and changes time serialization |
| rustfs/Cargo.toml | Removes scopeguard dependency |
| Cargo.toml | Removes scopeguard from workspace dependencies |
| Cargo.lock | Updates lock file to reflect dependency removals |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 19 out of 20 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 23 out of 24 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Type of Change
Related Issues
Summary of Changes
Summary
This PR introduces a comprehensive refactoring of the audit logging and event notification systems within the
ecfs.rsstorage implementation. The primary goal is to enhance code quality, reduce redundancy, and improve maintainability by centralizing common logic into a new, unifiedOperationHelper.Key Changes
Introduced
OperationHelper:OperationHelperstruct has been created in its own module (rustfs/src/storage/helper.rs).AuditEntryBuilderfor audit logs and theEventArgsBuilderfor event notifications.Dropimplementation automatically dispatches logs and (on success) notifications, simplifying the end of every S3 operation method.Refactored
ecfs.rs:AuditHelperand manualtokio::spawncalls fornotifier_global::notifywith the newOperationHelper.put_object,create_bucket, anddelete_objectare now cleaner and more focused on their core logic.helper.object(info).version_id(id)).Enhanced
delete_objectsLogic:delete_objects, which requires multiple event notifications per API call, theOperationHelperis now used with a newsuppress_event()method.delete_objectsfunction manage the manual, per-object event notifications. This maintains a clear separation of responsibilities.Improved
notifyCrate API:notifycrate was improved by replacing the statelessNotifierstruct with a directnotifier_globalmodule, simplifying the public API.EventArgsBuilderwas enhanced with a full set of builder methods, making event creation safer and more readable.LifecycleErrorenum.Benefits
?operator).OperationHelper) instead of across dozens of methods.Verification
All existing unit and integration tests pass. The following commands were run successfully:
cargo fmt --all --checkcargo clippy --all-targets --all-features -- -D warningscargo test --workspace --exclude e2e_testThis refactoring lays a solid foundation for more maintainable and robust S3 operation implementations.
Checklist
make pre-commitImpact
Additional Notes
Thank you for your contribution! Please ensure your PR follows the community standards (CODE_OF_CONDUCT.md) and sign the CLA if this is your first contribution.