The Problem:
Earlier we used cloud debugger ,a GCP product to put a debugger to debug the state of the application, but down the line one problem occurred.
Cloud Debugger is Deprecated.It wont be there after May,2023.
So Google has moved their Cloud Debugger to Snapshot Debugger ,which is not a open source project, to be maintained by end users.
Developers can add the debugger sources and agents in their project and use the Debugger.
Prerequisites:
To use the debugger locally you need these 4 things:
- A Spring boot project using gradle/maven.
- Gcloud cli and account.
- Python3/3.4 with pip.
- Firebase project with Realtime Database Enabled
- Firebase Admin Service Account Json key
- Linux/Ubuntu Machine/Subsystem.(It wont run on mac /windows)
Once you have all these we can proceed with the setup process.
Setup:
Configuring Firebase
- Go to Console.firebase.com and login with Google Account.
- Select your project
- Enable Realtime Database
- Now goto project Settings, then Service Account
- Download the admin key json File.
Configuring Gcloud
- Open Terminal and run gcloud auth login
- Login using same credentials that you used for firebase.
- Type the following command gcloud projects list
- Check if the same firebase project is listed or not.If listed ,then correct Gcloud account is used.
- Now Run the following command gcloud config set project $MY_PROJECT_ID ,replace $MY_PROJECT_ID with your project name.
- GCloud Config is done
Installing and Configuring Snapshot Debug Cli
To install Snapshot debugger Cli ,run the following command:
python3 -m pip install snapshot-dbg-cli
Once Installation is complete and you have made sure that correct firebase account is selected using gcloud cli,Run the following command,
snapshot-dbg-cli init --use-default-rtdb
Or
python3 -m snapshot-dbg-cli init --use-default-rtdb
This will initialize the snapshot debugger for your firebase account and create logs in your Realtime Database.
Such output should be expected
Project 'test-proj' is successfully configured with the Firebase Realtime
Database for use by Snapshot Debugger.
The full database information is below. If you have specified a custom database
ID the url below is the one you'll need to specify when using the other cli
commands.
name: projects/23498723497/locations/us-central1/instances/test-proj-cdbg
project: projects/23498723497
database url: https://test-proj-cdbg.firebaseio.com
type: USER_DATABASE
state: ACTIVE
Here take a note for the database url, because we will need it later.
Agent setup
- Create a folder named debugger inside “src” folder
- Download the following tar file and unzip it inside the debugger folder.
https://github.com/GoogleCloudPlatform/cloud-debug-java/releases/latest/download/cdbg_java_agent_gce.tar.gz
- Also add your admin json file inside this folder for testing(we can remove it later)
- In service build. gradle, go to JIB
- Now add/replace the following
extraDirectories.paths = ['src/debugger']
container {
creationTime = 'USE_CURRENT_TIMESTAMP'
ports = ['50061', '50062']
// environment = ["FIREBASE_ADMIN_SDK_KEY":"/opt/cdbg/admin.json"]
entrypoint=["sh", "-c",
"java -Djava.security.egd=file:/dev/urandom " +
"-agentpath:./opt/cdbg/cdbg_java_agent.so " +
"-Dcom.google.cdbg.module=starter-server " +
"-Dcom.google.cdbg.version=${scmVersion.version.toString()} " +
"-Dcom.google.cdbg.agent.use_firebase=True " +
"-Dcom.google.cdbg.auth.serviceaccount.jsonfile=\$FIREBASE_ADMIN_SDK_KEY " +
"-Dcom.google.cdbg.agent.firebase_db_url=https://unifiedplatform-dev.firebaseio.com/ "+
"-cp /app/resources:/app/classes:/app/libs/* " +
"org.heartfulness.unifiedplatform.volunteer.application.VolunteerApplicationApp"]
mainClass = 'org.heartfulness.unifiedplatform.volunteer.application.VolunteerApplicationApp'
}
Now when you will build Docker image ,all the files from the debugger folder will be copied into /opt/cdbg folder inside the container.
For testing purpose ,you can change the following line
-Dcom.google.cdbg.auth.serviceaccount.jsonfile=\$FIREBASE_ADMIN_SDK_KEY
To
-Dcom.google.cdbg.auth.serviceaccount.jsonfile=/opt/cdbg/firebase_admin.json’
Now try running the docker container locally using docker hub desktop.If everything is configured properly,it will start .You will notice a new entry ”Debugger” in firebase Realtime database .
If everything is working fine,you can revert the changes and rebuild the docker container.
Platform GCP DevOps Settings
Add the following lines to your deployment.yml(Make Sure indentation is correct)
Env:
- name: FIREBASE_ADMIN_SDK_KEY
value: "/var/run/secrets/firebase-admin-sdk/key.json"
volumeMounts:
- name: firebase-admin-sdk-key
mountPath: /var/run/secrets/firebase-admin-sdk/
volumes:
- name: firebase-admin-sdk-key
secret:
secretName: firebase-admin-sdk-key


