Commit 57f7346
authored
cpu_utilization: gracefully handle cgroup v2 CPU detection in CONTAINER mode (#47485)
Commit Message:
cpu_utilization: fix CONTAINER mode in the host cgroup namespace
In CONTAINER mode the cpu_utilization resource monitor read the cgroup
v2 files
straight from /sys/fs/cgroup, assuming it is the process's own cgroup,
and
required cpu.stat, cpu.max and cpuset.cpus.effective to all exist. When
Envoy
shares the host cgroup namespace, as privileged containers do,
/sys/fs/cgroup is
the cgroup v2 root: its cpu.stat covers the whole machine and it has no
cpu.max.
Detection failed and config initialization aborted the server.
Resolve the process's own cgroup from /proc/self/cgroup and
/proc/self/mountinfo,
reusing the parsing in CgroupCpuUtil, before probing the cgroup v2
files, so the
monitor reports container rather than host usage. Key cgroup v2
detection on
cpu.stat. An absent cpu.max means no CPU limit and an absent
cpuset.cpus.effective falls back to the CPU affinity count, while a file
that
exists but cannot be read fails the sample. When no supported cgroup CPU
implementation is found, config initialization still fails as before.
HOST mode
is unchanged.
Additional Description:
Measured inside an affected container (privileged, Kubernetes with
containerd,
cgroup v2):
```
/proc/self/cgroup 0::/kubepods.slice/kubepods-pod<uid>.slice/cri-containerd-<id>.scope
/proc/self/mountinfo ... 0:30 / /sys/fs/cgroup ... - cgroup2 cgroup rw
/sys/fs/cgroup/cpu.stat present usage_usec 17341693371 <- whole machine
/sys/fs/cgroup/cpu.max absent <- none at the root
/sys/fs/cgroup/cpuset.cpus.effective present
<own cgroup>/cpu.stat present usage_usec 12356042342 <- this container
<own cgroup>/cpu.max present max 100000
<own cgroup>/cpuset.cpus.effective present 0-31
```
`CgroupCpuUtil::getCurrentCgroupInfo()` is a new public wrapper around
the
existing `discoverCgroupMount()` and `constructCgroupPath()`, so the
monitor
shares the mount root stripping and `mountinfo` unescaping already used
for
concurrency detection.
Related to #39978. This supersedes #47503.
AI assistance disclosure: this change was prepared with AI assistance.
The
submitter has reviewed and fully understands all of the submitted code,
per the
project's generative AI policy.
Risk Level: Low. Any resolution failure falls back to the previous
`/sys/fs/cgroup` behavior.
Testing: Unit tests in
`test/extensions/resource_monitors/cpu_utilization/` and
`test/server/cgroup_cpu_util_test.cc` cover resolution in the host
cgroup
namespace, `0::/` resolving to the mount point, the fallback when the
resolved
cgroup has no `cpu.stat`, absent versus unreadable optional
files (stat errors other than `ENOENT`, and read failures after a
successful
stat), the affinity fallback, and the config-init error when no cgroup
CPU
support is found. A native macOS build of Envoy was not possible for
unrelated
toolchain reasons, so build and test verification relies on CI.
Docs Changes: N/A
Release Notes: Updated
`changelogs/current/bug_fixes/cpu_utilization__cgroup-v2-graceful-detection.rst`.
Platform Specific Features: Linux cgroup detection only. The affinity
fallback
is compiled on Linux only; other platforms keep
`hardware_concurrency()`.
---------
Signed-off-by: William Dauchy <william.dauchy@datadoghq.com>1 parent 587588d commit 57f7346
11 files changed
Lines changed: 352 additions & 77 deletions
File tree
- changelogs/current/bug_fixes
- source
- extensions/resource_monitors/cpu_utilization
- server
- test
- extensions/resource_monitors/cpu_utilization
- server
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| |||
Lines changed: 16 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
43 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
47 | 55 | | |
48 | 56 | | |
49 | | - | |
50 | | - | |
| 57 | + | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
| |||
57 | 65 | | |
58 | 66 | | |
59 | 67 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
| |||
Lines changed: 99 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
14 | 22 | | |
15 | 23 | | |
| 24 | + | |
16 | 25 | | |
| 26 | + | |
17 | 27 | | |
18 | 28 | | |
19 | 29 | | |
| |||
26 | 36 | | |
27 | 37 | | |
28 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
29 | 70 | | |
30 | 71 | | |
31 | 72 | | |
| |||
165 | 206 | | |
166 | 207 | | |
167 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
168 | 221 | | |
169 | 222 | | |
170 | 223 | | |
| |||
261 | 314 | | |
262 | 315 | | |
263 | 316 | | |
264 | | - | |
265 | | - | |
266 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
267 | 325 | | |
268 | 326 | | |
269 | 327 | | |
| |||
306 | 364 | | |
307 | 365 | | |
308 | 366 | | |
309 | | - | |
310 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
311 | 373 | | |
312 | | - | |
| 374 | + | |
| 375 | + | |
313 | 376 | | |
314 | 377 | | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
323 | 390 | | |
324 | | - | |
325 | 391 | | |
326 | | - | |
327 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
328 | 396 | | |
329 | | - | |
| 397 | + | |
| 398 | + | |
330 | 399 | | |
331 | 400 | | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
338 | 411 | | |
339 | 412 | | |
340 | 413 | | |
| |||
344 | 417 | | |
345 | 418 | | |
346 | 419 | | |
347 | | - | |
| 420 | + | |
348 | 421 | | |
349 | | - | |
| 422 | + | |
350 | 423 | | |
351 | 424 | | |
352 | 425 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
228 | 236 | | |
229 | 237 | | |
230 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
120 | 129 | | |
121 | 130 | | |
122 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
Lines changed: 27 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
52 | 63 | | |
53 | 64 | | |
54 | 65 | | |
| |||
90 | 101 | | |
91 | 102 | | |
92 | 103 | | |
93 | | - | |
| 104 | + | |
94 | 105 | | |
95 | 106 | | |
96 | | - | |
| 107 | + | |
97 | 108 | | |
98 | | - | |
99 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
100 | 120 | | |
101 | 121 | | |
102 | 122 | | |
103 | 123 | | |
104 | 124 | | |
105 | 125 | | |
106 | 126 | | |
107 | | - | |
108 | 127 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | 128 | | |
117 | 129 | | |
118 | 130 | | |
119 | 131 | | |
120 | | - | |
| 132 | + | |
121 | 133 | | |
122 | 134 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 135 | + | |
130 | 136 | | |
131 | | - | |
| 137 | + | |
132 | 138 | | |
133 | 139 | | |
134 | 140 | | |
| |||
0 commit comments