Skip to content

Commit 5f72c7f

Browse files
authored
fix(runtime): add support for PCF containers (backport #4405) (#4420)
This is an automatic backport of pull request #4405 done by [Mergify](https://mergify.com). --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com/) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details>
1 parent f18d02a commit 5f72c7f

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

ddtrace/internal/runtime/container.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ class CGroupInfo(object):
2323
controllers = attr.ib(default=None)
2424
pod_id = attr.ib(default=None)
2525

26-
UUID_SOURCE_PATTERN = r"[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}"
26+
# The second part is the PCF/Garden regexp. We currently assume no suffix ($) to avoid matching pod UIDs
27+
# See https://github.com/DataDog/datadog-agent/blob/7.40.x/pkg/util/cgroups/reader.go#L50
28+
UUID_SOURCE_PATTERN = (
29+
r"[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}|([0-9a-f]{8}(-[0-9a-f]{4}){4}$)"
30+
)
2731
CONTAINER_SOURCE_PATTERN = r"[0-9a-f]{64}"
2832
TASK_PATTERN = r"[0-9a-f]{32}-\d+"
2933

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
CGroup file parsing was fixed to correctly parse container UUID for PCF containers.

tests/tracer/runtime/test_container.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ def test_cgroup_info_init():
7070
pod_id=None,
7171
),
7272
),
73+
# Valid, PCF
74+
(
75+
"10:freezer:/garden/6f265890-5165-7fab-6b52-18d1",
76+
CGroupInfo(
77+
id="10",
78+
groups="freezer",
79+
controllers=["freezer"],
80+
path="/garden/6f265890-5165-7fab-6b52-18d1",
81+
container_id="6f265890-5165-7fab-6b52-18d1",
82+
pod_id=None,
83+
),
84+
),
7385
# Invalid container_ids
7486
(
7587
# One character too short
@@ -240,6 +252,24 @@ def test_cgroup_info_from_line(line, expected_info):
240252
""",
241253
"34dc0b5e626f2c5c4c5170e34b10e765-1234567890",
242254
),
255+
# PCF file
256+
(
257+
"""
258+
12:rdma:/
259+
11:net_cls,net_prio:/garden/6f265890-5165-7fab-6b52-18d1
260+
10:freezer:/garden/6f265890-5165-7fab-6b52-18d1
261+
9:devices:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
262+
8:blkio:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
263+
7:pids:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
264+
6:memory:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
265+
5:cpuset:/garden/6f265890-5165-7fab-6b52-18d1
266+
4:cpu,cpuacct:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
267+
3:perf_event:/garden/6f265890-5165-7fab-6b52-18d1
268+
2:hugetlb:/garden/6f265890-5165-7fab-6b52-18d1
269+
1:name=systemd:/system.slice/garden.service/garden/6f265890-5165-7fab-6b52-18d1
270+
""",
271+
"6f265890-5165-7fab-6b52-18d1",
272+
),
243273
# Linux non-containerized file
244274
(
245275
"""

0 commit comments

Comments
 (0)