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