Skip to main content

Module entity_id

Module entity_id 

Source
Expand description

Extract the entity id, container id and external env

The container id can be extracted from /proc/self/group

The entity id is one of:

  • cid:<container id> if available
  • in:<cgroup node inode> if container id is not available (e.g. when using cgroupV2)

The external env is an environment variable provided by the admission controller.

§References

§Supported environments

§Docker

/proc/self/cgroup should contain lines like:

13:name=systemd:/docker/3726184226f5d3147c25fdeab5b60097e378e8a720503a5e19ecfdf29f869860

§Kubernetes

/proc/self/cgroup should contain lines like:

11:perf_event:/kubepods/besteffort/pod3d274242-8ee0-11e9-a8a6-1e68d864ef1a/3e74d3fd9db4c9dd921ae05c2502fb984d0cde1b36e581b13f79c639da4518a1

Possibly with extra characters before id:

1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod2d3da189_6407_48e3_9ab6_78188d75e609.slice/docker-7b8952daecf4c0e44bbcefe1b5c5ebc7b4839d4eefeccefe694709d3809b6199.scope

Or a UUID:

1:name=systemd:/kubepods/besteffort/pode9b90526-f47d-11e8-b2a5-080027b9f4fb/15aa6e53-b09a-40c7-8558-c6c31e36c88a

§ECS

/proc/self/cgroup should contain lines like:

9:perf_event:/ecs/haissam-ecs-classic/5a0d5ceddf6c44c1928d367a815d890f/38fac3e99302b3622be089dd41e7ccf38aff368a86cc339972075136ee2710ce

§Fargate 1.3-:

/proc/self/cgroup should contain lines like:

11:hugetlb:/ecs/55091c13-b8cf-4801-b527-f4601742204d/432624d2150b349fe35ba397284dea788c2bf66b885d14dfc1569b01890ca7da

§Fargate 1.4+:

Here we match a task id with a suffix

1:name=systemd:/ecs/8cd79a803caf4d2aa945152e934a5c00/8cd79a803caf4d2aa945152e934a5c00-1053176469

Statics§

DD_EXTERNAL_ENV

Functions§

get_container_id
Returns the container_id if available in the cgroup file, otherwise returns None
get_entity_headers
Returns an iterator of entity-related headers (container-id, entity-id, external-env) as (header_name, header_value) string tuples for any that are available.
get_entity_id
Returns the entity_id if available, either cid-<container_id> or in-<cgroup_inode>