Skip to main content

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    /// Additional gRPC services advertised during registration and served on the privileged API endpoint.
33    const ADDITIONAL_SERVICE_NAMES: &'static [&'static str] = &[];
34}
35
36/// A remote agent's local configuration, loaded before it connects to the Datadog Agent.
37///
38/// This is the configuration from local sources only, such as a configuration file and environment variables. It
39/// decides whether the remote agent runs standalone, and how it reaches the Datadog Agent. It then becomes the remote
40/// agent's [`AuthoritativeConfiguration`], either by layering the Datadog Agent's configuration stream on top of it or,
41/// in standalone mode, on its own.
42pub trait LocalConfiguration<R: RemoteAgentSpecification>: Send + Sized + 'static {
43    /// Returns `true` if the remote agent runs without the Datadog Agent.
44    fn is_standalone(&self) -> bool;
45
46    /// Returns the configuration for connecting to the Datadog Agent.
47    ///
48    /// # Errors
49    ///
50    /// If the configuration is invalid, an error is returned.
51    fn client_configuration(&self) -> Result<RemoteAgentClientConfiguration, GenericError>;
52
53    /// Returns the secure API address that the remote agent advertises when it registers with the Datadog Agent.
54    ///
55    /// # Errors
56    ///
57    /// If the configured address is invalid, an error is returned.
58    fn advertised_secure_api_address(&self) -> Result<ListenAddress, GenericError>;
59
60    /// Selects the Datadog Agent's configuration stream as the configuration authority.
61    ///
62    /// Waits for the initial snapshot from `config_stream`, and returns the resulting configuration along with the
63    /// updates that apply each later snapshot.
64    ///
65    /// # Errors
66    ///
67    /// If the stream closes before its initial snapshot, or the resulting configuration is invalid, an error is
68    /// returned.
69    fn connect(
70        self, config_stream: mpsc::Receiver<ConfigUpdate>,
71    ) -> impl Future<Output = Result<(R::AuthoritativeConfiguration, R::ConfigurationUpdates), GenericError>> + Send;
72
73    /// Selects the local configuration as the configuration authority, for standalone mode.
74    ///
75    /// # Errors
76    ///
77    /// If the local configuration is invalid, an error is returned.
78    fn into_standalone(self) -> impl Future<Output = Result<R::AuthoritativeConfiguration, GenericError>> + Send;
79}
80
81/// A remote agent's authoritative configuration, available once the configuration authority is selected.
82pub trait AuthoritativeConfiguration: Send + Sync + 'static {
83    /// Returns `true` if the local configuration was selected as the configuration authority, for standalone mode.
84    fn is_standalone(&self) -> bool;
85
86    /// Returns the configuration for connecting to the Datadog Agent.
87    ///
88    /// # Errors
89    ///
90    /// If the configuration is invalid, an error is returned.
91    fn client_configuration(&self) -> Result<RemoteAgentClientConfiguration, GenericError>;
92
93    /// Returns the logging settings.
94    fn logging(&self) -> LoggingSettings;
95
96    /// Returns the settings for the workload provider.
97    fn workload(&self) -> WorkloadSettings;
98
99    /// Returns the settings for the host provider.
100    fn host(&self) -> HostSettings;
101
102    /// Returns `true` if Remote Configuration is enabled.
103    fn remote_config_enabled(&self) -> bool;
104
105    /// Returns the memory bounds configuration.
106    fn memory_bounds(&self) -> MemoryBoundsConfiguration;
107}