Skip to content

Commit be94f69

Browse files
Kyle-Nealeyannham
andauthored
feat(libdd-common): recognize PCF Garden container IDs (#2025)
## What - Add a dedicated `PCF_UUID_SOURCE` regex (8-4-4-4-4 hex) alongside the existing `UUID_SOURCE` (8-4-4-4-12). - Wire it into `CONTAINER_REGEX` so Garden cgroup paths resolve to their container ID. - Add unit cases for Garden paths plus a regression guard ensuring standard UUIDs are not truncated, and a `cgroup.pcf` fixture. ## Why PCF / Garden containers expose a non-standard 28-char UUID in their cgroup paths. Without a dedicated source, the parser either misses them entirely or risks truncating standard UUIDs if the existing source is loosened. ## Testing - Covered by the new cases in `container_id::tests::test_extract_container_id` (Garden paths, fixture file, regression guard, length boundary). Co-authored-by: yann.hamdaoui <yann.hamdaoui@datadoghq.com>
1 parent b6ea82e commit be94f69

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

libdd-common/src/entity_id/unix/container_id.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use std::sync::LazyLock;
1111

1212
const UUID_SOURCE: &str =
1313
r"[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}";
14+
/// PCF / Garden container UUID source: 8-4-4-4-4 hex (28 chars).
15+
/// Distinct from `UUID_SOURCE` (8-4-4-4-12) because the last group is 4 hex.
16+
const PCF_UUID_SOURCE: &str = r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}";
1417
const CONTAINER_SOURCE: &str = r"[0-9a-f]{64}";
1518
const TASK_SOURCE: &str = r"[0-9a-f]{32}-\d+";
1619

@@ -22,7 +25,7 @@ pub(crate) static LINE_REGEX: LazyLock<Regex> = LazyLock::new(|| {
2225
pub(crate) static CONTAINER_REGEX: LazyLock<Regex> = LazyLock::new(|| {
2326
#[allow(clippy::unwrap_used)]
2427
Regex::new(&format!(
25-
r"({UUID_SOURCE}|{CONTAINER_SOURCE}|{TASK_SOURCE})(?:\.scope(?:/[^/ \t]+)?)? *$"
28+
r"({UUID_SOURCE}|{PCF_UUID_SOURCE}|{CONTAINER_SOURCE}|{TASK_SOURCE})(?:\.scope(?:/[^/ \t]+)?)? *$"
2629
))
2730
.unwrap()
2831
});
@@ -92,6 +95,17 @@ mod tests {
9295
// invalid hex
9396
"13:name=systemd:/docker/3726184226f5d3147g25fdeab5b60097e378e8a720503a5e19ecfdf29f869860"
9497
=> None,
98+
// PCF Garden 8-4-4-4-4 UUID
99+
"1:name=systemd:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1"
100+
=> Some("6f265890-5165-7fab-6b52-18d1"),
101+
"10:freezer:/garden/6f265890-5165-7fab-6b52-18d1"
102+
=> Some("6f265890-5165-7fab-6b52-18d1"),
103+
// Regression guard: 8-4-4-4-12 standard UUID must NOT be truncated to 28 chars
104+
"1:name=systemd:/uuid/5a081c13-b8cf-4801-b427-f4601742204d"
105+
=> Some("5a081c13-b8cf-4801-b427-f4601742204d"),
106+
// First group only 7 chars -> no match
107+
"1:name=systemd:/garden/6f26589-5165-7fab-6b52-18d1"
108+
=> None,
95109
};
96110
for (line, &expected_result) in test_lines.iter() {
97111
assert_eq!(
@@ -118,6 +132,7 @@ mod tests {
118132
"cgroup.fargate" => Some("432624d2150b349fe35ba397284dea788c2bf66b885d14dfc1569b01890ca7da"),
119133
// parse a Fargate 1.4+ container ID
120134
"cgroup.fargate.1.4" => Some("8cd79a803caf4d2aa945152e934a5c00-1053176469"),
135+
"cgroup.pcf" => Some("6f265890-5165-7fab-6b52-18d1"),
121136

122137
// Whitespace around the matching ID is permitted so long as it is matched within a valid cgroup line.
123138
// parse a container ID with leading and trailing whitespace

libdd-common/tests/cgroup.pcf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
12:rdma:/
2+
11:net_cls,net_prio:/garden/6f265890-5165-7fab-6b52-18d1
3+
10:freezer:/garden/6f265890-5165-7fab-6b52-18d1
4+
9:devices:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
5+
8:blkio:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
6+
7:pids:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
7+
6:memory:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
8+
5:cpuset:/garden/6f265890-5165-7fab-6b52-18d1
9+
4:cpu,cpuacct:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
10+
3:perf_event:/garden/6f265890-5165-7fab-6b52-18d1
11+
2:hugetlb:/garden/6f265890-5165-7fab-6b52-18d1
12+
1:name=systemd:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1

0 commit comments

Comments
 (0)