llm_sentinel_storage/
lib.rs

1//! # Sentinel Storage
2//!
3//! Data persistence layer for LLM-Sentinel.
4//!
5//! This crate provides:
6//! - Time-series storage (InfluxDB)
7//! - In-memory caching (Moka)
8//! - Distributed caching (Redis)
9//! - Query interfaces for metrics and anomalies
10
11#![warn(missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
12
13pub mod cache;
14pub mod influxdb;
15pub mod query;
16
17use async_trait::async_trait;
18use llm_sentinel_core::{
19    events::{AnomalyEvent, TelemetryEvent},
20    Result,
21};
22
23/// Trait for storage backends
24#[async_trait]
25pub trait Storage: Send + Sync {
26    /// Write a telemetry event
27    async fn write_telemetry(&self, event: &TelemetryEvent) -> Result<()>;
28
29    /// Write an anomaly event
30    async fn write_anomaly(&self, anomaly: &AnomalyEvent) -> Result<()>;
31
32    /// Batch write telemetry events
33    async fn write_telemetry_batch(&self, events: &[TelemetryEvent]) -> Result<()>;
34
35    /// Batch write anomaly events
36    async fn write_anomaly_batch(&self, anomalies: &[AnomalyEvent]) -> Result<()>;
37
38    /// Query telemetry events
39    async fn query_telemetry(&self, query: query::TelemetryQuery) -> Result<Vec<TelemetryEvent>>;
40
41    /// Query anomaly events
42    async fn query_anomalies(&self, query: query::AnomalyQuery) -> Result<Vec<AnomalyEvent>>;
43
44    /// Health check
45    async fn health_check(&self) -> Result<()>;
46}
47
48/// Re-export commonly used types
49pub mod prelude {
50    pub use crate::cache::{BaselineCache, CacheConfig};
51    pub use crate::influxdb::{InfluxDbStorage, InfluxDbConfig};
52    pub use crate::query::{AnomalyQuery, TelemetryQuery, TimeRange};
53    pub use crate::Storage;
54}