Skip to content

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 key
  • agent_id: UUID, foreign key referencing the agents table
  • deployment_object_id: UUID, foreign key referencing the deployment_objects table
  • status: VARCHAR(20), health status (healthy, degraded, failing, unknown)
  • summary: TEXT, JSON-encoded health summary with pod counts and conditions
  • checked_at: TIMESTAMP, when the agent last checked health
  • created_at: TIMESTAMP, when the record was created
  • updated_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.

pub

Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema

Represents a deployment health record in the database.

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.

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema

Represents a new deployment health record to be inserted into the database.

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.

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,
})
}

pub

Derives: AsChangeset, Debug, Clone, Serialize, Deserialize

Represents an update to an existing deployment health record.

Name Type Description
status String Updated health status.
summary Option<String> Updated JSON-encoded summary.
checked_at DateTime<Utc> Updated check timestamp.

pub

Derives: Debug, Clone, Serialize, Deserialize, ToSchema

Structured health summary for serialization/deserialization.

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.

pub

Derives: Debug, Clone, Serialize, Deserialize, ToSchema

Health status for an individual Kubernetes resource.

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.
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"