brokkr-models::models::deployment_health
Rust
Deployment Health Module
This module defines structures and methods for tracking deployment health status.
Data Model
Deployment health records track the health status of deployments on a per-agent basis. Each agent that applies a deployment object has its own health record, since the same deployment may have different health on different clusters.
id: UUID, primary keyagent_id: UUID, foreign key referencing theagentstabledeployment_object_id: UUID, foreign key referencing thedeployment_objectstablestatus: VARCHAR(20), health status (healthy, degraded, failing, unknown)summary: TEXT, JSON-encoded health summary with pod counts and conditionschecked_at: TIMESTAMP, when the agent last checked healthcreated_at: TIMESTAMP, when the record was createdupdated_at: TIMESTAMP, when the record was last updated
Usage
Agents periodically check the health of deployed resources and report status to the broker. This enables operators to see at-a-glance health across all deployments without direct cluster access.
Structs
Section titled “Structs”struct DeploymentHealth
Section titled “struct DeploymentHealth”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema
Represents a deployment health record in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the health record. |
agent_id |
Uuid |
ID of the agent that reported this health status. |
deployment_object_id |
Uuid |
ID of the deployment object this health status applies to. |
status |
String |
Health status: healthy, degraded, failing, or unknown. |
summary |
Option<String> |
JSON-encoded summary with pod counts, conditions, and resource details. |
checked_at |
DateTime<Utc> |
Timestamp when the agent last checked health. |
created_at |
DateTime<Utc> |
Timestamp when the record was created. |
updated_at |
DateTime<Utc> |
Timestamp when the record was last updated. |
struct NewDeploymentHealth
Section titled “struct NewDeploymentHealth”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new deployment health record to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
ID of the agent reporting this health status. |
deployment_object_id |
Uuid |
ID of the deployment object this health status applies to. |
status |
String |
Health status: healthy, degraded, failing, or unknown. |
summary |
Option<String> |
JSON-encoded summary with pod counts, conditions, and resource details. |
checked_at |
DateTime<Utc> |
Timestamp when the agent checked health. |
Methods
Section titled “Methods”pub
fn new( agent_id: Uuid, deployment_object_id: Uuid, status: String, summary: Option<String>, checked_at: DateTime<Utc>,) -> Result<Self, String>Creates a new NewDeploymentHealth instance.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
UUID of the agent reporting health. |
deployment_object_id |
Uuid |
UUID of the deployment object. |
status |
String |
Health status (healthy, degraded, failing, unknown). |
summary |
Option<String> |
Optional JSON-encoded health summary. |
checked_at |
DateTime<Utc> |
When the health was checked. |
Returns:
Returns Ok(NewDeploymentHealth) if all parameters are valid,
otherwise returns an Err with a description of the validation failure.
Source
pub fn new( agent_id: Uuid, deployment_object_id: Uuid, status: String, summary: Option<String>, checked_at: DateTime<Utc>, ) -> Result<Self, String> { // Validate agent_id if agent_id.is_nil() { return Err("Invalid agent ID".to_string()); }
// Validate deployment_object_id if deployment_object_id.is_nil() { return Err("Invalid deployment object ID".to_string()); }
// Validate status if !VALID_HEALTH_STATUSES.contains(&status.as_str()) { return Err(format!( "Invalid health status. Must be one of: {}", VALID_HEALTH_STATUSES.join(", ") )); }
Ok(NewDeploymentHealth { agent_id, deployment_object_id, status, summary, checked_at, }) }struct UpdateDeploymentHealth
Section titled “struct UpdateDeploymentHealth”pub
Derives: AsChangeset, Debug, Clone, Serialize, Deserialize
Represents an update to an existing deployment health record.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
status |
String |
Updated health status. |
summary |
Option<String> |
Updated JSON-encoded summary. |
checked_at |
DateTime<Utc> |
Updated check timestamp. |
struct HealthSummary
Section titled “struct HealthSummary”pub
Derives: Debug, Clone, Serialize, Deserialize, ToSchema
Structured health summary for serialization/deserialization.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
pods_ready |
i32 |
Number of pods in ready state. |
pods_total |
i32 |
Total number of pods. |
conditions |
Vec<String> |
List of detected problematic conditions (e.g., ImagePullBackOff). |
resources |
Option<Vec<ResourceHealth>> |
Optional detailed resource status. |
struct ResourceHealth
Section titled “struct ResourceHealth”pub
Derives: Debug, Clone, Serialize, Deserialize, ToSchema
Health status for an individual Kubernetes resource.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
kind |
String |
Resource kind (e.g., Deployment, StatefulSet). |
name |
String |
Resource name. |
namespace |
String |
Resource namespace. |
ready |
bool |
Whether the resource is ready. |
message |
Option<String> |
Optional status message. |
Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
HEALTH_STATUS_HEALTHY |
&str |
"healthy" |
Valid health status values |
HEALTH_STATUS_DEGRADED |
&str |
"degraded" |
|
HEALTH_STATUS_FAILING |
&str |
"failing" |
|
HEALTH_STATUS_UNKNOWN |
&str |
"unknown" |