Skip to content

Commit 039883a

Browse files
Apply suggestions from code review
Co-authored-by: Damien Mehala <[email protected]>
1 parent 376793e commit 039883a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/datadog/platform_util.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Optional<std::string> find_container_id(std::istream& source) {
363363

364364
std::string line;
365365

366-
// First, iterate using the simple substring match.
366+
// Look for Docker container IDs in the basic format: `docker-<uuid>.scope`.
367367
while (std::getline(source, line)) {
368368
// Example:
369369
// `0::/system.slice/docker-abcdef0123456789abcdef0123456789.scope`
@@ -383,12 +383,13 @@ Optional<std::string> find_container_id(std::istream& source) {
383383
source.clear();
384384
source.seekg(0);
385385

386-
// If no match is found, iterate using the regex match.
386+
// Perform a second pass using a regular expression for matching container IDs in a Fargate environment.
387+
// This two-step approach is used because STL `regex` is relatively slow, so we avoid using it unless necessary.
387388
while (std::getline(source, line)) {
388389
// Example:
389390
// `0::/system.slice/docker-abcdef0123456789abcdef0123456789.scope`
390391
std::smatch match;
391-
if (std::regex_match(line, match, path_reg)) {
392+
if (std::regex_match(line, match, path_reg) && match.size() == 2) {
392393
assert(match.ready());
393394
assert(match.size() == 2);
394395

0 commit comments

Comments
 (0)