pub struct AnalyticsDatabase { /* private fields */ }Expand description
Analytics database manager
Implementations§
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn run_migrations(&self) -> Result<()>
pub async fn run_migrations(&self) -> Result<()>
Sourcepub const fn pool(&self) -> &SqlitePool
pub const fn pool(&self) -> &SqlitePool
Get a reference to the database pool
Sourcepub async fn insert_minute_aggregate(
&self,
agg: &MetricsAggregate,
) -> Result<i64>
pub async fn insert_minute_aggregate( &self, agg: &MetricsAggregate, ) -> Result<i64>
Sourcepub async fn insert_minute_aggregates_batch(
&self,
aggregates: &[MetricsAggregate],
) -> Result<()>
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.
Sourcepub async fn insert_hour_aggregate(
&self,
agg: &HourMetricsAggregate,
) -> Result<i64>
pub async fn insert_hour_aggregate( &self, agg: &HourMetricsAggregate, ) -> Result<i64>
Sourcepub async fn insert_day_aggregate(
&self,
agg: &DayMetricsAggregate,
) -> Result<i64>
pub async fn insert_day_aggregate( &self, agg: &DayMetricsAggregate, ) -> Result<i64>
Sourcepub async fn upsert_endpoint_stats(&self, stats: &EndpointStats) -> Result<()>
pub async fn upsert_endpoint_stats(&self, stats: &EndpointStats) -> Result<()>
Sourcepub async fn insert_error_event(&self, error: &ErrorEvent) -> Result<i64>
pub async fn insert_error_event(&self, error: &ErrorEvent) -> Result<i64>
Sourcepub async fn insert_traffic_pattern(
&self,
pattern: &TrafficPattern,
) -> Result<()>
pub async fn insert_traffic_pattern( &self, pattern: &TrafficPattern, ) -> Result<()>
Sourcepub async fn insert_snapshot(&self, snapshot: &AnalyticsSnapshot) -> Result<i64>
pub async fn insert_snapshot(&self, snapshot: &AnalyticsSnapshot) -> Result<i64>
Sourcepub async fn get_minute_aggregates(
&self,
filter: &AnalyticsFilter,
) -> Result<Vec<MetricsAggregate>>
pub async fn get_minute_aggregates( &self, filter: &AnalyticsFilter, ) -> Result<Vec<MetricsAggregate>>
Sourcepub async fn get_hour_aggregates(
&self,
filter: &AnalyticsFilter,
) -> Result<Vec<HourMetricsAggregate>>
pub async fn get_hour_aggregates( &self, filter: &AnalyticsFilter, ) -> Result<Vec<HourMetricsAggregate>>
Sourcepub async fn get_top_endpoints(
&self,
limit: i64,
workspace_id: Option<&str>,
) -> Result<Vec<EndpointStats>>
pub async fn get_top_endpoints( &self, limit: i64, workspace_id: Option<&str>, ) -> Result<Vec<EndpointStats>>
Sourcepub async fn get_recent_errors(
&self,
limit: i64,
filter: &AnalyticsFilter,
) -> Result<Vec<ErrorEvent>>
pub async fn get_recent_errors( &self, limit: i64, filter: &AnalyticsFilter, ) -> Result<Vec<ErrorEvent>>
Sourcepub async fn get_traffic_patterns(
&self,
days: i64,
workspace_id: Option<&str>,
) -> Result<Vec<TrafficPattern>>
pub async fn get_traffic_patterns( &self, days: i64, workspace_id: Option<&str>, ) -> Result<Vec<TrafficPattern>>
Sourcepub async fn cleanup_minute_aggregates(&self, days: u32) -> Result<u64>
pub async fn cleanup_minute_aggregates(&self, days: u32) -> Result<u64>
Sourcepub async fn cleanup_hour_aggregates(&self, days: u32) -> Result<u64>
pub async fn cleanup_hour_aggregates(&self, days: u32) -> Result<u64>
Sourcepub async fn cleanup_error_events(&self, days: u32) -> Result<u64>
pub async fn cleanup_error_events(&self, days: u32) -> Result<u64>
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn record_scenario_usage(
&self,
scenario_id: &str,
workspace_id: Option<&str>,
org_id: Option<&str>,
) -> Result<()>
pub async fn record_scenario_usage( &self, scenario_id: &str, workspace_id: Option<&str>, org_id: Option<&str>, ) -> Result<()>
Sourcepub async fn record_persona_ci_hit(
&self,
persona_id: &str,
workspace_id: Option<&str>,
org_id: Option<&str>,
ci_run_id: Option<&str>,
) -> Result<()>
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<()>
Sourcepub 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<()>
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<()>
Sourcepub 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<()>
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<()>
Sourcepub async fn record_drift_percentage(
&self,
workspace_id: &str,
org_id: Option<&str>,
total_mocks: i64,
drifting_mocks: i64,
) -> Result<()>
pub async fn record_drift_percentage( &self, workspace_id: &str, org_id: Option<&str>, total_mocks: i64, drifting_mocks: i64, ) -> Result<()>
Sourcepub async fn get_scenario_usage(
&self,
workspace_id: Option<&str>,
org_id: Option<&str>,
limit: Option<i64>,
) -> Result<Vec<ScenarioUsageMetrics>>
pub async fn get_scenario_usage( &self, workspace_id: Option<&str>, org_id: Option<&str>, limit: Option<i64>, ) -> Result<Vec<ScenarioUsageMetrics>>
Sourcepub async fn get_persona_ci_hits(
&self,
workspace_id: Option<&str>,
org_id: Option<&str>,
limit: Option<i64>,
) -> Result<Vec<PersonaCIHit>>
pub async fn get_persona_ci_hits( &self, workspace_id: Option<&str>, org_id: Option<&str>, limit: Option<i64>, ) -> Result<Vec<PersonaCIHit>>
Sourcepub async fn get_endpoint_coverage(
&self,
workspace_id: Option<&str>,
org_id: Option<&str>,
min_coverage: Option<f64>,
) -> Result<Vec<EndpointCoverage>>
pub async fn get_endpoint_coverage( &self, workspace_id: Option<&str>, org_id: Option<&str>, min_coverage: Option<f64>, ) -> Result<Vec<EndpointCoverage>>
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn export_to_csv<W: Write>(
&self,
writer: &mut W,
filter: &AnalyticsFilter,
) -> Result<usize>
pub async fn export_to_csv<W: Write>( &self, writer: &mut W, filter: &AnalyticsFilter, ) -> Result<usize>
Sourcepub async fn export_to_json(&self, filter: &AnalyticsFilter) -> Result<String>
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.
Sourcepub async fn export_endpoints_to_csv<W: Write>(
&self,
writer: &mut W,
workspace_id: Option<&str>,
limit: i64,
) -> Result<usize>
pub async fn export_endpoints_to_csv<W: Write>( &self, writer: &mut W, workspace_id: Option<&str>, limit: i64, ) -> Result<usize>
Sourcepub async fn export_errors_to_csv<W: Write>(
&self,
writer: &mut W,
filter: &AnalyticsFilter,
limit: i64,
) -> Result<usize>
pub async fn export_errors_to_csv<W: Write>( &self, writer: &mut W, filter: &AnalyticsFilter, limit: i64, ) -> Result<usize>
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn record_pillar_usage(&self, event: &PillarUsageEvent) -> Result<()>
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.
Sourcepub async fn get_workspace_pillar_metrics(
&self,
workspace_id: &str,
duration_seconds: i64,
) -> Result<PillarUsageMetrics>
pub async fn get_workspace_pillar_metrics( &self, workspace_id: &str, duration_seconds: i64, ) -> Result<PillarUsageMetrics>
Sourcepub async fn get_org_pillar_metrics(
&self,
org_id: &str,
duration_seconds: i64,
) -> Result<PillarUsageMetrics>
pub async fn get_org_pillar_metrics( &self, org_id: &str, duration_seconds: i64, ) -> Result<PillarUsageMetrics>
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn get_overview_metrics(
&self,
duration_seconds: i64,
) -> Result<OverviewMetrics>
pub async fn get_overview_metrics( &self, duration_seconds: i64, ) -> Result<OverviewMetrics>
Sourcepub async fn get_top_protocols(
&self,
limit: i64,
workspace_id: Option<&str>,
) -> Result<Vec<ProtocolStat>>
pub async fn get_top_protocols( &self, limit: i64, workspace_id: Option<&str>, ) -> Result<Vec<ProtocolStat>>
Sourcepub async fn get_request_time_series(
&self,
filter: &AnalyticsFilter,
granularity: Granularity,
) -> Result<Vec<TimeSeries>>
pub async fn get_request_time_series( &self, filter: &AnalyticsFilter, granularity: Granularity, ) -> Result<Vec<TimeSeries>>
Sourcepub async fn get_latency_trends(
&self,
filter: &AnalyticsFilter,
) -> Result<Vec<LatencyTrend>>
pub async fn get_latency_trends( &self, filter: &AnalyticsFilter, ) -> Result<Vec<LatencyTrend>>
Sourcepub async fn get_error_summary(
&self,
filter: &AnalyticsFilter,
limit: i64,
) -> Result<Vec<ErrorSummary>>
pub async fn get_error_summary( &self, filter: &AnalyticsFilter, limit: i64, ) -> Result<Vec<ErrorSummary>>
Trait Implementations§
Source§impl Clone for AnalyticsDatabase
impl Clone for AnalyticsDatabase
Source§fn clone(&self) -> AnalyticsDatabase
fn clone(&self) -> AnalyticsDatabase
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AnalyticsDatabase
impl !RefUnwindSafe for AnalyticsDatabase
impl Send for AnalyticsDatabase
impl Sync for AnalyticsDatabase
impl Unpin for AnalyticsDatabase
impl UnsafeUnpin for AnalyticsDatabase
impl !UnwindSafe for AnalyticsDatabase
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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