Overview
When running Java services in Azure Container Apps, understanding the root
cause of issues requires reliable log retrieval methods. This guide outlines
how to set up and fetch logs using Azure's storage capabilities and Java Flight
Recorder (JFR).
Why Do We Need This Setup?
Our order management system
container app experienced a crash due to high memory usage by Java
microservices, causing order generation to stop. While Azure provided some
insights, detailed logs were essential for a deeper investigation. This guide
explains how to set up and fetch those logs.
Prerequisites
Before you proceed, ensure you have:
- An Azure Storage
Account with the "File Share" feature enabled.
- A Container App
configured with mounted storage.
Infrastructure Setup
1.
Create and Configure a Storage Account
Using Terraform, we provisioned a storage account with file share capabilities
and assigned 200 GiB for storage. This account was securely linked to the OMS
container app using its connection string.
2.
Verify Mount Configuration in the
Container App
The storage mount ensures a designated path inside the container where logs can
be written and accessed. You can confirm this setup in the container's
configuration panel, which shows the mounted storage location and size.
3.
Create a Storage Share Folder
Manually create a folder named "Your folder name" in the file share. This folder will store the logs generated by the container
app.
Fetching Logs Using
Java Flight Recorder (JFR)
To generate profiling logs for the Java service:
1.
Run the JFR Command Inside the Container
App
Use the following command to initiate profiling and save logs to the mounted
storage:
bash:jcmd [YOUR_JAVA_PID] JFR.start name=MyRecording settings=profile duration=30s filename=
"/path/to/volume/jfr_profile.jfr"
- Replace
[YOUR_JAVA_PID]
with the process ID of your Java service. - Adjust the
duration
parameter as needed (e.g.,30s
for 30 seconds). - Specify the path to
the mounted storage in
filename
. Ensure the file extension is.jfr
.
2.
Download Logs from the Storage Share
Folder
Navigate to the storageshare
folder in your Azure Storage account to download the generated .jfr
log file.
Analyzing the Logs
Once the logs are downloaded, use a profiling tool such as Azul Mission Control to analyze them. This tool provides
detailed insights into memory usage, thread activity, and more, helping you
pinpoint the cause of issues.
Conclusion
This setup not only simplifies log retrieval but also empowers developers to diagnose and resolve container issues effectively. By leveraging Azure's storage and JFR, you can maintain high availability and ensure seamless operations for your Java services.