mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-10 15:16:56 +00:00
refactor(logging): unify governance runtime events (#3367)
This commit is contained in:
@@ -21,6 +21,11 @@ use rustfs_s3_types::EventName;
|
||||
use std::sync::Arc;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
const LOG_COMPONENT_NOTIFY: &str = "notify";
|
||||
const LOG_SUBSYSTEM_BUCKET_CONFIG: &str = "bucket_config";
|
||||
const EVENT_NOTIFY_BUCKET_CONFIG_VALIDATION: &str = "notify_bucket_config_validation";
|
||||
const EVENT_NOTIFY_BUCKET_CONFIG_LOADED: &str = "notify_bucket_config_loaded";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NotifyBucketConfigManager {
|
||||
notifier: Arc<EventNotifier>,
|
||||
@@ -57,24 +62,53 @@ impl NotifyBucketConfigManager {
|
||||
if arn_list.is_empty() {
|
||||
return Err(NotificationError::Configuration(notify_configuration_hint()));
|
||||
}
|
||||
info!("Available ARNs: {:?}", arn_list);
|
||||
debug!(
|
||||
event = EVENT_NOTIFY_BUCKET_CONFIG_VALIDATION,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_BUCKET_CONFIG,
|
||||
bucket = %bucket,
|
||||
region = %cfg.region,
|
||||
available_arn_count = arn_list.len(),
|
||||
"Loaded available notify target ARNs for bucket config validation"
|
||||
);
|
||||
|
||||
if let Err(e) = cfg.validate(&cfg.region, &arn_list) {
|
||||
debug!("Bucket notification config validation region:{} failed: {}", &cfg.region, e);
|
||||
debug!(
|
||||
event = EVENT_NOTIFY_BUCKET_CONFIG_VALIDATION,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_BUCKET_CONFIG,
|
||||
bucket = %bucket,
|
||||
region = %cfg.region,
|
||||
error = %e,
|
||||
result = "validation_failed",
|
||||
"Bucket notification config validation failed"
|
||||
);
|
||||
if !matches!(e, ParseConfigError::ArnNotFound(_)) {
|
||||
return Err(NotificationError::BucketNotification(e.to_string()));
|
||||
}
|
||||
warn!(
|
||||
event = EVENT_NOTIFY_BUCKET_CONFIG_VALIDATION,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_BUCKET_CONFIG,
|
||||
bucket = %bucket,
|
||||
region = %cfg.region,
|
||||
error = %e,
|
||||
result = "missing_target_arn",
|
||||
"Bucket notification config references missing target ARN; keeping compatibility and loading remaining rules"
|
||||
);
|
||||
}
|
||||
|
||||
self.subscriber_view.apply_bucket_config(bucket, cfg);
|
||||
self.rule_engine.set_bucket_rules(bucket, cfg.get_rules_map().clone()).await;
|
||||
info!("Loaded notification config for bucket: {}", bucket);
|
||||
info!(
|
||||
event = EVENT_NOTIFY_BUCKET_CONFIG_LOADED,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_BUCKET_CONFIG,
|
||||
bucket = %bucket,
|
||||
region = %cfg.region,
|
||||
rule_count = cfg.get_rules_map().inner().len(),
|
||||
"Loaded bucket notification config"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ const METRIC_NOTIFICATION_CURRENT_SEND_IN_PROGRESS: &str = "rustfs_notification_
|
||||
const METRIC_NOTIFICATION_EVENTS_ERRORS_TOTAL: &str = "rustfs_notification_events_errors_total";
|
||||
const METRIC_NOTIFICATION_EVENTS_SENT_TOTAL: &str = "rustfs_notification_events_sent_total";
|
||||
const METRIC_NOTIFICATION_EVENTS_SKIPPED_TOTAL: &str = "rustfs_notification_events_skipped_total";
|
||||
const LOG_COMPONENT_NOTIFY: &str = "notify";
|
||||
const LOG_SUBSYSTEM_INTEGRATION: &str = "integration";
|
||||
const EVENT_NOTIFY_SYSTEM_DROP: &str = "notify_system_drop";
|
||||
const EVENT_NOTIFY_SYSTEM_SHUTDOWN_METRIC: &str = "notify_system_shutdown_metric";
|
||||
const EVENT_NOTIFY_SYSTEM_STATUS_SNAPSHOT: &str = "notify_system_status_snapshot";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LiveEventBatch {
|
||||
@@ -362,7 +367,13 @@ impl NotificationSystem {
|
||||
impl Drop for NotificationSystem {
|
||||
fn drop(&mut self) {
|
||||
// Asynchronous operation cannot be used here, but logs can be recorded.
|
||||
info!("Notify the system instance to be destroyed");
|
||||
info!(
|
||||
event = EVENT_NOTIFY_SYSTEM_DROP,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_INTEGRATION,
|
||||
state = "dropping",
|
||||
"Notification system instance is being dropped"
|
||||
);
|
||||
|
||||
let snapshot = self.snapshot_metrics();
|
||||
for (name, value, is_gauge) in [
|
||||
@@ -376,15 +387,28 @@ impl Drop for NotificationSystem {
|
||||
} else {
|
||||
counter!(name).absolute(value);
|
||||
}
|
||||
info!("shutdown metric {}={}", name, value);
|
||||
info!(
|
||||
event = EVENT_NOTIFY_SYSTEM_SHUTDOWN_METRIC,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_INTEGRATION,
|
||||
metric_name = name,
|
||||
metric_value = value,
|
||||
metric_kind = if is_gauge { "gauge" } else { "counter" },
|
||||
"Notification shutdown metric snapshot"
|
||||
);
|
||||
}
|
||||
|
||||
let status = self.get_status();
|
||||
for (key, value) in status {
|
||||
info!("key:{}, value:{}", key, value);
|
||||
info!(
|
||||
event = EVENT_NOTIFY_SYSTEM_STATUS_SNAPSHOT,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_INTEGRATION,
|
||||
status_key = %key,
|
||||
status_value = %value,
|
||||
"Notification system status snapshot"
|
||||
);
|
||||
}
|
||||
|
||||
info!("Notification system status at shutdown:");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ use starshard::{AsyncShardedHashMap, DEFAULT_SHARDS, SnapshotMode};
|
||||
use std::sync::Arc;
|
||||
use tracing::info;
|
||||
|
||||
const LOG_COMPONENT_NOTIFY: &str = "notify";
|
||||
const LOG_SUBSYSTEM_RULE_ENGINE: &str = "rule_engine";
|
||||
const EVENT_NOTIFY_RULES_UPDATED: &str = "notify_bucket_rules_updated";
|
||||
|
||||
fn decoded_object_key_for_matching(object_key: &str) -> Option<String> {
|
||||
if !object_key.contains('%') {
|
||||
return None;
|
||||
@@ -52,12 +56,21 @@ impl NotifyRuleEngine {
|
||||
}
|
||||
|
||||
pub async fn set_bucket_rules(&self, bucket: &str, rules_map: RulesMap) {
|
||||
let event_count = rules_map.iter_events().count();
|
||||
if rules_map.is_empty() {
|
||||
self.bucket_rules_map.remove(&bucket.to_string()).await;
|
||||
} else {
|
||||
self.bucket_rules_map.insert(bucket.to_string(), rules_map).await;
|
||||
}
|
||||
info!("Updated notification rules for bucket: {}", bucket);
|
||||
info!(
|
||||
event = EVENT_NOTIFY_RULES_UPDATED,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_RULE_ENGINE,
|
||||
bucket = %bucket,
|
||||
state = "updated",
|
||||
event_count,
|
||||
"Updated bucket notification rules"
|
||||
);
|
||||
}
|
||||
|
||||
pub async fn get_bucket_rules(&self, bucket: &str) -> Option<RulesMap> {
|
||||
@@ -66,7 +79,14 @@ impl NotifyRuleEngine {
|
||||
|
||||
pub async fn clear_bucket_rules(&self, bucket: &str) {
|
||||
if self.bucket_rules_map.remove(&bucket.to_string()).await.is_some() {
|
||||
info!("Removed all notification rules for bucket: {}", bucket);
|
||||
info!(
|
||||
event = EVENT_NOTIFY_RULES_UPDATED,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_RULE_ENGINE,
|
||||
bucket = %bucket,
|
||||
state = "removed",
|
||||
"Removed bucket notification rules"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ use tracing::{debug, info};
|
||||
const LOG_COMPONENT_NOTIFY: &str = "notify";
|
||||
const LOG_SUBSYSTEM_RUNTIME: &str = "runtime";
|
||||
const EVENT_NOTIFY_RUNTIME_LIFECYCLE: &str = "notify_runtime_lifecycle";
|
||||
const EVENT_NOTIFY_RUNTIME_SHUTDOWN_FAILED: &str = "notify_runtime_shutdown_failed";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NotifyRuntimeFacade {
|
||||
@@ -143,7 +144,13 @@ impl NotifyRuntimeFacade {
|
||||
.shutdown(target_list.runtime_mut(), &mut replay_workers)
|
||||
.await
|
||||
{
|
||||
tracing::error!(error = %err, "Failed to shutdown notify runtime cleanly");
|
||||
tracing::error!(
|
||||
event = EVENT_NOTIFY_RUNTIME_SHUTDOWN_FAILED,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_RUNTIME,
|
||||
error = %err,
|
||||
"Failed to shutdown notify runtime cleanly"
|
||||
);
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
|
||||
Reference in New Issue
Block a user