mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-12 16:16:55 +00:00
feat: add an opt-in NATS JetStream publish path for the notify and audit targets (#4634)
feat(targets): add an opt-in NATS JetStream publish path for the notify and audit targets The NATS notify and audit targets publish through NATS Core, which returns before the server has durably accepted the message. A broker restart or a connection drop between the publish and the flush loses the event, even though the send queue has already cleared it, and no acknowledgement gates that clear. An opt-in JetStream publish path clears a queued event only after the server returns a durable PublishAck, so delivery is at-least-once across a broker restart or a reconnect. It applies to both the notify and audit NATS targets, is off by default, and is byte-identical to the NATS Core path when disabled. The path includes durable store-and-forward, a stable dedup id sent as the Nats-Msg-Id header so a replayed event is collapsed by the stream duplicate window, pre-flight stream validation, and a bounded failed-events store for terminally-failed and retry-exhausted events. Three configuration keys per target select it: JETSTREAM_ENABLE, JETSTREAM_STREAM_NAME, and JETSTREAM_ACK_TIMEOUT_SECS, under the RUSTFS_NOTIFY_NATS_ and RUSTFS_AUDIT_NATS_ prefixes. The on-disk batch filename separator changes from colon to underscore so batch names are valid on Windows filesystems, with transparent read-back of files written under the previous separator. The migration affects the shared queue store for every target type and lands with this feature because the store gains its first Windows-exercised paths here. Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -80,6 +80,7 @@ pub struct NotificationMetricSnapshot {
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct NotificationTargetMetricSnapshot {
|
||||
pub failed_messages: u64,
|
||||
pub failed_store_length: u64,
|
||||
pub queue_length: u64,
|
||||
pub target_id: String,
|
||||
pub target_type: String,
|
||||
|
||||
@@ -19,12 +19,13 @@ use rustfs_targets::{
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::{RwLock, Semaphore};
|
||||
use tracing::{debug, info};
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
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";
|
||||
const EVENT_NOTIFY_REPLAY_RETRY_EXHAUSTED: &str = "notify_replay_retry_exhausted";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NotifyRuntimeFacade {
|
||||
@@ -48,9 +49,18 @@ impl NotifyRuntimeFacade {
|
||||
match event {
|
||||
ReplayEvent::Delivered { .. } => metrics.increment_processed(),
|
||||
ReplayEvent::RetryableError { .. } => {}
|
||||
ReplayEvent::Dropped { target, .. }
|
||||
| ReplayEvent::PermanentFailure { target, .. }
|
||||
| ReplayEvent::RetryExhausted { target, .. } => {
|
||||
ReplayEvent::RetryExhausted { detail, key, target } => {
|
||||
warn!(
|
||||
event = EVENT_NOTIFY_REPLAY_RETRY_EXHAUSTED,
|
||||
component = LOG_COMPONENT_NOTIFY,
|
||||
subsystem = LOG_SUBSYSTEM_RUNTIME,
|
||||
target_id = %target.id(),
|
||||
replay_key = %key,
|
||||
error = %detail,
|
||||
"notify replay retry budget exhausted, entry stays queued and retries"
|
||||
);
|
||||
}
|
||||
ReplayEvent::Dropped { target, .. } | ReplayEvent::PermanentFailure { target, .. } => {
|
||||
target.record_final_failure();
|
||||
metrics.increment_failed();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ impl NotifyRuntimeView {
|
||||
.into_iter()
|
||||
.map(|snapshot| NotificationTargetMetricSnapshot {
|
||||
failed_messages: snapshot.failed_messages,
|
||||
failed_store_length: snapshot.failed_store_length,
|
||||
queue_length: snapshot.queue_length,
|
||||
target_id: snapshot.target_id,
|
||||
target_type: snapshot.target_type,
|
||||
@@ -90,6 +91,7 @@ mod tests {
|
||||
active: bool,
|
||||
enabled: bool,
|
||||
failed_messages: Arc<AtomicU64>,
|
||||
failed_store_length: u64,
|
||||
id: TargetID,
|
||||
total_messages: Arc<AtomicU64>,
|
||||
}
|
||||
@@ -100,6 +102,7 @@ mod tests {
|
||||
active: true,
|
||||
enabled: true,
|
||||
failed_messages: Arc::new(AtomicU64::new(0)),
|
||||
failed_store_length: 0,
|
||||
id: TargetID::new(id.to_string(), name.to_string()),
|
||||
total_messages: Arc::new(AtomicU64::new(0)),
|
||||
}
|
||||
@@ -110,6 +113,11 @@ mod tests {
|
||||
self
|
||||
}
|
||||
|
||||
fn with_failed_store_length(mut self, failed_store_length: u64) -> Self {
|
||||
self.failed_store_length = failed_store_length;
|
||||
self
|
||||
}
|
||||
|
||||
fn with_enabled(mut self, enabled: bool) -> Self {
|
||||
self.enabled = enabled;
|
||||
self
|
||||
@@ -168,6 +176,7 @@ mod tests {
|
||||
fn delivery_snapshot(&self) -> TargetDeliverySnapshot {
|
||||
TargetDeliverySnapshot {
|
||||
failed_messages: self.failed_messages.load(Ordering::Relaxed),
|
||||
failed_store_length: self.failed_store_length,
|
||||
queue_length: 0,
|
||||
total_messages: self.total_messages.load(Ordering::Relaxed),
|
||||
}
|
||||
@@ -206,7 +215,7 @@ mod tests {
|
||||
let target_list = Arc::new(RwLock::new(TargetList::new()));
|
||||
let replay_workers = Arc::new(RwLock::new(ReplayWorkerManager::new()));
|
||||
|
||||
let online = Arc::new(TestTarget::new("primary", "webhook"));
|
||||
let online = Arc::new(TestTarget::new("primary", "webhook").with_failed_store_length(7));
|
||||
online.record_successes(3);
|
||||
online.record_failures(1);
|
||||
|
||||
@@ -239,9 +248,11 @@ mod tests {
|
||||
assert_eq!(metric_snapshots.len(), 2);
|
||||
assert_eq!(metric_snapshots[0].target_id, "backup:mqtt");
|
||||
assert_eq!(metric_snapshots[0].failed_messages, 0);
|
||||
assert_eq!(metric_snapshots[0].failed_store_length, 0);
|
||||
assert_eq!(metric_snapshots[0].total_messages, 2);
|
||||
assert_eq!(metric_snapshots[1].target_id, "primary:webhook");
|
||||
assert_eq!(metric_snapshots[1].failed_messages, 1);
|
||||
assert_eq!(metric_snapshots[1].failed_store_length, 7);
|
||||
assert_eq!(metric_snapshots[1].total_messages, 3);
|
||||
|
||||
let health_snapshots = runtime_view.snapshot_target_health().await;
|
||||
|
||||
Reference in New Issue
Block a user