Extract Container ID in cgroupv2 Environments

Note: This document is applicable only if you are not using Cluster Agent. If you are using Cluster Agent, you can extract the container ID based on the following scenarios:

After upgrading to Kubernetes 1.25 or later, Java Agent might fail to properly identify the container ID of the application container. While the discovered container ID has the correct form and syntax, it differs from the actual container ID used by Kubernetes. This discrepancy disrupts the correlation between APM data and infrastructure. To extract the correct container ID in Kubernetes 1.25 or later, you need to query the Kubernetes API Server.

Note:
  • Prior to version 25.1.0, If Java Agent cannot fetch the container ID after three attempts, it will register with Controller with all zeros (00000) container ID and log an error. Please review the container or agent logs to address the issue.

  • From version 25.1.0 onward, Java Agent assigns the container ID only when it detects a valid container ID. If it fails to retrieve the container ID after 15 attempts (approximately ten minutes), it logs an error and does not register with the Controller. However, the application will start as usual after the default timeout of one minute. In such cases, review the container or agent logs to resolve the issue.

  • From version 25.3.0 onward, you can modify this default behavior by setting either the APPDYNAMICS_AGENT_FAIL_IF_INVALID_CONTAINER_ID environment variable or the appdynamics.agent.fail.if.invalid.container.id system property to false. This allows the Java Agent to register and provide application monitoring even with an invalid container ID.

  • Java Agent identifies the Kubernetes API server URL using the environment variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT set by Kubernetes. Additionally, the Java Agent depends on the HOSTNAME environment variable, using it as the pod name to query the Cluster Agent. It is important to keep these variables unchanged to accurately extract the container ID.

  • From version 25.3.0 onward, if you change the HOSTNAME environment variable, it's important to set the APPDYNAMICS_POD_NAME environment variable to the pod name. This ensures that the Java agent can successfully extract the container ID.

    You can dynamically set environment variables based on the pod's attributes using the following Kubernetes configuration:
    - name: APPDYNAMICS_POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
Important: Java Agent identifies the Kubernetes API server URL using the environment variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT set by Kubernetes. Additionally, the Java Agent depends on the HOSTNAME environment variable, using it as the pod name to query the Cluster Agent. It is important to keep these variables unchanged to accurately extract the container ID.