Skip to main content

datadog_agent_runtime/facade/
stage.rs

1//! The stages of the remote agent startup sequence.
2//!
3//! [`RemoteAgent`](super::RemoteAgent) takes one of these as its stage parameter, which determines the methods it
4//! offers.
5
6use std::time::Instant;
7
8use datadog_agent_remote_config::{RemoteConfigurationClient, RemoteConfigurationWorker};
9use saluki_core::{
10    accounting::ComponentRegistry,
11    health::HealthRegistry,
12    runtime::{state::ResourceRegistry, Supervisor},
13};
14
15use super::RemoteAgentSpecification;
16use crate::{env::RemoteAgentEnvironmentProvider, logging::LoggingTranslator, remote_agent::RemoteAgentBootstrap};
17
18/// A remote agent that hasn't started yet.
19pub enum Unstarted {}
20
21/// A remote agent whose configuration authority is selected.
22///
23/// The binary can inspect its configuration here, and stop before anything else starts.
24pub enum Started {}
25
26/// A remote agent with its registries and environment provider in place.
27///
28/// The binary builds its topology and its control plane supervisor here, and then runs the remote agent.
29pub enum Initialized {}
30
31mod sealed {
32    pub trait Sealed {}
33
34    impl Sealed for super::Unstarted {}
35    impl Sealed for super::Started {}
36    impl Sealed for super::Initialized {}
37}
38
39/// A stage of the remote agent startup sequence.
40///
41/// This trait is sealed, and only implemented by the stages in this module.
42pub trait Stage: sealed::Sealed {
43    /// The state that the remote agent holds in this stage.
44    #[doc(hidden)]
45    type Data<R: RemoteAgentSpecification>;
46}
47
48impl Stage for Unstarted {
49    type Data<R: RemoteAgentSpecification> = data::UnstartedData<R>;
50}
51
52impl Stage for Started {
53    type Data<R: RemoteAgentSpecification> = data::StartedData<R>;
54}
55
56impl Stage for Initialized {
57    type Data<R: RemoteAgentSpecification> = data::InitializedData<R>;
58}
59
60pub(super) use self::data::{InitializedData, StartedData, UnstartedData};
61
62mod data {
63    use super::*;
64
65    pub struct UnstartedData<R: RemoteAgentSpecification> {
66        pub local: R::LocalConfiguration,
67        pub translator: LoggingTranslator,
68        pub start_time: Instant,
69    }
70
71    pub struct StartedData<R: RemoteAgentSpecification> {
72        pub config: R::AuthoritativeConfiguration,
73        pub ra_bootstrap: Option<RemoteAgentBootstrap>,
74        pub config_updates: Option<R::ConfigurationUpdates>,
75        pub bootstrap_supervisor: Supervisor,
76        pub start_time: Instant,
77    }
78
79    pub struct InitializedData<R: RemoteAgentSpecification> {
80        pub started: StartedData<R>,
81        pub root_supervisor: Supervisor,
82        pub component_registry: ComponentRegistry,
83        pub health_registry: HealthRegistry,
84        pub resource_registry: ResourceRegistry,
85        pub env_provider: RemoteAgentEnvironmentProvider,
86        pub env_supervisor: Option<Supervisor>,
87        pub remote_config: Option<(RemoteConfigurationClient, RemoteConfigurationWorker)>,
88    }
89}