brokkr-agent::health Rust
Structs
brokkr-agent::health::HealthState
pub
Derives: Clone
Shared state for health endpoints
Fields
| Name | Type | Description |
|---|---|---|
k8s_client | Client | |
broker_status | Arc < RwLock < BrokerStatus > > | |
start_time | SystemTime |
brokkr-agent::health::BrokerStatus
pub
Derives: Clone
Broker connection status
Fields
| Name | Type | Description |
|---|---|---|
connected | bool | |
last_heartbeat | Option < String > |
brokkr-agent::health::HealthStatus
private
Derives: Serialize
Health status response structure
Fields
| Name | Type | Description |
|---|---|---|
status | String | |
kubernetes | KubernetesStatus | |
broker | BrokerStatusResponse | |
uptime_seconds | u64 | |
version | String | |
timestamp | String |
brokkr-agent::health::KubernetesStatus
private
Derives: Serialize
Kubernetes health status
Fields
| Name | Type | Description |
|---|---|---|
connected | bool | |
error | Option < String > |
brokkr-agent::health::BrokerStatusResponse
private
Derives: Serialize
Broker health status for response
Fields
| Name | Type | Description |
|---|---|---|
connected | bool | |
last_heartbeat | Option < String > |
Functions
brokkr-agent::health::configure_health_routes
pub
#![allow(unused)]
fn main() {
fn configure_health_routes (state : HealthState) -> Router
}
Configures and returns the health check router
Source
#![allow(unused)]
fn main() {
pub fn configure_health_routes(state: HealthState) -> Router {
Router::new()
.route("/healthz", get(healthz))
.route("/readyz", get(readyz))
.route("/health", get(health))
.route("/metrics", get(metrics_handler))
.with_state(state)
}
}
brokkr-agent::health::healthz
private
#![allow(unused)]
fn main() {
async fn healthz () -> impl IntoResponse
}
Simple liveness check endpoint
Returns 200 OK if the process is running. This is used for Kubernetes liveness probes.
Source
#![allow(unused)]
fn main() {
async fn healthz() -> impl IntoResponse {
(StatusCode::OK, "OK")
}
}
brokkr-agent::health::readyz
private
#![allow(unused)]
fn main() {
async fn readyz (State (state) : State < HealthState >) -> impl IntoResponse
}
Readiness check endpoint
Validates Kubernetes API connectivity. Returns 200 OK if K8s API is accessible, 503 if not.
Source
#![allow(unused)]
fn main() {
async fn readyz(State(state): State<HealthState>) -> impl IntoResponse {
// Test Kubernetes API connectivity by checking API health
match state.k8s_client.apiserver_version().await {
Ok(_) => (StatusCode::OK, "Ready"),
Err(e) => {
error!("Kubernetes API connectivity check failed: {:?}", e);
(
StatusCode::SERVICE_UNAVAILABLE,
"Kubernetes API unavailable",
)
}
}
}
}
brokkr-agent::health::health
private
#![allow(unused)]
fn main() {
async fn health (State (state) : State < HealthState >) -> impl IntoResponse
}
Detailed health check endpoint
Provides comprehensive JSON status including:
- Kubernetes API connectivity
- Broker connection status
- Service uptime
- Application version
- Timestamp Returns 200 OK if all checks pass, 503 if any check fails.
Source
#![allow(unused)]
fn main() {
async fn health(State(state): State<HealthState>) -> impl IntoResponse {
// Get current timestamp
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards");
let timestamp = chrono::Utc::now().to_rfc3339();
// Calculate uptime
let uptime = now.as_secs().saturating_sub(
state
.start_time
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_secs(),
);
// Check Kubernetes API connectivity
let (k8s_connected, k8s_error) = match state.k8s_client.apiserver_version().await {
Ok(_) => (true, None),
Err(e) => {
error!("Kubernetes API connectivity check failed: {:?}", e);
(false, Some(format!("{:?}", e)))
}
};
// Get broker status
let broker_status = state.broker_status.read().await;
let broker_connected = broker_status.connected;
let broker_last_heartbeat = broker_status.last_heartbeat.clone();
// Determine overall status
let overall_status = if k8s_connected && broker_connected {
"healthy"
} else {
"unhealthy"
};
let status_code = if k8s_connected && broker_connected {
StatusCode::OK
} else {
StatusCode::SERVICE_UNAVAILABLE
};
let health_status = HealthStatus {
status: overall_status.to_string(),
kubernetes: KubernetesStatus {
connected: k8s_connected,
error: k8s_error,
},
broker: BrokerStatusResponse {
connected: broker_connected,
last_heartbeat: broker_last_heartbeat,
},
uptime_seconds: uptime,
version: env!("CARGO_PKG_VERSION").to_string(),
timestamp,
};
(status_code, Json(health_status))
}
}
brokkr-agent::health::metrics_handler
private
#![allow(unused)]
fn main() {
async fn metrics_handler () -> impl IntoResponse
}
Prometheus metrics endpoint
Returns Prometheus metrics in text exposition format. Metrics include broker polling, Kubernetes operations, and agent health.
Source
#![allow(unused)]
fn main() {
async fn metrics_handler() -> impl IntoResponse {
let metrics_data = metrics::encode_metrics();
(
StatusCode::OK,
[("Content-Type", "text/plain; version=0.0.4")],
metrics_data,
)
}
}