Skip to content

Commit

Permalink
Merge branch 'main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Aug 13, 2021
2 parents 40ab25a + ebcdbdb commit e0243aa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def detect(self) -> "Resource":
) as container_info_file:
for raw_line in container_info_file.readlines():
line = raw_line.strip()
# Subsequent IDs should be the same, exit if found one
if len(line) > _CONTAINER_ID_LENGTH:
container_id = line[-_CONTAINER_ID_LENGTH:]
break
except FileNotFoundError as exception:
logger.warning(
"Failed to get container ID on ECS: %s.", exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ def _get_container_id():
with open("/proc/self/cgroup", encoding="utf8") as container_info_file:
for raw_line in container_info_file.readlines():
line = raw_line.strip()
# Subsequent IDs should be the same, exit if found one
if len(line) > _CONTAINER_ID_LENGTH:
container_id = line[-_CONTAINER_ID_LENGTH:]
break
return container_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ class AwsEcsResourceDetectorTest(unittest.TestCase):
new_callable=mock_open,
read_data=f"""14:name=systemd:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
13:rdma:/
12:pids:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
11:hugetlb:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
10:net_prio:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
9:perf_event:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
8:net_cls:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
7:freezer:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
6:devices:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
5:memory:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
4:blkio:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
3:cpuacct:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
2:cpu:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
1:cpuset:/docker/{MockEcsResourceAttributes[ResourceAttributes.CONTAINER_ID]}
12:pids:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
11:hugetlb:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
10:net_prio:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
9:perf_event:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
8:net_cls:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
7:freezer:/docker/
6:devices:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
5:memory:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
4:blkio:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
3:cpuacct:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
2:cpu:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
1:cpuset:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
""",
)
def test_simple_create(self, mock_open_function, mock_socket_gethostname):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ class AwsEksResourceDetectorTest(unittest.TestCase):
new_callable=mock_open,
read_data=f"""14:name=systemd:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
13:rdma:/
12:pids:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
11:hugetlb:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
10:net_prio:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
9:perf_event:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
8:net_cls:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
7:freezer:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
6:devices:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
5:memory:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
4:blkio:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
3:cpuacct:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
2:cpu:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
1:cpuset:/docker/{MockEksResourceAttributes[ResourceAttributes.CONTAINER_ID]}
12:pids:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
11:hugetlb:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
10:net_prio:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
9:perf_event:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
8:net_cls:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
7:freezer:/docker/
6:devices:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
5:memory:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
4:blkio:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
3:cpuacct:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
2:cpu:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
1:cpuset:/docker/bogusContainerIdThatShouldNotBeOneSetBecauseTheFirstOneWasPicked
""",
)
def test_simple_create(
Expand Down

0 comments on commit e0243aa

Please sign in to comment.