Skip to content

Commit 8800d1d

Browse files
committed
[ACTP] add par-control resolved configuration
Loads the settings par-control needs directly in Rust with Fleet policy > environment > local YAML precedence, resolves runner identity, and leaves the executor idle timeout to the executor itself.
1 parent 00a3402 commit 8800d1d

14 files changed

Lines changed: 1685 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ nom = "8.0"
4545
normalize-path = "0.2"
4646
phf = { version = "0.14", features = ["macros"] }
4747
rawzip = "0.5.0"
48+
reqwest = { version = "0.12.28", default-features = false }
4849
xml-rs = "1.0"
4950
rmp-serde = "1.3"
5051
serde = { version = "1.0.219", features = ["derive", "std"] }

MODULE.bazel.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/schema/yaml/private_action_runner.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ properties:
105105
platform_default:
106106
windows: \\.\pipe\dd-par-executor
107107
other: ${run_path}/par-executor.sock
108+
executor_process_name:
109+
node_type: setting
110+
type: string
111+
default: datadog-agent-action-executor
112+
heartbeat_interval_seconds:
113+
node_type: setting
114+
type: integer
115+
default: 20
108116
identity_file_path:
109117
node_type: setting
110118
type: string
@@ -139,6 +147,13 @@ properties:
139147
node_type: setting
140148
type: string
141149
default: ''
150+
procmgr_socket_path:
151+
node_type: setting
152+
type: string
153+
platform_default:
154+
windows: \\.\pipe\datadog-procmgrd
155+
other: /var/run/datadog-procmgrd/dd-procmgrd.sock
156+
comment: Control-plane settings consumed by par-control.
142157
restricted_shell:
143158
node_type: section
144159
type: object

pkg/privateactionrunner/par-control/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
2+
load(":version.bzl", "par_control_agent_version")
3+
4+
_RUSTC_ENV = {"DD_AGENT_VERSION": par_control_agent_version()}
25

36
_LINUX_OR_WINDOWS = select({
47
"@platforms//os:linux": [],
@@ -9,21 +12,27 @@ _LINUX_OR_WINDOWS = select({
912
rust_library(
1013
name = "par-control-lib",
1114
srcs = [
15+
"src/bootstrap.rs",
1216
"src/config.rs",
17+
"src/identity.rs",
1318
"src/lib.rs",
1419
"src/platform.rs",
1520
"src/procmgr.rs",
1621
"src/test_support.rs",
1722
],
1823
crate_name = "par_control",
1924
edition = "2024",
25+
rustc_env = _RUSTC_ENV,
26+
rustc_flags = ["--cfg=bazel"],
2027
target_compatible_with = _LINUX_OR_WINDOWS,
2128
visibility = ["//visibility:public"],
2229
deps = [
2330
"//pkg/procmgr/rust/client:dd-procmgr-client",
2431
"@crates//:anyhow",
2532
"@crates//:log",
33+
"@crates//:reqwest",
2634
"@crates//:serde",
35+
"@crates//:serde_json",
2736
"@crates//:serde_yaml",
2837
"@crates//:tokio",
2938
"@crates//:tonic",
@@ -56,6 +65,8 @@ rust_test(
5665
name = "par-control_test",
5766
crate = ":par-control-lib",
5867
edition = "2024",
68+
rustc_env = _RUSTC_ENV,
69+
rustc_flags = ["--cfg=bazel"],
5970
target_compatible_with = _LINUX_OR_WINDOWS,
6071
deps = [
6172
"@crates//:tempfile",

pkg/privateactionrunner/par-control/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ clap = { workspace = true, features = ["derive"] }
2121
dd-agent-log.workspace = true
2222
dd-procmgr-client.workspace = true
2323
log.workspace = true
24+
reqwest.workspace = true
2425
serde = { workspace = true, features = ["derive"] }
26+
serde_json.workspace = true
2527
serde_yaml.workspace = true
2628
tokio = { workspace = true, features = [
2729
"macros",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2026-present Datadog, Inc.
5+
6+
fn main() {
7+
println!("cargo::rustc-check-cfg=cfg(bazel)");
8+
}

pkg/privateactionrunner/par-control/src/bins/par-control.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2026-present Datadog, Inc.
55

6+
//! par-control installation, configuration, and executor-lifecycle scaffold.
7+
68
use anyhow::Result;
79
use clap::Parser;
10+
use par_control::bootstrap;
811
use par_control::config::Launch;
912
use par_control::platform;
1013
use std::path::PathBuf;
@@ -15,6 +18,15 @@ use std::process::ExitCode;
1518
struct Cli {
1619
#[arg(short = 'c', long, default_value_os_t = platform::default_config_path())]
1720
config: PathBuf,
21+
22+
/// Go one-shot command that validates or creates the runner identity. Must
23+
/// be the last option because it consumes all remaining arguments.
24+
#[arg(
25+
long = "ensure-enrollment-command",
26+
num_args = 1..,
27+
allow_hyphen_values = true
28+
)]
29+
ensure_enrollment_command: Vec<String>,
1830
}
1931

2032
#[tokio::main]
@@ -53,6 +65,9 @@ async fn run() -> Result<()> {
5365
return Ok(());
5466
}
5567

68+
let _config =
69+
bootstrap::load_config_with_bootstrap(&cli.config, &cli.ensure_enrollment_command)?;
70+
5671
log::info!("par-control started");
5772
shutdown_signal().await;
5873
log::info!("par-control is exiting");
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2026-present Datadog, Inc.
5+
6+
//! Identity bootstrap. Before its first OPMS call, par-control runs the Go
7+
//! ensure-enrollment one-shot. Go owns hostname resolution, enrollment, and
8+
//! persistence; Rust then loads ordinary operational configuration and the
9+
//! persisted or configured identity directly.
10+
11+
use crate::config::Config;
12+
use anyhow::{Context, Result, bail};
13+
use log::info;
14+
use std::path::Path;
15+
use std::process::Command;
16+
17+
/// Run the Go ensure-enrollment one-shot, then load the control-plane config
18+
/// directly from local YAML, environment, and Fleet policy.
19+
///
20+
/// `ensure_enrollment_command` is the complete argv configured by the installed
21+
/// process definition, normally `privateactionrunner ensure-enrollment --cfgpath
22+
/// <datadog.yaml>`. It runs on every split-mode startup so the hostname decision
23+
/// exactly matches the Go Agent. The command itself applies persisted identity,
24+
/// inline identity, and `self_enroll` precedence.
25+
pub fn load_config_with_bootstrap(
26+
config_path: &Path,
27+
ensure_enrollment_command: &[String],
28+
) -> Result<Config> {
29+
if ensure_enrollment_command.is_empty() {
30+
bail!(
31+
"no ensure-enrollment command is configured; set \
32+
--ensure-enrollment-command"
33+
);
34+
}
35+
36+
info!("ensuring runner enrollment: {ensure_enrollment_command:?}");
37+
run_ensure_enrollment(ensure_enrollment_command)?;
38+
39+
Config::try_from_yaml_file(config_path)?
40+
.context("runner has no usable identity after ensure-enrollment completed")
41+
}
42+
43+
fn run_ensure_enrollment(argv: &[String]) -> Result<()> {
44+
let status = Command::new(&argv[0])
45+
.args(&argv[1..])
46+
.status()
47+
.with_context(|| format!("failed to run ensure-enrollment command {argv:?}"))?;
48+
if !status.success() {
49+
bail!("ensure-enrollment command {argv:?} exited with status {status}");
50+
}
51+
Ok(())
52+
}

0 commit comments

Comments
 (0)