Introduction
Cloud Debugger is also known as Stackdriver Debugger. It lets the user inspect the state of a running cloud application at any code location without stopping or slowing it down. It's safe for use with the production apps. When a debug snapshot is captured by the Java debugger agent, it adds less than 10ms to the request latency. This blog will discuss the basic concepts that are used in Cloud Debugger.
Setting up Cloud Debugger for Java
For some environments, the user must explicitly specify the access scope in order to let the cloud debugger agent send data. It is recommended to set the broadest possible access scope and then use Identity and Access Management to restrict access.
Setting up Cloud Debugger
Follow the below-mentioned steps in order to set up a cloud debugger.
- Make sure that Cloud Debugger API is enabled on the project.
- On the compute environment that is currently being used, install as well as configure the Debugger.
- Select the source code.
Canary snapshots and logpoints
Enable the canary mode for the debugger agent to prevent snapshots and logpoints from being loaded on all the running instances simultaneously and causing the job to be taken down because of a potential bug in the debugger agent. A snapshot or logpoint is applied to only a subset of the running instances . The snapshot or logpoint doesn't affect the instances when the carry mode is enabled is verified by the Debugger. The snapshot or the logpoint is applied to all the instances once the verification is complete.
Enabling canary snapshots and logpoints
The user gets the option of enabling or disabling the canary when the latest version of the debugger agent is installed. By default, canarying is disabled.
When to enable canary snapshots and logpoints
If the user wishes to protect deployment and production-critical workloads, then the user should enable canarying when debugging these workloads. If a user has a single instance, the user can still debug with canarying enabled, but then the single instance runs without canarying the snapshot or logpoint.
When to disable canary snapshots and logpoints
The user shouldn't enable canarying on workloads that have an execution time of less than 40 seconds. If the user wants a faster snapshot-triggering cycle, then also the user shouldn't enable canarying.
App Engine Flexible Environment
No configuration is required as the Debugger is enabled by default for the Java runtime. The Java source files that have been used to build the app are displayed by the Debug page in the console.
A debugger for custom runtimes that uses the Google-provided base images for Java is included by default. If the default entry point is used, then no configuration is required. The Java source files that have been used to build the app are displayed by the Debug page in the console. If the user wants to use Cloud debugger with custom runtimes built using other base images, the user needs to follow the setup instructions for Compute Engine.
Google Kubernetes Engine
Follow the below-mentioned steps to enable Debugger using gcloud:
-
The user can create their cluster using one of the below-mentioned access scopes:
- https://www.googleapis.com/auth/cloud-platform grants the user's cluster access to all of the Google Cloud APIs.
- https://www.googleapis.com/auth/cloud_debugger grants the user's cluster access to only the debugger API.
To add the debugger agent to the containerized app and initialize it when the app is deployed, add the below-mentioned lines to the Dockerfile.
# Create a directory for the Debugger. Add and unzip the agent in the directory.
RUN mkdir /opt/cdbg && \
wget -qO- https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezy/cdbg_java_agent_gce.tar.gz | \
tar xvz -C /opt/cdbg
- To run the Debugger agent, add the below-mentioned lines to the Dockerfile
If the user wants to debug with canarying enabled
# Start the agent when the app is deployed.
RUN java -agentpath:/opt/cdbg/cdbg_java_agent.so \
-Dcom.google.cdbg.module=MODULE \
-Dcom.google.cdbg.version=VERSION \
-Dcom.google.cdbg.breakpoints.enable_canary=true \
-jar PATH_TO_JAR_FILE
- If the user wants to debug with canarying NOT enabled, set the enable_canary flag to false:
-Dcom.google.cdbg.breakpoints.enable_canary=false
Assign the placeholder with the below-mentioned:
PATH_TO_JAR_FILE: it refers to the relative path to the app's JAR file.
Module: it is the name of the app.
VERSION: it is the app version or the build ID.
Compute Engine
The user can use the cloud debugger with any Java app that is running on a Google Compute Engine instance. It is recommended to enable the Debugger on all of the running instances of the app.
-
The user must ensure that the Compute Engine VM instances are running on:
- 64-bit Debian Linux image
- Java JDK version 7, 8 or 9
- The user needs to ensure that the compute engine VM instances that are created must have the access scope option to Allow full access to all Cloud APIs.
To get the pre-built agent package, use the below-mentioned command:
# Create a directory for the Debugger. Add and unzip the agent in the directory.
sudo mkdir /opt/cdbg
wget -qO- https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezy/cdbg_java_agent_gce.tar.gz | \
tar xvz -C /opt/cdbg
- Add the agent to the Java invocation:
- To debug with canarying enabled:
# Start the agent when the app is deployed.
java -agentpath:/opt/cdbg/cdbg_java_agent.so \
-Dcom.google.cdbg.module=MODULE \
-Dcom.google.cdbg.version=VERSION \
-Dcom.google.cdbg.breakpoints.enable_canary=true \
-jar PATH_TO_JAR_FILE
- To debug with canarying disabled:
-Dcom.google.cdbg.breakpoints.enable_canary=false
Tomcat
Add this line to either of the below mentioned:
/etc/default/tomcat7 or /etc/default/tomcat8
To debug with canarying enabled
# Start the agent when the app is deployed.
JAVA_OPTS="${JAVA_OPTS} -agentpath:/opt/cdbg/cdbg_java_agent.so \
-Dcom.google.cdbg.module=MODULE \
-Dcom.google.cdbg.version=VERSION \
-Dcom.google.cdbg.breakpoints.enable_canary=true"
To debug with canarying disabled:
-Dcom.google.cdbg.breakpoints.enable_canary=false
Jetty
Add the lines to below mentioned
/var/lib/jetty/start.d
To debug with canarying enabled
--exec
-agentpath:/opt/cdbg/cdbg_java_agent.so \
-Dcom.google.cdbg.module=MODULE \
-Dcom.google.cdbg.version=VERSION \
-Dcom.google.cdbg.breakpoints.enable_canary=true
To debug with canarying disabled
-Dcom.google.cdbg.breakpoints.enable_canary=false
Cloud Run and Cloud Run for Anthos
- To create a directory in for installing the debugger agent, download the debugger agent archive, and extract it into the installation directory: add the following mentioned commands to the Dockerfile:
# Create a directory for the Debugger. Add and then unzip the agent in the directory.
RUN mkdir /opt/cdbg && \
wget -qO- https://storage.googleapis.com/cloud-debugger/compute-java/debian-wheezycdbg_java_agent_gce.tar.gz | \
tar xvz -C /opt/cdbg
If the user wishes to install a previous version of the agent, then change the URL to the below-mentioned value and replace the VERSION_NUMBER with the version of the agent that you want to use:
https://storage.googleapis.com/cloud-debugger/archive/java/VERSION_NUMBER/cdbg_java_agent_gce.tar.gz
After locating the Java invocation, add the following flag to initialize the debugger agent. To debug with canarying enabled:
# Start the agent when the app is deployed.
RUN java -agentpath:/opt/cdbg/cdbg_java_agent.so \
-Dcom.google.cdbg.breakpoints.enable_canary=true \
-jar PATH_TO_JAR_FILE
If you want to debug with canarying disabled:
-Dcom.google.cdbg.breakpoints.enable_canary=false