Skip to content

Commit e82eecf

Browse files
committed
adapted container ID regex to match IDs from CloudFoundry Garden (#564)
fixes #523 closes #564
1 parent 121f86d commit e82eecf

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
### Bugfixes
77
* fixed an issue with empty responses from APM Server's config endpoint (#562, #563)
88
* fixed Windows tests by avoiding time.sleep in breakdown metrics tests (#537, #550)
9+
* fixed container ID matching to match CloudFoundry Garden container IDs (#523, #564)
910

1011
## v5.1.0
1112
[Check the diff](https://github.com/elastic/apm-agent-python/compare/v5.0.0...v5.1.0)

elasticapm/utils/cgroup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
r"(?:^/kubepods/[^/]+/pod([^/]+)$)|(?:^/kubepods\.slice/kubepods-[^/]+\.slice/kubepods-[^/]+-pod([^/]+)\.slice$)"
4040
)
4141

42-
container_id_regexp = re.compile("^[0-9A-Fa-f]{64}$")
42+
container_id_regexp = re.compile(
43+
"^(?:[0-9a-f]{64}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4,})$", re.IGNORECASE
44+
)
4345

4446

4547
def get_cgroup_container_metadata():
@@ -85,10 +87,8 @@ def parse_cgroups(filehandle):
8587
#
8688
# In a Kubernetes pod, the cgroup path will look like:
8789
#
88-
# systemd:
89-
# /kubepods.slice/kubepods-<QoS-class>.slice/kubepods-<QoS-class>-pod<pod-UID>.slice/<container-iD>.scope
90-
# cgroupfs:
91-
# /kubepods/<QoS-class>/pod<pod-UID>/<container-iD>
90+
# systemd:/kubepods.slice/kubepods-<QoS-class>.slice/kubepods-<QoS-class>-pod<pod-UID>.slice/<container-iD>.scope
91+
# cgroupfs:/kubepods/<QoS-class>/pod<pod-UID>/<container-iD>
9292

9393
directory, container_id = os.path.split(cgroup_path)
9494
if container_id.endswith(SYSTEMD_SCOPE_SUFFIX):

tests/utils/cgroup_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
"kubernetes": {"pod": {"uid": "90d81341_92de_11e7_8cf2_507b9d4141fa"}},
6060
},
6161
),
62+
(
63+
"1:name=systemd:/system.slice/garden.service/garden/70eb4ce5-a065-4401-6990-88ed",
64+
{"container": {"id": "70eb4ce5-a065-4401-6990-88ed"}},
65+
),
6266
],
6367
)
6468
def test_cgroup_parsing(test_input, expected):

0 commit comments

Comments
 (0)