feat(obs): add init_obs_with_config API and signature guard test (#2175)

Signed-off-by: houseme <housemecn@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
houseme
2026-03-16 18:17:55 +08:00
committed by GitHub
parent 06dff96c09
commit 94cdb89e29
18 changed files with 2597 additions and 325 deletions
+26 -6
View File
@@ -14,17 +14,32 @@
//! Log-file cleanup subsystem.
//!
//! This module provides [`LogCleaner`], a configurable manager that
//! periodically removes, compresses, or archives old rolling log files.
//! This module exposes the high-level [`LogCleaner`] API used by the
//! observability layer to manage rotated log files after they are no longer
//! active. The implementation is intentionally split into small focused
//! sub-modules so each concern can evolve independently without turning the
//! cleaner into a monolithic state machine.
//!
//! At a high level, one cleanup pass follows this lifecycle:
//!
//! 1. scan the target directory and classify matching entries;
//! 2. decide which regular log files exceed retention constraints;
//! 3. optionally compress those files using the configured codec;
//! 4. delete only files that are safe to remove;
//! 5. separately expire already-compressed archives by age.
//!
//! The design favors operational safety over aggressive reclamation:
//! compression and deletion are decoupled, symlinks are rejected on removal,
//! and dry-run mode reports intent without mutating the filesystem.
//!
//! ## Sub-modules
//!
//! | Module | Responsibility |
//! |-------------|----------------------------------------------------------|
//! | `types` | Shared data types (`FileInfo`) |
//! | `scanner` | Filesystem traversal — discovers eligible files |
//! | `compress` | Gzip compression helper |
//! | `core` | Core orchestration — selection, compression, deletion |
//! | `types` | Shared enums and metadata (`FileInfo`, match/compression choices) |
//! | `scanner` | Filesystem traversal, pattern matching, empty-file handling |
//! | `compress` | Archive creation helpers for gzip and zstd |
//! | `core` | Selection, parallel/serial processing, secure deletion |
//!
//! ## Usage
//!
@@ -60,6 +75,10 @@ mod core;
mod scanner;
pub mod types;
/// Primary entry point for the cleaner subsystem.
///
/// Re-exported from [`core`] so callers can construct a cleaner without
/// knowing the internal module layout.
pub use core::LogCleaner;
#[cfg(test)]
@@ -72,6 +91,7 @@ mod tests {
use std::path::Path;
use tempfile::TempDir;
/// Create a test log file with deterministic contents and size.
fn create_log_file(dir: &Path, name: &str, size: usize) -> std::io::Result<()> {
let path = dir.join(name);
let mut f = File::create(path)?;