celers_broker_sql/stats_types.rs
1//! Statistics and diagnostics type definitions
2//!
3//! Types used for task execution stats, queue saturation monitoring,
4//! latency percentiles, state transitions, priority queue stats,
5//! migration verification, and query performance profiling.
6
7use celers_core::TaskId;
8use chrono::Utc;
9use serde::{Deserialize, Serialize};
10
11/// Task execution time statistics
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct TaskExecutionStats {
14 /// Number of completed tasks measured
15 pub task_count: i64,
16 /// Minimum execution time in seconds
17 pub min_execution_secs: f64,
18 /// Maximum execution time in seconds
19 pub max_execution_secs: f64,
20 /// Average execution time in seconds
21 pub avg_execution_secs: f64,
22 /// Standard deviation of execution time in seconds
23 pub stddev_execution_secs: f64,
24 /// P95 execution time in seconds
25 pub p95_execution_secs: f64,
26}
27
28/// Queue saturation monitoring
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct QueueSaturation {
31 /// Number of pending tasks
32 pub pending_count: i64,
33 /// Number of processing tasks
34 pub processing_count: i64,
35 /// Total tasks in all states
36 pub total_tasks: i64,
37 /// Configured capacity threshold
38 pub capacity_threshold: i64,
39 /// Utilization percentage (0-100)
40 pub utilization_percent: f64,
41 /// Whether queue is saturated (>= 80% of capacity)
42 pub is_saturated: bool,
43 /// Whether queue is critical (>= 95% of capacity)
44 pub is_critical: bool,
45 /// Status: healthy, warning, or critical
46 pub status: String,
47}
48
49/// Task latency percentiles for SLA monitoring
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct TaskLatencyPercentiles {
52 /// Number of tasks measured
53 pub task_count: i64,
54 /// P50 (median) latency in seconds
55 pub p50_latency_secs: f64,
56 /// P95 latency in seconds
57 pub p95_latency_secs: f64,
58 /// P99 latency in seconds
59 pub p99_latency_secs: f64,
60}
61
62/// Task state transition record
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct TaskStateTransition {
65 /// Task ID
66 pub task_id: TaskId,
67 /// Previous state (None if this is initial state)
68 pub from_state: Option<String>,
69 /// New state
70 pub to_state: String,
71 /// When the transition occurred
72 pub transitioned_at: chrono::DateTime<Utc>,
73}
74
75/// Task latency statistics
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct TaskLatencyStats {
78 /// Number of tasks measured
79 pub task_count: i64,
80 /// Minimum latency in seconds
81 pub min_latency_secs: f64,
82 /// Maximum latency in seconds
83 pub max_latency_secs: f64,
84 /// Average latency in seconds
85 pub avg_latency_secs: f64,
86 /// Standard deviation of latency in seconds
87 pub stddev_latency_secs: f64,
88}
89
90/// Priority queue statistics
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct PriorityQueueStats {
93 /// Priority level
94 pub priority: i32,
95 /// Number of pending tasks at this priority
96 pub pending_count: i64,
97 /// Number of processing tasks at this priority
98 pub processing_count: i64,
99 /// Number of completed tasks at this priority
100 pub completed_count: i64,
101 /// Number of failed tasks at this priority
102 pub failed_count: i64,
103 /// Average wait time in seconds for this priority
104 pub avg_wait_time_secs: f64,
105}
106
107/// Migration verification report
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct MigrationVerification {
110 /// Whether all required migrations are applied
111 pub is_complete: bool,
112 /// Number of migrations applied
113 pub applied_count: usize,
114 /// Number of migrations missing
115 pub missing_count: usize,
116 /// List of applied migration versions
117 pub applied_migrations: Vec<String>,
118 /// List of missing migration versions
119 pub missing_migrations: Vec<String>,
120 /// Whether core database schema is valid
121 pub schema_valid: bool,
122}
123
124/// Query performance profile
125#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct QueryPerformanceProfile {
127 /// Query digest (normalized query text)
128 pub query_digest: String,
129 /// Number of times executed
130 pub execution_count: i64,
131 /// Average execution time in milliseconds
132 pub avg_execution_time_ms: f64,
133 /// Total rows examined
134 pub total_rows_examined: i64,
135 /// Total rows sent
136 pub total_rows_sent: i64,
137 /// Number of executions without index
138 pub no_index_used_count: i64,
139 /// Number of executions with suboptimal index
140 pub no_good_index_used_count: i64,
141 /// Whether query needs optimization
142 pub needs_optimization: bool,
143}