Skip to main content

a3s_box_runtime/scale/
mod.rs

1//! Scale Manager — Tracks instances per service and processes scale requests.
2//!
3//! Manages the mapping between services and their running instances,
4//! handles scale-up/scale-down decisions, and emits instance state events.
5
6use a3s_box_core::scale::{InstanceHealth, InstanceState};
7use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9
10mod manager;
11mod registry;
12
13#[cfg(test)]
14mod tests;
15
16// Re-export public types
17pub use manager::ScaleManager;
18pub use registry::InstanceRegistry;
19
20/// Instances belonging to a single service.
21#[derive(Debug, Clone)]
22pub(super) struct ServiceInstances {
23    /// Target replica count
24    pub(super) target_replicas: u32,
25    /// Active instances
26    pub(super) instances: Vec<TrackedInstance>,
27}
28
29/// A tracked instance with its current state.
30#[derive(Debug, Clone)]
31pub(super) struct TrackedInstance {
32    pub(super) id: String,
33    pub(super) state: InstanceState,
34    pub(super) created_at: DateTime<Utc>,
35    pub(super) ready_at: Option<DateTime<Utc>>,
36    pub(super) endpoint: Option<String>,
37    pub(super) health: InstanceHealth,
38}
39
40/// Aggregated health metrics for a service.
41#[derive(Debug, Clone, Default, Serialize, Deserialize)]
42pub struct ServiceHealth {
43    /// Number of active instances (Ready + Busy)
44    pub active_instances: u32,
45    /// Number of Ready instances
46    pub ready_instances: u32,
47    /// Number of Busy instances
48    pub busy_instances: u32,
49    /// Average CPU usage across active instances
50    pub avg_cpu_percent: Option<f32>,
51    /// Total memory usage across all active instances
52    pub total_memory_bytes: u64,
53    /// Total in-flight requests across all active instances
54    pub total_inflight_requests: u32,
55    /// Number of unhealthy instances
56    pub unhealthy_instances: u32,
57}