Skip to content

Commit

Permalink
feat: improved container-id parsing for ECS Fargate (#4216)
Browse files Browse the repository at this point in the history
Refs: elastic/apm#888
Closes: #4215
  • Loading branch information
trentm authored Sep 4, 2024
1 parent 069f9f5 commit 6360a96
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
19 changes: 19 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ Notes:
See the <<upgrade-to-v4>> guide.
==== Unreleased
[float]
===== Breaking changes
[float]
===== Features
- Minor improvement to container ID parsing from /etc/cgroup v1 files in
AWS ECS Fargate, where the pattern has been observed to sometimes differ
from the documented pattern. (https://github.com/elastic/apm/issues/888[APM spec issue #888])
[float]
===== Bug fixes
[float]
===== Chores
[[release-notes-4.7.3]]
==== 4.7.3 - 2024/08/09
Expand Down
2 changes: 1 addition & 1 deletion lib/apm-client/http-apm-client/container-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const uuidSource =
'[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}';
const containerSource = '[0-9a-f]{64}';
const taskSource = '[0-9a-f]{32}';
const awsEcsSource = '[0-9a-f]{32}-[0-9]{10}';
const awsEcsSource = '[0-9a-f]{32}-[0-9]{1,10}';

const lineReg = /^(\d+):([^:]*):(.+)$/;
const podReg = new RegExp(`pod(${uuidSource})(?:.slice)?$`);
Expand Down
42 changes: 42 additions & 0 deletions test/apm-client/http-apm-client/container-info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,48 @@ tape.test('basics', (t) => {
},
);

// https://github.com/elastic/apm/issues/888 Fewer than ten digits observed
// for the suffix in ECS Fargate in the wild.
t.deepEqual(
parse(
'1:name=systemd:/ecs/46686c7c701cdfdf2549f88f7b9575e9/46686c7c701cdfdf2549f88f7b9575e9-123456789',
// ^^^^^^^^^
),
{
entries: [
{
id: '1',
groups: 'name=systemd',
path: '/ecs/46686c7c701cdfdf2549f88f7b9575e9/46686c7c701cdfdf2549f88f7b9575e9-123456789',
controllers: ['name=systemd'],
taskId: '46686c7c701cdfdf2549f88f7b9575e9',
},
],
containerId:
'34dc0b5e626f2c5c4c5170e34b10e7654ce36f0fcd532739f4445baabea03376',
taskId: '46686c7c701cdfdf2549f88f7b9575e9',
},
);
t.deepEqual(
parse(
'1:name=systemd:/ecs/46686c7c701cdfdf2549f88f7b9575e9/46686c7c701cdfdf2549f88f7b9575e9-1',
),
{
entries: [
{
id: '1',
groups: 'name=systemd',
path: '/ecs/46686c7c701cdfdf2549f88f7b9575e9/46686c7c701cdfdf2549f88f7b9575e9-1',
controllers: ['name=systemd'],
taskId: '46686c7c701cdfdf2549f88f7b9575e9',
},
],
containerId:
'34dc0b5e626f2c5c4c5170e34b10e7654ce36f0fcd532739f4445baabea03376',
taskId: '46686c7c701cdfdf2549f88f7b9575e9',
},
);

t.deepEqual(
parse(`
12:devices:/user.slice
Expand Down

0 comments on commit 6360a96

Please sign in to comment.