read_from_cgroup!

in lib/elastic_apm/metadata/system_info/container_info.rb [104:148]


        def read_from_cgroup!
          return unless File.exist?(cgroup_path)
          IO.readlines(cgroup_path).each do |line|
            parts = line.strip.split(':')
            next if parts.length != 3

            cgroup_path = parts[2]

            
            
            
            
            
            
            
            
            
            
            
            
            
            
            directory, container_id = File.split(cgroup_path)

            if container_id.end_with?(SYSTEMD_SCOPE_SUFFIX)
              container_id = container_id[0...-SYSTEMD_SCOPE_SUFFIX.length]
              if container_id.include?('-')
                container_id = container_id.split('-', 2)[1]
              end
            end

            if (kubepods_match = match_kubepods(directory))
              unless (pod_id = kubepods_match[1])
                pod_id = kubepods_match[2]
                pod_id&.tr!('_', '-')
              end

              self.container_id = container_id
              self.kubernetes_pod_uid = pod_id
            elsif match_container(container_id)
              self.container_id = container_id
            end
          end
        end