Skip to content

Commit 64e5b69

Browse files
committed
fixup: connect to Agent in local-snapshot mode
start_local was unconditionally forcing standalone_mode=true, which killed the workload provider and broke origin detection. When standalone_mode is false (the remote_agent_enabled=false case), the Agent is still available for metadata services. Connect to it so the env-provider gets real gRPC-backed workload/host/autodiscovery providers.
1 parent e2d13f7 commit 64e5b69

1 file changed

Lines changed: 52 additions & 16 deletions

File tree

  • lib/agent-data-plane-config-system/src

lib/agent-data-plane-config-system/src/system.rs

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
//! distinct `start_runtime` paths:
2222
//!
2323
//! - [`RuntimeAuthority::LocalSnapshot`]: the retained local Datadog snapshot is the runtime
24-
//! authority. No Agent connection is made, no inbound stream task runs, and all dynamic handles
25-
//! are `Fixed`. [`StartedConfigurationSystem::attachments`] returns `None`.
24+
//! authority. No inbound stream task runs and all dynamic handles are `Fixed`. When
25+
//! `standalone_mode` is `false` a lightweight Agent connection is established for metadata
26+
//! services (hostname, workload/origin detection, autodiscovery) and `attachments()` returns
27+
//! `Some`; in true standalone mode no connection is made and `attachments()` returns `None`.
2628
//! - [`RuntimeAuthority::AgentStream`]: the config-system connects to the Agent, awaits the first
2729
//! `ConfigUpdate::Snapshot`, and uses that as the initial runtime Datadog snapshot (local Datadog
2830
//! sources are bootstrap-only and are **not** merged into runtime config). The inbound stream task
@@ -155,7 +157,15 @@ impl LoadedConfigurationSystem {
155157

156158
match authority {
157159
RuntimeAuthority::LocalSnapshot => {
158-
start_local(saluki_only, datadog_snapshot, standalone_mode, otlp_enabled).await
160+
start_local(
161+
bootstrap,
162+
saluki_only,
163+
datadog_snapshot,
164+
standalone_mode,
165+
otlp_enabled,
166+
registration,
167+
)
168+
.await
159169
}
160170
RuntimeAuthority::AgentStream => start_stream(bootstrap, saluki_only, registration, otlp_enabled).await,
161171
}
@@ -182,27 +192,53 @@ fn assemble(
182192
(router, handles, views_rx, initial)
183193
}
184194

185-
/// Starts the runtime in local-snapshot mode (no Agent connection).
195+
/// Starts the runtime in local-snapshot mode.
196+
///
197+
/// Config authority is the retained local snapshot -- no config stream from the Agent. However, when
198+
/// `standalone_mode` is `false` (the normal `remote_agent_enabled=false` case in a bundled image),
199+
/// the Agent IS available for metadata services (hostname, workload/origin detection,
200+
/// autodiscovery). In that case we establish a lightweight Agent connection for the env-provider
201+
/// attachments without subscribing to the config stream.
186202
async fn start_local(
187-
saluki_only: SalukiOnlyConfiguration, datadog_snapshot: serde_json::Value, standalone_mode: bool,
188-
otlp_enabled: bool,
203+
bootstrap: BootstrapConfiguration, saluki_only: SalukiOnlyConfiguration,
204+
datadog_snapshot: serde_json::Value, standalone_mode: bool, otlp_enabled: bool,
205+
registration: RemoteAgentRegistration,
189206
) -> Result<StartedConfigurationSystem, GenericError> {
190207
let datadog: DatadogConfiguration = serde_json::from_value(datadog_snapshot.clone())
191208
.map_err(|e| generic_error!("Failed to parse the local Datadog snapshot at startup: {}", e))?;
192209
let mut initial = translate(&saluki_only, &datadog)
193210
.map_err(|e| generic_error!("Failed to translate the local Datadog snapshot at startup: {}", e))?;
194211

195212
// standalone_mode and otlp_enabled are not in the Datadog core schema so the witness cannot
196-
// set them. Thread the bootstrap-time values through so the runtime control slice reflects them.
197-
//
198-
// `start_local` is only called for `LocalSnapshot` (no Agent connection), so the environment
199-
// provider must use local-only host resolution. `standalone_mode` enables that path regardless
200-
// of how the LocalSnapshot authority was reached (e.g. remote_agent_enabled=false also lands
201-
// here but leaves LoadedSources::standalone_mode as false).
202-
let _ = standalone_mode;
203-
initial.control.standalone_mode = true;
213+
// set them. Thread the bootstrap-time values through.
214+
initial.control.standalone_mode = standalone_mode;
204215
initial.control.otlp.enabled = otlp_enabled;
205216

217+
// When not in standalone mode the Agent is available for metadata services (hostname, workload,
218+
// autodiscovery). Connect to it so the env-provider can build real gRPC-backed providers -- the
219+
// same behavior the binary had before the config-system cutover. The config stream from this
220+
// connection is unused; only the attachments matter.
221+
let (connection, attachments) = if !standalone_mode {
222+
let client_config = RemoteAgentClientConfiguration::from_bootstrap(&bootstrap);
223+
match connect(client_config, registration).await {
224+
Ok(conn) => {
225+
let att = conn.attachments();
226+
(Some(conn), Some(att))
227+
}
228+
Err(e) => {
229+
warn!(
230+
error = %e,
231+
"Failed to connect to the Datadog Agent for metadata services; \
232+
falling back to standalone mode (origin detection will be unavailable)."
233+
);
234+
initial.control.standalone_mode = true;
235+
(None, None)
236+
}
237+
}
238+
} else {
239+
(None, None)
240+
};
241+
206242
// The `saluki-env` provider layer reads the runtime Datadog source map; in local mode that is
207243
// the retained local snapshot.
208244
let env_config = EnvConfig::from_snapshot(datadog_snapshot.clone()).await?;
@@ -218,10 +254,10 @@ async fn start_local(
218254
Ok(StartedConfigurationSystem {
219255
saluki,
220256
handles: Some(handles),
221-
attachments: None,
257+
attachments,
222258
env_config,
223259
views_rx,
224-
connection: None,
260+
connection,
225261
router_task,
226262
})
227263
}

0 commit comments

Comments
 (0)