agent_data_plane_config/control.rs
1//! Topology gates, orchestration decisions and application configuration.
2//!
3//! `ControlConfiguration` is read only by config-system and the topology builder, not by
4//! components. It carries pipeline activation gates, topology-shaping decisions, listen addresses,
5//! logging (read before topology exists), bootstrap IPC parameters, and process-lifecycle knobs.
6
7use std::{num::NonZeroUsize, path::PathBuf, time::Duration};
8
9use serde::Serialize;
10
11use crate::{defaults::DEFAULT_REMOTE_AGENT_STRING_INTERNER_SIZE_BYTES, ConfigValue};
12
13/// Topology gates and orchestration decisions. Most are static; `logging.level` is live.
14///
15/// The derived `Default` is all zeroes, empty, and `false`, and serves only as the starting point for translation. The
16/// effective default of each field is the one translation resolves, noted per field below.
17#[derive(Clone, Debug, Default, PartialEq, Serialize)]
18pub struct ControlConfiguration {
19 /// Master switch for the whole data plane; when false, no pipelines are built.
20 pub enabled: bool,
21
22 /// Whether the DogStatsD metrics pipeline is built.
23 pub dogstatsd: bool,
24
25 /// Whether the checks metrics pipeline is built. (not in Datadog Agent config schema)
26 pub checks: bool,
27
28 /// Whether the OTLP pipeline is built.
29 pub otlp: bool,
30
31 /// Whether the logs agent is enabled: `logs_enabled`, or its deprecated spelling `log_enabled`.
32 ///
33 /// Defaults to `false`.
34 pub logs_enabled: bool,
35
36 /// Whether the experimental APM proxy runs in front of the trace-agent. (not in Datadog Agent
37 /// config schema)
38 ///
39 /// Defaults to `false`. See [`domains::apm`](crate::domains::apm).
40 pub apm: bool,
41
42 /// Whether standalone mode is active, running without a core Agent. (not in Datadog Agent
43 /// config schema)
44 pub standalone_mode: bool,
45
46 /// Whether the process registers itself with the core Agent as a remote agent.
47 pub remote_agent_enabled: bool,
48
49 /// Whether to subscribe to core Agent configuration updates over the newer config-stream
50 /// endpoint.
51 pub use_new_config_stream_endpoint: bool,
52
53 /// Address the unsecured control API listens on.
54 pub api_listen_address: String,
55
56 /// Address the mutually authenticated control API listens on. Every HTTP and gRPC client must
57 /// present the exact configured Agent IPC certificate during the TLS handshake.
58 pub secure_api_listen_address: String,
59
60 /// Logging configuration, read before runtime authority exists.
61 pub logging: Logging,
62
63 /// Bootstrap IPC and remote-agent connection parameters.
64 pub ipc: ControlIpc,
65
66 /// Grace period the aggregator is given to flush before shutdown.
67 pub aggregator_stop_timeout: Duration,
68
69 /// Override for the topology shutdown grace period.
70 ///
71 /// Defaults to `None`. When absent, the topology timeout is the sum of
72 /// `aggregator_stop_timeout` and `forwarder_stop_timeout`.
73 pub stop_timeout: Option<Duration>,
74
75 /// Process memory ceiling, in bytes, that bounds validation and the global limiter work against.
76 ///
77 /// Defaults to `None`. When absent, ADP reads the ceiling from the process cgroup, but only when `DOCKER_DD_AGENT`
78 /// is set to a non-empty value. When neither source supplies a value, bounds validation is skipped and the global
79 /// limiter never exerts backpressure, whatever `memory_mode` and `enable_global_limiter` say.
80 ///
81 /// `Some(0)` is a ceiling of zero bytes rather than "no ceiling": every component bound then exceeds it, which is
82 /// fatal under [`MemoryMode::Strict`]. A ceiling above 2^53 bytes is rejected during startup.
83 ///
84 /// Set this to the memory the process is allowed to use, and leave it unset only where cgroup detection supplies
85 /// that number.
86 pub memory_limit: Option<u64>,
87
88 /// Fraction of `memory_limit` held back as headroom for memory the component bounds do not account for.
89 ///
90 /// Defaults to [`DEFAULT_MEMORY_SLOP_FACTOR`](crate::defaults::DEFAULT_MEMORY_SLOP_FACTOR) (`0.25`), which
91 /// validates bounds against 75% of `memory_limit`. Valid values run from `0.0` up to but excluding `1.0`, where
92 /// `0.0` holds nothing back. A value outside that range, including `NaN`, fails startup once a memory ceiling
93 /// resolves, and goes unused when none does.
94 ///
95 /// Raise this for a workload whose real usage overshoots its validated bounds; lower it to hand more of a tight
96 /// ceiling to the components that do account for their usage.
97 pub memory_slop_factor: f64,
98
99 /// Whether the global memory limiter exerts backpressure as usage approaches the effective ceiling.
100 ///
101 /// Defaults to [`DEFAULT_ENABLE_GLOBAL_LIMITER`](crate::defaults::DEFAULT_ENABLE_GLOBAL_LIMITER) (`true`). When
102 /// `false`, the limiter is a no-op: it throttles nothing, and only the components' own bounds hold memory usage
103 /// down. Either way it does nothing unless a memory ceiling resolves and `memory_mode` is
104 /// [`MemoryMode::Permissive`] or [`MemoryMode::Strict`], because no other case installs a limiter.
105 ///
106 /// Turn this off to attribute a throughput drop to memory backpressure, accepting that the process can then run
107 /// past `memory_limit`.
108 pub enable_global_limiter: bool,
109
110 /// How the component memory bounds are reconciled with the effective memory ceiling during startup.
111 ///
112 /// Defaults to [`MemoryMode::Disabled`]. Validation runs only when a memory ceiling resolves; without one,
113 /// `Permissive` and `Strict` log that validation was skipped and startup continues.
114 ///
115 /// Run `Permissive` first to learn whether a ceiling fits the topology, then move to `Strict` where the platform
116 /// kills a process that exceeds its ceiling and refusing to start is the better failure.
117 pub memory_mode: MemoryMode,
118}
119
120/// Memory bounds validation and limiter behavior.
121#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
122#[serde(rename_all = "lowercase")]
123pub enum MemoryMode {
124 /// Bounds validation is skipped and no limiter is installed, whatever `enable_global_limiter` says.
125 #[default]
126 Disabled,
127
128 /// Bounds that do not fit the ceiling are logged as a warning and startup continues.
129 ///
130 /// Memory limiting is best effort: the limiter is installed when a ceiling resolves and
131 /// `enable_global_limiter` is `true`.
132 Permissive,
133
134 /// Bounds that do not fit the ceiling fail startup.
135 ///
136 /// The limiter is installed on the same terms as [`MemoryMode::Permissive`].
137 Strict,
138}
139
140impl ControlConfiguration {
141 /// Derived decision the topology builder reads. The outbound Datadog forwarder is needed only
142 /// if some pipeline that emits to Datadog is enabled.
143 pub fn requires_datadog_forwarder(&self) -> bool {
144 self.dogstatsd || self.checks || self.otlp
145 }
146}
147
148/// Logging configuration, read before runtime authority exists.
149#[derive(Clone, Debug, Default, PartialEq, Serialize)]
150pub struct Logging {
151 /// Minimum severity a record must reach to be emitted.
152 pub level: String,
153
154 /// Whether log timestamps are formatted as RFC 3339.
155 pub format_rfc3339: bool,
156
157 /// Whether log records are emitted as JSON.
158 pub format_json: bool,
159
160 /// Whether logs are written to the console.
161 pub to_console: bool,
162
163 /// Whether logs are forwarded to syslog.
164 pub to_syslog: bool,
165
166 /// Whether syslog messages use the RFC 5424 framing.
167 pub syslog_rfc: bool,
168
169 /// Destination URI for syslog forwarding.
170 pub syslog_uri: String,
171
172 /// Path of the log file.
173 ///
174 /// A defaulted or explicitly empty path selects the platform-specific ADP log file path.
175 pub file: ConfigValue<String>,
176
177 /// Whether file logging is turned off entirely.
178 pub disable_file_logging: bool,
179
180 /// Number of rotated log files retained.
181 ///
182 /// Defaults to `1`. The file writer retains one rotated file when this is `0`. A negative value is
183 /// rejected during translation.
184 pub file_max_rolls: usize,
185
186 /// Maximum size, in bytes, a log file reaches before it is rotated.
187 ///
188 /// When defaulted, the logging stack keeps its own 10 MiB threshold instead.
189 pub file_max_size: ConfigValue<u64>,
190}
191
192/// IPC and remote-agent connection parameters, read once at bootstrap before runtime authority
193/// exists and again from the authoritative configuration once it does.
194///
195/// Witnessed fields get their effective defaults during translation. The Saluki-only interner
196/// budget uses its Rust `Default`.
197#[derive(Clone, Debug, PartialEq, Serialize)]
198pub struct ControlIpc {
199 /// Path to the Agent authentication token file.
200 ///
201 /// ADP sends the file contents as a bearer token to the Core Agent. Override this path only when the Core Agent
202 /// uses a non-default token path, and configure both processes to use the same token.
203 ///
204 /// Defaults to an empty path, which selects the platform-specific Agent authentication token path.
205 pub auth_token_file_path: PathBuf,
206
207 /// Path to the shared Agent IPC mTLS identity file.
208 ///
209 /// The PEM file contains the certificate and private key used by ADP and its IPC peers. Every peer must use the
210 /// same identity because authentication requires an exact certificate match. Override this path only when the Core
211 /// Agent uses a non-default identity path.
212 ///
213 /// Defaults to an empty path, which selects `ipc_cert.pem` beside the resolved authentication token path.
214 pub ipc_cert_file_path: PathBuf,
215
216 /// Host the command API listens on.
217 ///
218 /// This is the effective host: like the Datadog Agent, the deprecated `ipc_address` takes precedence when it's
219 /// explicitly set, and `cmd_host` is used otherwise.
220 ///
221 /// Defaults to `localhost`.
222 pub cmd_host: String,
223
224 /// TCP port the command API listens on.
225 ///
226 /// Defaults to `5001`.
227 pub cmd_port: u16,
228
229 /// vsock address used for guest/host IPC.
230 ///
231 /// Defaults to empty, which reaches the Core Agent over TCP at `cmd_host` and `cmd_port`.
232 pub vsock_addr: String,
233
234 /// Maximum gRPC message size, in bytes, accepted over the remote-agent IPC channel.
235 ///
236 /// Defaults to `134217728` (128 MiB).
237 pub grpc_max_message_size: usize,
238
239 /// Byte budget for the remote-agent workload metadata string interner. (not in Datadog Agent config schema)
240 ///
241 /// The workload provider interns entity IDs and tags into a single allocation of this size, taken at startup and
242 /// charged in full against the memory bounds ceiling. A workload whose tag cardinality outgrows the budget starts
243 /// failing to intern, which drops the affected tags and entity updates and increments the collectors'
244 /// `intern_failed_total` counters.
245 ///
246 /// Defaults to `524288` (512 KiB). An explicit `0` fails the configuration load. Change it when tuning ADP itself;
247 /// operators are not expected to.
248 pub remote_agent_string_interner_size_bytes: NonZeroUsize,
249}
250
251impl Default for ControlIpc {
252 fn default() -> Self {
253 Self {
254 // Written by the Datadog witness driver.
255 auth_token_file_path: PathBuf::new(),
256 ipc_cert_file_path: PathBuf::new(),
257 cmd_host: String::new(),
258 cmd_port: 0,
259 vsock_addr: String::new(),
260 grpc_max_message_size: 0,
261 remote_agent_string_interner_size_bytes: DEFAULT_REMOTE_AGENT_STRING_INTERNER_SIZE_BYTES,
262 }
263 }
264}