openzeppelin_relayer/models/health/
mod.rs

1//! Health check models and response types.
2//!
3//! This module contains all data structures used for health check endpoints,
4//! including component statuses, health information, and readiness responses.
5
6use serde::Serialize;
7use utoipa::ToSchema;
8
9/// Status of an individual Redis connection pool.
10#[derive(Debug, Clone, Serialize, ToSchema)]
11pub struct PoolStatus {
12    /// Whether the pool is connected and responding to PING.
13    pub connected: bool,
14    /// Number of available connections in the pool.
15    pub available: usize,
16    /// Maximum configured pool size.
17    pub max_size: usize,
18    /// Error message if the pool is not healthy.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    #[schema(nullable = false)]
21    pub error: Option<String>,
22}
23
24/// Component health status levels.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, ToSchema)]
26#[serde(rename_all = "lowercase")]
27pub enum ComponentStatus {
28    /// Component is fully operational.
29    Healthy,
30    /// Component is operational but with reduced capacity or fallback mode.
31    Degraded,
32    /// Component is not operational.
33    Unhealthy,
34}
35
36/// System health information (file descriptors, sockets).
37#[derive(Debug, Clone, Serialize, ToSchema)]
38pub struct SystemHealth {
39    pub status: ComponentStatus,
40    pub fd_count: usize,
41    pub fd_limit: usize,
42    pub fd_usage_percent: u32,
43    pub close_wait_count: usize,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[schema(nullable = false)]
46    pub error: Option<String>,
47}
48
49/// Redis health information.
50#[derive(Debug, Clone, Serialize, ToSchema)]
51pub struct RedisHealth {
52    pub status: ComponentStatus,
53    pub primary_pool: PoolStatus,
54    pub reader_pool: PoolStatus,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    #[schema(nullable = false)]
57    pub error: Option<String>,
58}
59
60/// Queue health information.
61#[derive(Debug, Clone, Serialize, ToSchema)]
62pub struct QueueHealth {
63    pub status: ComponentStatus,
64    #[serde(skip_serializing_if = "Option::is_none")]
65    #[schema(nullable = false)]
66    pub error: Option<String>,
67}
68
69/// Plugin health information.
70#[derive(Debug, Clone, Serialize, ToSchema)]
71pub struct PluginHealth {
72    pub status: ComponentStatus,
73    pub enabled: bool,
74    #[serde(skip_serializing_if = "Option::is_none")]
75    #[schema(nullable = false)]
76    pub circuit_state: Option<String>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    #[schema(nullable = false)]
79    pub error: Option<String>,
80    /// Plugin uptime in milliseconds
81    #[serde(skip_serializing_if = "Option::is_none")]
82    #[schema(nullable = false)]
83    pub uptime_ms: Option<u64>,
84    /// Memory usage in bytes
85    #[serde(skip_serializing_if = "Option::is_none")]
86    #[schema(nullable = false)]
87    pub memory: Option<u64>,
88    /// Number of completed tasks in the pool
89    #[serde(skip_serializing_if = "Option::is_none")]
90    #[schema(nullable = false)]
91    pub pool_completed: Option<u64>,
92    /// Number of queued tasks in the pool
93    #[serde(skip_serializing_if = "Option::is_none")]
94    #[schema(nullable = false)]
95    pub pool_queued: Option<u64>,
96    /// Success rate as a percentage (0.0-100.0)
97    #[serde(skip_serializing_if = "Option::is_none")]
98    #[schema(nullable = false)]
99    pub success_rate: Option<f64>,
100    /// Average response time in milliseconds
101    #[serde(skip_serializing_if = "Option::is_none")]
102    #[schema(nullable = false)]
103    pub avg_response_time_ms: Option<u32>,
104    /// Whether recovery mode is active
105    #[serde(skip_serializing_if = "Option::is_none")]
106    #[schema(nullable = false)]
107    pub recovering: Option<bool>,
108    /// Current recovery allowance percentage
109    #[serde(skip_serializing_if = "Option::is_none")]
110    #[schema(nullable = false)]
111    pub recovery_percent: Option<u32>,
112    /// Shared socket available connection slots
113    #[serde(skip_serializing_if = "Option::is_none")]
114    #[schema(nullable = false)]
115    pub shared_socket_available_slots: Option<usize>,
116    /// Shared socket active connection count
117    #[serde(skip_serializing_if = "Option::is_none")]
118    #[schema(nullable = false)]
119    pub shared_socket_active_connections: Option<usize>,
120    /// Shared socket registered execution count
121    #[serde(skip_serializing_if = "Option::is_none")]
122    #[schema(nullable = false)]
123    pub shared_socket_registered_executions: Option<usize>,
124    /// Connection pool available slots (for pool server connections)
125    #[serde(skip_serializing_if = "Option::is_none")]
126    #[schema(nullable = false)]
127    pub connection_pool_available_slots: Option<usize>,
128    /// Connection pool active connections (for pool server connections)
129    #[serde(skip_serializing_if = "Option::is_none")]
130    #[schema(nullable = false)]
131    pub connection_pool_active_connections: Option<usize>,
132}
133
134/// All health check components.
135#[derive(Debug, Clone, Serialize, ToSchema)]
136pub struct Components {
137    pub system: SystemHealth,
138    pub redis: RedisHealth,
139    pub queue: QueueHealth,
140    #[serde(skip_serializing_if = "Option::is_none")]
141    #[schema(nullable = false)]
142    pub plugins: Option<PluginHealth>,
143}
144
145/// Complete readiness response.
146#[derive(Debug, Clone, Serialize, ToSchema)]
147pub struct ReadinessResponse {
148    pub ready: bool,
149    pub status: ComponentStatus,
150    #[serde(skip_serializing_if = "Option::is_none")]
151    #[schema(nullable = false)]
152    pub reason: Option<String>,
153    pub components: Components,
154    pub timestamp: String,
155}
156
157/// Health status of Redis connections (primary and reader pools).
158///
159/// This is an intermediate structure used internally by health check functions
160/// before being converted to the public `RedisHealth` model.
161#[derive(Debug, Clone)]
162pub struct RedisHealthStatus {
163    /// Overall health status.
164    pub healthy: bool,
165    /// Primary pool status.
166    pub primary_pool: PoolStatus,
167    /// Reader pool status.
168    pub reader_pool: PoolStatus,
169    /// Error message if unhealthy.
170    pub error: Option<String>,
171}
172
173/// Health status of Queue's Redis connection.
174///
175/// This is an intermediate structure used internally by health check functions
176/// before being converted to the public `QueueHealth` model.
177#[derive(Debug, Clone)]
178pub struct QueueHealthStatus {
179    /// Overall health status.
180    pub healthy: bool,
181    /// Error message if unhealthy.
182    pub error: Option<String>,
183}