mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 08:36:54 +00:00
refactor(logging): unify governance runtime events (#3367)
This commit is contained in:
@@ -29,6 +29,9 @@ use tokio::sync::RwLock;
|
||||
use tracing::info;
|
||||
|
||||
const RUSTFS_AUDIT_METRICS_NAMESPACE: &str = "rustfs.audit.";
|
||||
const LOG_COMPONENT_AUDIT: &str = "audit";
|
||||
const LOG_SUBSYSTEM_OBSERVABILITY: &str = "observability";
|
||||
const EVENT_AUDIT_OBSERVABILITY_STATE: &str = "audit_observability_state";
|
||||
|
||||
const M_AUDIT_EVENTS_TOTAL: &str = const_str::concat!(RUSTFS_AUDIT_METRICS_NAMESPACE, "events.total");
|
||||
const M_AUDIT_EVENTS_FAILED: &str = const_str::concat!(RUSTFS_AUDIT_METRICS_NAMESPACE, "events.failed");
|
||||
@@ -152,14 +155,26 @@ impl AuditMetrics {
|
||||
pub fn record_config_reload(&self) {
|
||||
self.config_reload_count.fetch_add(1, Ordering::Relaxed);
|
||||
counter!(M_AUDIT_CONFIG_RELOADS).increment(1);
|
||||
info!("Audit configuration reloaded");
|
||||
info!(
|
||||
event = EVENT_AUDIT_OBSERVABILITY_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_OBSERVABILITY,
|
||||
state = "config_reloaded",
|
||||
"Audit observability state updated"
|
||||
);
|
||||
}
|
||||
|
||||
/// Records a system start
|
||||
pub fn record_system_start(&self) {
|
||||
self.system_start_count.fetch_add(1, Ordering::Relaxed);
|
||||
counter!(M_AUDIT_SYSTEM_STARTS).increment(1);
|
||||
info!("Audit system started");
|
||||
info!(
|
||||
event = EVENT_AUDIT_OBSERVABILITY_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_OBSERVABILITY,
|
||||
state = "system_started",
|
||||
"Audit observability state updated"
|
||||
);
|
||||
}
|
||||
|
||||
/// Gets the current events per second (EPS)
|
||||
@@ -229,7 +244,13 @@ impl AuditMetrics {
|
||||
|
||||
// Reset EPS to zero after reset
|
||||
gauge!(M_AUDIT_EPS).set(0.0);
|
||||
info!("Audit metrics reset");
|
||||
info!(
|
||||
event = EVENT_AUDIT_OBSERVABILITY_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_OBSERVABILITY,
|
||||
state = "metrics_reset",
|
||||
"Audit observability state updated"
|
||||
);
|
||||
}
|
||||
|
||||
/// Generates a comprehensive metrics report
|
||||
|
||||
@@ -19,6 +19,11 @@ use rustfs_targets::arn::TargetID;
|
||||
use rustfs_targets::{SharedTarget, Target, TargetError, TargetPluginRegistry, TargetRuntimeManager};
|
||||
use tracing::info;
|
||||
|
||||
const LOG_COMPONENT_AUDIT: &str = "audit";
|
||||
const LOG_SUBSYSTEM_REGISTRY: &str = "registry";
|
||||
const EVENT_AUDIT_TARGET_REGISTRY_KEY_CREATED: &str = "audit_target_registry_key_created";
|
||||
const EVENT_AUDIT_TARGET_REGISTRY_STATE: &str = "audit_target_registry_state";
|
||||
|
||||
/// Registry for managing audit targets
|
||||
pub struct AuditRegistry {
|
||||
/// Storage for created targets
|
||||
@@ -155,7 +160,15 @@ impl AuditRegistry {
|
||||
if let Some(target) = self.targets.remove(&target_id)
|
||||
&& let Err(err) = target.close().await
|
||||
{
|
||||
tracing::error!(target_id = %target_id, error = %err, "Failed to close target during shutdown");
|
||||
tracing::error!(
|
||||
event = EVENT_AUDIT_TARGET_REGISTRY_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_REGISTRY,
|
||||
target_id = %target_id,
|
||||
state = "close_failed",
|
||||
error = %err,
|
||||
"Failed to close target during shutdown"
|
||||
);
|
||||
if first_error.is_none() {
|
||||
first_error = Some(err);
|
||||
}
|
||||
@@ -178,7 +191,15 @@ impl AuditRegistry {
|
||||
/// * `String` - The unique key for the target.
|
||||
pub fn create_key(&self, target_type: &str, target_id: &str) -> String {
|
||||
let key = TargetID::new(target_id.to_string(), target_type.to_string());
|
||||
info!(target_type = %target_type, "Create key for {}", key);
|
||||
info!(
|
||||
event = EVENT_AUDIT_TARGET_REGISTRY_KEY_CREATED,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_REGISTRY,
|
||||
target_type = %target_type,
|
||||
target_id = %target_id,
|
||||
registry_key = %key,
|
||||
"Created audit target registry key"
|
||||
);
|
||||
key.to_string()
|
||||
}
|
||||
|
||||
@@ -193,7 +214,15 @@ impl AuditRegistry {
|
||||
pub fn enable_target(&self, target_type: &str, target_id: &str) -> AuditResult<()> {
|
||||
let key = self.create_key(target_type, target_id);
|
||||
if self.get_target(&key).is_some() {
|
||||
info!("Target {}-{} enabled", target_type, target_id);
|
||||
info!(
|
||||
event = EVENT_AUDIT_TARGET_REGISTRY_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_REGISTRY,
|
||||
target_type = %target_type,
|
||||
target_id = %target_id,
|
||||
state = "enabled",
|
||||
"Audit target registry state changed"
|
||||
);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(AuditError::Configuration(
|
||||
@@ -214,7 +243,15 @@ impl AuditRegistry {
|
||||
pub fn disable_target(&self, target_type: &str, target_id: &str) -> AuditResult<()> {
|
||||
let key = self.create_key(target_type, target_id);
|
||||
if self.get_target(&key).is_some() {
|
||||
info!("Target {}-{} disabled", target_type, target_id);
|
||||
info!(
|
||||
event = EVENT_AUDIT_TARGET_REGISTRY_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_REGISTRY,
|
||||
target_type = %target_type,
|
||||
target_id = %target_id,
|
||||
state = "disabled",
|
||||
"Audit target registry state changed"
|
||||
);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(AuditError::Configuration(
|
||||
|
||||
@@ -183,7 +183,15 @@ impl AuditSystem {
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(error = %e, "Failed to create audit targets");
|
||||
error!(
|
||||
event = EVENT_AUDIT_SYSTEM_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_SYSTEM,
|
||||
state = "stopped",
|
||||
reason = "target_creation_failed",
|
||||
error = %e,
|
||||
"Failed to create audit targets"
|
||||
);
|
||||
let mut state = self.state.write().await;
|
||||
*state = AuditSystemState::Stopped;
|
||||
Err(e)
|
||||
@@ -265,7 +273,15 @@ impl AuditSystem {
|
||||
|
||||
// Stop all stream tasks first
|
||||
if let Err(e) = self.clear_runtime_targets().await {
|
||||
error!(error = %e, "Failed to close some audit targets");
|
||||
error!(
|
||||
event = EVENT_AUDIT_SYSTEM_STATE,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_SYSTEM,
|
||||
state = "stopping",
|
||||
reason = "target_shutdown_failed",
|
||||
error = %e,
|
||||
"Failed to close some audit targets"
|
||||
);
|
||||
}
|
||||
|
||||
// Clear configuration
|
||||
@@ -454,7 +470,14 @@ impl AuditSystem {
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(error = %e, "Failed to reload audit configuration");
|
||||
error!(
|
||||
event = EVENT_AUDIT_CONFIG_RELOADED,
|
||||
component = LOG_COMPONENT_AUDIT,
|
||||
subsystem = LOG_SUBSYSTEM_SYSTEM,
|
||||
state = "reload_failed",
|
||||
error = %e,
|
||||
"Failed to reload audit configuration"
|
||||
);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user