Skip to main content

millipede_core/autoscale/
signal.rs

1use crate::errors::CrawlError;
2use std::time::Duration;
3use tokio::time::Instant;
4
5/// A point-in-time overload observation from a load signal.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct LoadSnapshot {
8    /// The Tokio-clock instant at which the observation was captured.
9    pub at: Instant,
10    /// Whether the signal was overloaded at that instant.
11    pub overloaded: bool,
12}
13
14/// A source of recent system or client load observations.
15#[async_trait::async_trait]
16pub trait LoadSignal: Send + Sync + 'static {
17    /// Returns the stable name of this signal.
18    fn name(&self) -> &str;
19
20    /// Returns the utilization threshold at which this signal is overloaded.
21    fn overload_threshold(&self) -> f32;
22
23    /// Starts any sampling work required by this signal.
24    async fn start(&self) -> Result<(), CrawlError> {
25        Ok(())
26    }
27
28    /// Stops any sampling work required by this signal.
29    async fn stop(&self) -> Result<(), CrawlError> {
30        Ok(())
31    }
32
33    /// Returns observations from the requested recent window.
34    fn sample(&self, window: Duration) -> Vec<LoadSnapshot>;
35}