datadog_agent_runtime/facade/config.rs
1//! The types a remote agent supplies to the facade.
2
3use std::future::Future;
4
5use datadog_agent_commons::ipc::config::RemoteAgentClientConfiguration;
6use saluki_app::accounting::MemoryBoundsConfiguration;
7use saluki_config::dynamic::ConfigUpdate;
8use saluki_error::GenericError;
9use saluki_io::net::ListenAddress;
10use tokio::sync::mpsc;
11
12use crate::{
13 control_plane::ConfigUpdatesRunner,
14 env::{HostSettings, WorkloadSettings},
15 logging::LoggingSettings,
16};
17
18/// The types that make up a remote agent.
19///
20/// A binary implements this on a marker type named after itself, such as `enum AgentDataPlane {}`, and drives the
21/// startup sequence with [`RemoteAgent<AgentDataPlane>`](super::RemoteAgent).
22pub trait RemoteAgentSpecification: Sized + 'static {
23 /// The configuration from local sources, loaded before the configuration authority is selected.
24 type LocalConfiguration: LocalConfiguration<Self>;
25
26 /// The configuration that results once the configuration authority is selected.
27 type AuthoritativeConfiguration: AuthoritativeConfiguration;
28
29 /// Applies the configuration updates that the Datadog Agent sends after its initial snapshot.
30 type ConfigurationUpdates: ConfigUpdatesRunner;
31}
32
33/// A remote agent's local configuration, loaded before it connects to the Datadog Agent.
34///
35/// This is the configuration from local sources only, such as a configuration file and environment variables. It
36/// decides whether the remote agent runs standalone, and how it reaches the Datadog Agent. It then becomes the remote
37/// agent's [`AuthoritativeConfiguration`], either by layering the Datadog Agent's configuration stream on top of it or,
38/// in standalone mode, on its own.
39pub trait LocalConfiguration<R: RemoteAgentSpecification>: Send + Sized + 'static {
40 /// Returns `true` if the remote agent runs without the Datadog Agent.
41 fn is_standalone(&self) -> bool;
42
43 /// Returns the configuration for connecting to the Datadog Agent.
44 ///
45 /// # Errors
46 ///
47 /// If the configuration is invalid, an error is returned.
48 fn client_configuration(&self) -> Result<RemoteAgentClientConfiguration, GenericError>;
49
50 /// Returns the secure API address that the remote agent advertises when it registers with the Datadog Agent.
51 ///
52 /// # Errors
53 ///
54 /// If the configured address is invalid, an error is returned.
55 fn advertised_secure_api_address(&self) -> Result<ListenAddress, GenericError>;
56
57 /// Selects the Datadog Agent's configuration stream as the configuration authority.
58 ///
59 /// Waits for the initial snapshot from `config_stream`, and returns the resulting configuration along with the
60 /// updates that apply each later snapshot.
61 ///
62 /// # Errors
63 ///
64 /// If the stream closes before its initial snapshot, or the resulting configuration is invalid, an error is
65 /// returned.
66 fn connect(
67 self, config_stream: mpsc::Receiver<ConfigUpdate>,
68 ) -> impl Future<Output = Result<(R::AuthoritativeConfiguration, R::ConfigurationUpdates), GenericError>> + Send;
69
70 /// Selects the local configuration as the configuration authority, for standalone mode.
71 ///
72 /// # Errors
73 ///
74 /// If the local configuration is invalid, an error is returned.
75 fn into_standalone(self) -> impl Future<Output = Result<R::AuthoritativeConfiguration, GenericError>> + Send;
76}
77
78/// A remote agent's authoritative configuration, available once the configuration authority is selected.
79pub trait AuthoritativeConfiguration: Send + Sync + 'static {
80 /// Returns `true` if the local configuration was selected as the configuration authority, for standalone mode.
81 fn is_standalone(&self) -> bool;
82
83 /// Returns the configuration for connecting to the Datadog Agent.
84 ///
85 /// # Errors
86 ///
87 /// If the configuration is invalid, an error is returned.
88 fn client_configuration(&self) -> Result<RemoteAgentClientConfiguration, GenericError>;
89
90 /// Returns the logging settings.
91 fn logging(&self) -> LoggingSettings;
92
93 /// Returns the settings for the workload provider.
94 fn workload(&self) -> WorkloadSettings;
95
96 /// Returns the settings for the host provider.
97 fn host(&self) -> HostSettings;
98
99 /// Returns `true` if Remote Configuration is enabled.
100 fn remote_config_enabled(&self) -> bool;
101
102 /// Returns the memory bounds configuration.
103 fn memory_bounds(&self) -> MemoryBoundsConfiguration;
104}