headless_lms_server/domain/system_health/
mod.rs1pub mod health_check;
4pub mod kubernetes;
5
6pub use health_check::{check_system_health, check_system_health_detailed};
7pub use kubernetes::{
8 get_cronjobs, get_deployments, get_events, get_ingresses, get_jobs, get_pod_disruption_budgets,
9 get_pod_logs, get_pods, get_services,
10};
11
12use serde::{Deserialize, Serialize};
13use std::collections::HashMap;
14#[cfg(feature = "ts_rs")]
15use ts_rs::TS;
16
17#[derive(Debug, Serialize, Deserialize)]
18#[cfg_attr(feature = "ts_rs", derive(TS))]
19pub struct PodInfo {
20 pub name: String,
21 pub phase: String,
22 pub ready: Option<bool>,
23 pub labels: HashMap<String, String>,
24}
25
26#[derive(Debug, Serialize, Deserialize)]
27#[cfg_attr(feature = "ts_rs", derive(TS))]
28pub struct DeploymentInfo {
29 pub name: String,
30 pub replicas: i32,
31 pub ready_replicas: i32,
32 pub selector_labels: HashMap<String, String>,
33}
34
35#[derive(Debug, Serialize, Deserialize)]
36#[cfg_attr(feature = "ts_rs", derive(TS))]
37pub struct CronJobInfo {
38 pub name: String,
39 pub schedule: String,
40 pub last_schedule_time: Option<String>,
41}
42
43#[derive(Debug, Serialize, Deserialize)]
44#[cfg_attr(feature = "ts_rs", derive(TS))]
45pub struct JobInfo {
46 pub name: String,
47 pub succeeded: Option<i32>,
48 pub failed: Option<i32>,
49 pub active: Option<i32>,
50}
51
52#[derive(Debug, Serialize, Deserialize)]
53#[cfg_attr(feature = "ts_rs", derive(TS))]
54pub struct ServiceInfo {
55 pub name: String,
56 pub cluster_ip: Option<String>,
57 pub ports: Vec<ServicePortInfo>,
58}
59
60#[derive(Debug, Serialize, Deserialize)]
61#[cfg_attr(feature = "ts_rs", derive(TS))]
62pub struct ServicePortInfo {
63 pub name: Option<String>,
64 pub port: i32,
65 pub target_port: Option<String>,
66 pub protocol: Option<String>,
67}
68
69#[derive(Debug, Serialize, Deserialize)]
70#[cfg_attr(feature = "ts_rs", derive(TS))]
71pub struct EventInfo {
72 pub name: String,
73 pub reason: Option<String>,
74 pub message: Option<String>,
75 pub type_: Option<String>,
76 pub first_timestamp: Option<String>,
77 pub last_timestamp: Option<String>,
78 pub count: Option<i32>,
79 pub involved_object_kind: Option<String>,
80 pub involved_object_name: Option<String>,
81}
82
83#[derive(Debug, Serialize, Deserialize)]
84#[cfg_attr(feature = "ts_rs", derive(TS))]
85pub struct IngressInfo {
86 pub name: String,
87 pub hosts: Vec<String>,
88 pub paths: Vec<String>,
89 pub class_name: Option<String>,
90}
91
92#[derive(Debug, Serialize, Deserialize)]
93#[cfg_attr(feature = "ts_rs", derive(TS))]
94pub struct PodDisruptionBudgetInfo {
95 pub name: String,
96 pub current_healthy: i32,
97 pub desired_healthy: i32,
98 pub disruptions_allowed: i32,
99 pub expected_pods: i32,
100 pub selector_labels: HashMap<String, String>,
101}
102
103#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
104#[cfg_attr(feature = "ts_rs", derive(TS))]
105#[serde(rename_all = "lowercase")]
106pub enum HealthStatus {
107 Healthy,
108 Warning,
109 Error,
110}
111
112#[derive(Debug, Serialize, Deserialize)]
113#[cfg_attr(feature = "ts_rs", derive(TS))]
114pub struct SystemHealthStatus {
115 pub status: HealthStatus,
116 pub issues: Vec<String>,
117}
118
119pub fn get_namespace() -> String {
120 std::env::var("POD_NAMESPACE").unwrap_or_else(|_| "default".to_string())
121}