elastic / apm

Elastic Application Performance Monitoring - resources and general issue tracking for Elastic APM.
https://www.elastic.co/apm
Apache License 2.0
384 stars 114 forks source link

Failure to parse Cloud Foundry Garden container IDs #105

Open eyalkoren opened 5 years ago

eyalkoren commented 5 years ago

Description of the issue

As reported in https://github.com/elastic/apm-agent-java/issues/693 - we fail to parse the container ID from the /proc/self/cgroup file in Cloud Foundry Garden containers.

The algorithm used by some of the agents only looks for contiguous 64 hex digits IDs, unless we identify that this is a container within a k8 pod, in which case we take the last part of the cgroup path regardless of format (maybe have slight differences between agents).

Proposed solution

  1. parse the line and extract the last part of the path section
  2. keep the current algorithm that parses the contiguous 64 hex digits IDs out this part and use it if a match is found
  3. if not matched at 2, use this part as ID if matches the following pattern:
    ^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4,}

    which is a shortened version of valid UUID (8-4-4-4-4 instead of 8-4-4-4-12)

  4. if the cgroup path matches a k8 pod pattern - use this part as ID regardless of structure (current algorithm)

Agent issues

eyalkoren commented 5 years ago

I edited the proposed algorithm to keep the current logic so that if the cgroup path matches a k8 pod, we use the last part of the path regardless of its structure.

axw commented 5 years ago

Depending on whether systemd or cgroupfs is being used, we also need to cater for the last path segment ending in ".scope". This was in the original Docker container ID issue (https://github.com/elastic/apm/issues/22#issuecomment-442284817) so hopefully it's already being catered for, but thought I'd mention it again here for completeness.