Skip to content

Commit 8cc535a

Browse files
fix(procmgr): sync config gate YAML and system_probe fixes from #53249
1 parent 9fc0107 commit 8cc535a

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

pkg/procmgr/rust/src/config_gate/system_probe.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
//! Mirrors `load()` in `pkg/system-probe/config/config.go` and the NPM back-compat
1111
//! rule in `pkg/system-probe/config/adjust.go`. Sk-tracer disables USM in
1212
//! `pkg/system-probe/config/adjust_npm.go`; discovery conflicts in
13-
//! `pkg/system-probe/config/adjust_discovery.go`. Module knob resolution uses fleet →
14-
//! env → YAML ([`super::env_bindings`], `pkg/config/model/types.go` precedence).
13+
//! `pkg/system-probe/config/adjust_discovery.go`. Module knob resolution uses
14+
//! highest-priority configured source among fleet, secret (pre-fleet layers only),
15+
//! env, and YAML ([`super::env_bindings`], `pkg/config/model/types.go` precedence).
1516
//!
1617
//! **When module enablement changes in Go, update `derived_enabled` below.**
1718

pkg/procmgr/rust/src/config_gate/yaml_load.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ use serde_yaml::{Mapping, Number, Sequence, Value};
2222

2323
/// Parse YAML for config-gate lookups, matching Agent config file semantics.
2424
pub(super) fn load_yaml(contents: &str) -> Result<Value> {
25-
match serde_yaml::from_str(contents) {
26-
Ok(value) => Ok(value),
25+
let value = match serde_yaml::from_str(contents) {
26+
Ok(mut value) => {
27+
apply_yaml_merges(&mut value)?;
28+
value
29+
}
2730
Err(strict_err) => {
2831
debug!("strict YAML parse failed, retrying permissive: {strict_err}");
29-
load_yaml_permissive(contents).with_context(|| strict_err.to_string())
32+
load_yaml_permissive(contents).with_context(|| strict_err.to_string())?
3033
}
31-
}
34+
};
35+
Ok(value)
36+
}
37+
38+
fn apply_yaml_merges(value: &mut Value) -> Result<()> {
39+
value
40+
.apply_merge()
41+
.context("apply YAML merge keys for config gate lookup")
3242
}
3343

3444
/// Same shape as `serde_yaml::Value`, but mappings use `HashMap` (last duplicate wins).
@@ -45,7 +55,9 @@ enum PermissiveValue {
4555

4656
fn load_yaml_permissive(contents: &str) -> Result<Value> {
4757
let root: PermissiveValue = serde_yaml::from_str(contents)?;
48-
Ok(permissive_to_value(root))
58+
let mut value = permissive_to_value(root);
59+
apply_yaml_merges(&mut value)?;
60+
Ok(value)
4961
}
5062

5163
fn permissive_to_value(value: PermissiveValue) -> Value {
@@ -123,4 +135,31 @@ mod tests {
123135
Some(&Value::Bool(true))
124136
);
125137
}
138+
139+
#[test]
140+
fn merge_keys_expand_disabled_process_config_defaults() {
141+
let yaml = r#"
142+
disabled: &disabled
143+
process_collection:
144+
enabled: false
145+
container_collection:
146+
enabled: false
147+
148+
process_config:
149+
<<: *disabled
150+
"#;
151+
let root = load_yaml(yaml).unwrap();
152+
assert_eq!(
153+
root.get("process_config")
154+
.and_then(|v| v.get("process_collection"))
155+
.and_then(|v| v.get("enabled")),
156+
Some(&Value::Bool(false))
157+
);
158+
assert_eq!(
159+
root.get("process_config")
160+
.and_then(|v| v.get("container_collection"))
161+
.and_then(|v| v.get("enabled")),
162+
Some(&Value::Bool(false))
163+
);
164+
}
126165
}

0 commit comments

Comments
 (0)