Skip to content

Conversation

@houseme
Copy link
Contributor

@houseme houseme commented Nov 9, 2025

Type of Change

  • New Feature
  • Bug Fix
  • Documentation
  • Performance Improvement
  • Test/CI
  • Refactor
  • Other:

Related Issues

Summary of Changes

Summary

This PR introduces a comprehensive refactoring of the audit logging and event notification systems within the ecfs.rs storage implementation. The primary goal is to enhance code quality, reduce redundancy, and improve maintainability by centralizing common logic into a new, unified OperationHelper.

Key Changes

  1. Introduced OperationHelper:

    • A new OperationHelper struct has been created in its own module (rustfs/src/storage/helper.rs).
    • This helper now manages both the AuditEntryBuilder for audit logs and the EventArgsBuilder for event notifications.
    • It leverages the RAII pattern: its Drop implementation automatically dispatches logs and (on success) notifications, simplifying the end of every S3 operation method.
  2. Refactored ecfs.rs:

    • Replaced all instances of the old AuditHelper and manual tokio::spawn calls for notifier_global::notify with the new OperationHelper.
    • S3 methods like put_object, create_bucket, and delete_object are now cleaner and more focused on their core logic.
    • The construction of audit and event data is now more expressive, using a fluent, chainable API (e.g., helper.object(info).version_id(id)).
  3. Enhanced delete_objects Logic:

    • For the special case of delete_objects, which requires multiple event notifications per API call, the OperationHelper is now used with a new suppress_event() method.
    • This allows the helper to handle the single audit log for the entire operation while letting the delete_objects function manage the manual, per-object event notifications. This maintains a clear separation of responsibilities.
  4. Improved notify Crate API:

    • The notify crate was improved by replacing the stateless Notifier struct with a direct notifier_global module, simplifying the public API.
    • EventArgsBuilder was enhanced with a full set of builder methods, making event creation safer and more readable.
    • Error handling was made more granular with the introduction of a LifecycleError enum.

Benefits

  • Reduced Boilerplate: Eliminates repetitive code for building and dispatching logs/events at the end of each S3 function.
  • Increased Robustness: The RAII pattern ensures that logging and notifications are handled correctly, even in functions with multiple return paths (e.g., using the ? operator).
  • Improved Readability: S3 operation logic is now cleaner and easier to follow, as the cross-cutting concerns of auditing and notifying are abstracted away.
  • Better Maintainability: Future changes to logging or notification logic can be made in one central place (OperationHelper) instead of across dozens of methods.

Verification

All existing unit and integration tests pass. The following commands were run successfully:

  • cargo fmt --all --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --workspace --exclude e2e_test

This refactoring lays a solid foundation for more maintainable and robust S3 operation implementations.

Checklist

  • I have read and followed the CONTRIBUTING.md guidelines
  • Passed make pre-commit
  • Added/updated necessary tests
  • Documentation updated (if needed)
  • CI/CD passed (if applicable)

Impact

  • Breaking change (compatibility)
  • Requires doc/config/deployment update
  • Other impact:

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.

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.
@houseme houseme requested a review from Copilot November 9, 2025 18:54
@github-actions
Copy link

github-actions bot commented Nov 9, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails
cargo/bytesize 2.2.0 UnknownUnknown
cargo/pulldown-cmark-to-cmark 21.1.0 🟢 4
Details
CheckScoreReason
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Maintained⚠️ 22 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Binary-Artifacts🟢 10no binaries found in the repo
Code-Review🟢 4Found 8/18 approved changesets -- score normalized to 4
Packaging⚠️ -1packaging workflow not detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy⚠️ 0security policy file not detected
Vulnerabilities🟢 100 existing vulnerabilities detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
cargo/syn 2.0.110 🟢 6.4
Details
CheckScoreReason
Maintained🟢 1030 commit(s) and 22 issue activity found in the last 90 days -- score normalized to 10
Code-Review🟢 3Found 6/19 approved changesets -- score normalized to 3
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Vulnerabilities🟢 100 existing vulnerabilities detected
License🟢 10license file detected
Fuzzing🟢 10project is fuzzed
Signed-Releases⚠️ -1no releases found
Security-Policy🟢 3security policy file detected
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0

Scanned Files

  • Cargo.lock

Copy link
Contributor

Copilot AI left a 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 OperationHelper for 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 scopeguard and once_cell libraries

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.

@houseme houseme requested a review from Copilot November 9, 2025 19:42
Copy link
Contributor

Copilot AI left a 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.

@houseme houseme requested a review from Copilot November 10, 2025 07:57
Copy link
Contributor

Copilot AI left a 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.

@houseme houseme merged commit 98be7df into main Nov 10, 2025
16 checks passed
@houseme houseme deleted the feature/improve-audit-1109 branch November 10, 2025 09:30
houseme added a commit that referenced this pull request Nov 11, 2025
…ypto

* 'main' of github.com:rustfs/rustfs:
  wip (#830)
  fix list object err (#831)
  fix (#828)
  feat(storage): refactor audit and notification with OperationHelper (#825)

# Conflicts:
#	Cargo.toml
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.

1 participant