Skip to content

Commit 8722c9a

Browse files
authored
fix pod ID for kubernetes when using the systemd cgroup driver (#631)
When the systemd cgroup driver is used, cgroup paths will have hyphens (e.g. in pod UIDs) escaped to underscores. When we're parsing cgroups, we must therefore unescape them. refs elastic/apm#165
1 parent 50dce14 commit 8722c9a

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
* ensure that metrics with value 0 are not collected if they have the `reset_on_collect` flag set (#615)
99
* unwrap postgres cursor for newly introduced psycopg2 extensions (#621)
10+
* fix pod ID for kubernetes when using the systemd cgroup driver (#631)
1011

1112
## v5.2.2
1213
[Check the diff](https://github.com/elastic/apm-agent-python/compare/v5.2.1...v5.2.2)

elasticapm/utils/cgroup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def parse_cgroups(filehandle):
100100
pod_id = kubepods_match.group(1)
101101
if not pod_id:
102102
pod_id = kubepods_match.group(2)
103+
if pod_id:
104+
pod_id = pod_id.replace("_", "-")
103105
return {"container": {"id": container_id}, "kubernetes": {"pod": {"uid": pod_id}}}
104106
elif container_id_regexp.match(container_id):
105107
return {"container": {"id": container_id}}

tests/utils/cgroup_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod90d81341_92de_11e7_8cf2_507b9d4141fa.slice/crio-2227daf62df6694645fee5df53c1f91271546a9560e8600a525690ae252b7f63.scope",
5757
{
5858
"container": {"id": "2227daf62df6694645fee5df53c1f91271546a9560e8600a525690ae252b7f63"},
59-
"kubernetes": {"pod": {"uid": "90d81341_92de_11e7_8cf2_507b9d4141fa"}},
59+
"kubernetes": {"pod": {"uid": "90d81341-92de-11e7-8cf2-507b9d4141fa"}},
6060
},
6161
),
6262
(

0 commit comments

Comments
 (0)