Skip to main content

AnalyticsDatabase

Struct AnalyticsDatabase 

Source
pub struct AnalyticsDatabase { /* private fields */ }
Expand description

Analytics database manager

Implementations§

Source§

impl AnalyticsDatabase

Source

pub async fn new(database_path: &Path) -> Result<Self>

Create a new analytics database connection

§Arguments
  • database_path - Path to the SQLite database file (or “:memory:” for in-memory)
§Errors

Returns an error if the database connection cannot be established or SQLite pragmas fail to execute.

Source

pub async fn run_migrations(&self) -> Result<()>

Run database migrations

§Errors

Returns an error if any migration SQL fails to execute.

Source

pub const fn pool(&self) -> &SqlitePool

Get a reference to the database pool

Source

pub async fn insert_minute_aggregate( &self, agg: &MetricsAggregate, ) -> Result<i64>

Insert a minute-level metrics aggregate

§Errors

Returns an error if the database insert fails.

Source

pub async fn insert_minute_aggregates_batch( &self, aggregates: &[MetricsAggregate], ) -> Result<()>

Insert multiple minute-level aggregates in a batch

§Errors

Returns an error if any database insert fails; the transaction is rolled back.

Source

pub async fn insert_hour_aggregate( &self, agg: &HourMetricsAggregate, ) -> Result<i64>

Insert an hour-level metrics aggregate

§Errors

Returns an error if the database insert fails.

Source

pub async fn insert_day_aggregate( &self, agg: &DayMetricsAggregate, ) -> Result<i64>

Insert a day-level metrics aggregate

§Errors

Returns an error if the database insert fails.

Source

pub async fn upsert_endpoint_stats(&self, stats: &EndpointStats) -> Result<()>

Insert or update endpoint statistics

§Errors

Returns an error if the database upsert fails.

Source

pub async fn insert_error_event(&self, error: &ErrorEvent) -> Result<i64>

Insert an error event

§Errors

Returns an error if the database insert fails.

Source

pub async fn insert_traffic_pattern( &self, pattern: &TrafficPattern, ) -> Result<()>

Insert a traffic pattern

§Errors

Returns an error if the database upsert fails.

Source

pub async fn insert_snapshot(&self, snapshot: &AnalyticsSnapshot) -> Result<i64>

Insert an analytics snapshot

§Errors

Returns an error if the database insert fails.

Source

pub async fn get_minute_aggregates( &self, filter: &AnalyticsFilter, ) -> Result<Vec<MetricsAggregate>>

Get minute aggregates for a time range

§Errors

Returns an error if the database query fails.

Source

pub async fn get_hour_aggregates( &self, filter: &AnalyticsFilter, ) -> Result<Vec<HourMetricsAggregate>>

Get hour-level aggregates

§Errors

Returns an error if the database query fails.

Source

pub async fn get_top_endpoints( &self, limit: i64, workspace_id: Option<&str>, ) -> Result<Vec<EndpointStats>>

Get top endpoints by request count

§Errors

Returns an error if the database query fails.

Source

pub async fn get_recent_errors( &self, limit: i64, filter: &AnalyticsFilter, ) -> Result<Vec<ErrorEvent>>

Get recent error events

§Errors

Returns an error if the database query fails.

Source

pub async fn get_traffic_patterns( &self, days: i64, workspace_id: Option<&str>, ) -> Result<Vec<TrafficPattern>>

Get traffic patterns for heatmap

§Errors

Returns an error if the database query fails.

Source

pub async fn cleanup_minute_aggregates(&self, days: u32) -> Result<u64>

Delete old minute aggregates

§Errors

Returns an error if the database delete fails.

Source

pub async fn cleanup_hour_aggregates(&self, days: u32) -> Result<u64>

Delete old hour aggregates

§Errors

Returns an error if the database delete fails.

Source

pub async fn cleanup_error_events(&self, days: u32) -> Result<u64>

Delete old error events

§Errors

Returns an error if the database delete fails.

Source

pub async fn vacuum(&self) -> Result<()>

Vacuum the database to reclaim space

§Errors

Returns an error if the VACUUM command fails.

Source§

impl AnalyticsDatabase

Source

pub async fn record_scenario_usage( &self, scenario_id: &str, workspace_id: Option<&str>, org_id: Option<&str>, ) -> Result<()>

Record scenario usage

§Errors

Returns an error if the database operation fails.

Source

pub async fn record_persona_ci_hit( &self, persona_id: &str, workspace_id: Option<&str>, org_id: Option<&str>, ci_run_id: Option<&str>, ) -> Result<()>

Record persona CI hit

§Errors

Returns an error if the database insert fails.

Source

pub async fn record_endpoint_coverage( &self, endpoint: &str, method: Option<&str>, protocol: &str, workspace_id: Option<&str>, org_id: Option<&str>, coverage_percentage: Option<f64>, ) -> Result<()>

Record endpoint test coverage

§Errors

Returns an error if the database operation fails.

Source

pub async fn record_reality_level_staleness( &self, workspace_id: &str, org_id: Option<&str>, endpoint: Option<&str>, method: Option<&str>, protocol: Option<&str>, current_reality_level: Option<&str>, staleness_days: Option<i32>, ) -> Result<()>

Record reality level staleness

§Errors

Returns an error if the database insert fails.

Source

pub async fn record_drift_percentage( &self, workspace_id: &str, org_id: Option<&str>, total_mocks: i64, drifting_mocks: i64, ) -> Result<()>

Record drift percentage metrics

§Errors

Returns an error if the database insert fails.

Source

pub async fn get_scenario_usage( &self, workspace_id: Option<&str>, org_id: Option<&str>, limit: Option<i64>, ) -> Result<Vec<ScenarioUsageMetrics>>

Get scenario usage metrics

§Errors

Returns an error if the database query fails.

Source

pub async fn get_persona_ci_hits( &self, workspace_id: Option<&str>, org_id: Option<&str>, limit: Option<i64>, ) -> Result<Vec<PersonaCIHit>>

Get persona CI hits

§Errors

Returns an error if the database query fails.

Source

pub async fn get_endpoint_coverage( &self, workspace_id: Option<&str>, org_id: Option<&str>, min_coverage: Option<f64>, ) -> Result<Vec<EndpointCoverage>>

Get endpoint coverage

§Errors

Returns an error if the database query fails.

Source

pub async fn get_reality_level_staleness( &self, workspace_id: Option<&str>, org_id: Option<&str>, max_staleness_days: Option<i32>, ) -> Result<Vec<RealityLevelStaleness>>

Get reality level staleness

§Errors

Returns an error if the database query fails.

Source

pub async fn get_drift_percentage( &self, workspace_id: Option<&str>, org_id: Option<&str>, limit: Option<i64>, ) -> Result<Vec<DriftPercentageMetrics>>

Get drift percentage metrics

§Errors

Returns an error if the database query fails.

Source§

impl AnalyticsDatabase

Source

pub async fn export_to_csv<W: Write>( &self, writer: &mut W, filter: &AnalyticsFilter, ) -> Result<usize>

Export metrics to CSV format

§Errors

Returns an error if the database query or CSV writing fails.

Source

pub async fn export_to_json(&self, filter: &AnalyticsFilter) -> Result<String>

Export metrics to JSON format

§Errors

Returns an error if the database query or JSON serialization fails.

Source

pub async fn export_endpoints_to_csv<W: Write>( &self, writer: &mut W, workspace_id: Option<&str>, limit: i64, ) -> Result<usize>

Export endpoint stats to CSV

§Errors

Returns an error if the database query or CSV writing fails.

Source

pub async fn export_errors_to_csv<W: Write>( &self, writer: &mut W, filter: &AnalyticsFilter, limit: i64, ) -> Result<usize>

Export error events to CSV

§Errors

Returns an error if the database query or CSV writing fails.

Source§

impl AnalyticsDatabase

Source

pub async fn record_pillar_usage(&self, event: &PillarUsageEvent) -> Result<()>

Record a pillar usage event

§Errors

Returns an error if the database insert or JSON serialization fails.

Source

pub async fn get_workspace_pillar_metrics( &self, workspace_id: &str, duration_seconds: i64, ) -> Result<PillarUsageMetrics>

Get pillar usage metrics for a workspace

§Errors

Returns an error if any database query fails.

Source

pub async fn get_org_pillar_metrics( &self, org_id: &str, duration_seconds: i64, ) -> Result<PillarUsageMetrics>

Get pillar usage metrics for an organization

§Errors

Returns an error if any database query fails.

Source§

impl AnalyticsDatabase

Source

pub async fn get_overview_metrics( &self, duration_seconds: i64, ) -> Result<OverviewMetrics>

Get overview metrics for the dashboard

§Errors

Returns an error if any database query fails.

Source

pub async fn get_top_protocols( &self, limit: i64, workspace_id: Option<&str>, ) -> Result<Vec<ProtocolStat>>

Get top protocols by request count

§Errors

Returns an error if the database query fails.

Source

pub async fn get_request_time_series( &self, filter: &AnalyticsFilter, granularity: Granularity, ) -> Result<Vec<TimeSeries>>

Get request count time series

§Errors

Returns an error if the database query fails.

Get latency trends

§Errors

Returns an error if the database query fails.

Source

pub async fn get_error_summary( &self, filter: &AnalyticsFilter, limit: i64, ) -> Result<Vec<ErrorSummary>>

Get error summary

§Errors

Returns an error if the database query fails.

Trait Implementations§

Source§

impl Clone for AnalyticsDatabase

Source§

fn clone(&self) -> AnalyticsDatabase

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more