pub struct TrendsManager { /* private fields */ }Expand description
High-level trends manager.
Implementations§
Source§impl TrendsManager
impl TrendsManager
Sourcepub fn new(config: TrendsConfig) -> Self
pub fn new(config: TrendsConfig) -> Self
Create a new trends manager.
Sourcepub fn with_dependencies(
config: TrendsConfig,
dependencies: TrendsManagerDependencies,
) -> Self
pub fn with_dependencies( config: TrendsConfig, dependencies: TrendsManagerDependencies, ) -> Self
Create with dependencies.
Sourcepub fn start_background_detection(&self) -> JoinHandle<()>
pub fn start_background_detection(&self) -> JoinHandle<()>
Start background anomaly detection.
Sourcepub fn record_request(
&self,
entity_id: &str,
session_id: Option<&str>,
user_agent: Option<&str>,
authorization: Option<&str>,
client_ip: Option<&str>,
ja4: Option<&str>,
ja4h: Option<&str>,
last_request_time: Option<i64>,
) -> Vec<Signal>
pub fn record_request( &self, entity_id: &str, session_id: Option<&str>, user_agent: Option<&str>, authorization: Option<&str>, client_ip: Option<&str>, ja4: Option<&str>, ja4h: Option<&str>, last_request_time: Option<i64>, ) -> Vec<Signal>
Extract and record signals from request context.
Sourcepub fn record_signal(&self, signal: Signal)
pub fn record_signal(&self, signal: Signal)
Record a single signal.
Sourcepub fn record_payload_anomaly(
&self,
id: String,
anomaly_type: AnomalyType,
severity: AnomalySeverity,
detected_at: i64,
template: String,
entity_id: String,
description: String,
metadata: AnomalyMetadata,
)
pub fn record_payload_anomaly( &self, id: String, anomaly_type: AnomalyType, severity: AnomalySeverity, detected_at: i64, template: String, entity_id: String, description: String, metadata: AnomalyMetadata, )
Record a payload anomaly.
Sourcepub fn record_login(
&self,
user_id: &str,
timestamp_ms: u64,
ip: &str,
latitude: f64,
longitude: f64,
country: &str,
country_code: &str,
city: Option<&str>,
accuracy_km: u32,
device_fingerprint: Option<&str>,
) -> bool
pub fn record_login( &self, user_id: &str, timestamp_ms: u64, ip: &str, latitude: f64, longitude: f64, country: &str, country_code: &str, city: Option<&str>, accuracy_km: u32, device_fingerprint: Option<&str>, ) -> bool
Record a login event for impossible travel detection.
Checks if the user’s login pattern indicates geographically impossible travel (e.g., logging in from NYC then London within 10 minutes).
§Arguments
user_id- User identifier (session subject, user ID, or email)timestamp_ms- Unix timestamp in millisecondsip- IP address of the loginlatitude- Latitude from GeoIP lookuplongitude- Longitude from GeoIP lookupcountry- Country namecountry_code- ISO country codecity- Optional city nameaccuracy_km- GeoIP accuracy radius in kmdevice_fingerprint- Optional device fingerprint for correlation
§Returns
true if an impossible travel alert was generated.
Sourcepub fn whitelist_travel_route(
&self,
user_id: &str,
country1: &str,
country2: &str,
)
pub fn whitelist_travel_route( &self, user_id: &str, country1: &str, country2: &str, )
Add a whitelisted travel route for a user.
Known travel patterns (e.g., home <-> work across countries) can be whitelisted to prevent false positives.
Sourcepub fn remove_travel_whitelist(
&self,
user_id: &str,
country1: &str,
country2: &str,
)
pub fn remove_travel_whitelist( &self, user_id: &str, country1: &str, country2: &str, )
Remove a whitelisted travel route.
Sourcepub fn travel_stats(&self) -> TravelStats
pub fn travel_stats(&self) -> TravelStats
Get impossible travel detection statistics.
Sourcepub fn clear_travel_history(&self, user_id: &str)
pub fn clear_travel_history(&self, user_id: &str)
Clear impossible travel history for a user.
Sourcepub fn get_summary(&self, options: TrendQueryOptions) -> TrendsSummary
pub fn get_summary(&self, options: TrendQueryOptions) -> TrendsSummary
Get overall trends summary.
Sourcepub fn get_trends(&self, options: TrendQueryOptions) -> Vec<SignalTrend>
pub fn get_trends(&self, options: TrendQueryOptions) -> Vec<SignalTrend>
Get detailed trends by type.
Sourcepub fn get_signals_for_entity(
&self,
entity_id: &str,
options: TrendQueryOptions,
) -> Vec<Signal>
pub fn get_signals_for_entity( &self, entity_id: &str, options: TrendQueryOptions, ) -> Vec<Signal>
Get signals for an entity.
Sourcepub fn get_signals(&self, options: TrendQueryOptions) -> Vec<Signal>
pub fn get_signals(&self, options: TrendQueryOptions) -> Vec<Signal>
Get all signals matching criteria.
Sourcepub fn get_anomalies(&self, options: AnomalyQueryOptions) -> Vec<Anomaly>
pub fn get_anomalies(&self, options: AnomalyQueryOptions) -> Vec<Anomaly>
Get anomalies matching criteria.
Sourcepub fn get_anomaly(&self, id: &str) -> Option<Anomaly>
pub fn get_anomaly(&self, id: &str) -> Option<Anomaly>
Get a specific anomaly by ID.
Sourcepub fn active_anomaly_count(&self) -> usize
pub fn active_anomaly_count(&self) -> usize
Get count of active anomalies.
Sourcepub fn get_correlations(
&self,
options: CorrelationQueryOptions,
) -> Vec<Correlation>
pub fn get_correlations( &self, options: CorrelationQueryOptions, ) -> Vec<Correlation>
Get correlations matching criteria.
Sourcepub fn get_entity_correlations(
&self,
entity_id: &str,
options: CorrelationQueryOptions,
) -> Vec<Correlation>
pub fn get_entity_correlations( &self, entity_id: &str, options: CorrelationQueryOptions, ) -> Vec<Correlation>
Get correlations for a specific entity.
Sourcepub fn stats(&self) -> TrendsManagerStats
pub fn stats(&self) -> TrendsManagerStats
Get manager statistics.
Sourcepub fn stats_snapshot(&self) -> TrendsStats
pub fn stats_snapshot(&self) -> TrendsStats
Get a stats snapshot for API responses.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if enabled.
Auto Trait Implementations§
impl !Freeze for TrendsManager
impl !RefUnwindSafe for TrendsManager
impl Send for TrendsManager
impl Sync for TrendsManager
impl Unpin for TrendsManager
impl UnsafeUnpin for TrendsManager
impl !UnwindSafe for TrendsManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more