Skip to content

chore: Added multiple scripts to trigger profiles#35546

Merged
nidhi-nair merged 2 commits intoreleasefrom
chore/profiling-scripts
Aug 12, 2024
Merged

chore: Added multiple scripts to trigger profiles#35546
nidhi-nair merged 2 commits intoreleasefrom
chore/profiling-scripts

Conversation

@nidhi-nair
Copy link
Contributor

@nidhi-nair nidhi-nair commented Aug 8, 2024

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags=""

🔍 Cypress test results

Warning

Tests have not run on the HEAD c684235 yet


Mon, 12 Aug 2024 13:59:02 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced scripts for enhanced monitoring and debugging of Java applications:
      • record-heap-dump.sh: Automates heap dump creation.
      • record-thread-dump.sh: Collects thread dumps for performance analysis.
      • thread-profile.sh: Manages Java Flight Recorder profiling sessions.

These scripts streamline the process of identifying memory usage and performance issues in Java applications, providing users with essential tools for effective monitoring.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2024

Walkthrough

The recent updates introduce three new Bash scripts to facilitate monitoring and debugging of Java applications running in Docker. The scripts enable automated recording of heap dumps, thread dumps, and Java Flight Recorder (JFR) profiling. These enhancements streamline the process of capturing critical performance data, aiding developers and system administrators in diagnosing memory usage and performance issues efficiently.

Changes

Files and Paths Change Summary
deploy/docker/fs/opt/appsmith/record-heap-dump.sh New script for recording heap dumps from the server.jar Java application.
deploy/docker/fs/opt/appsmith/record-thread-dump.sh New script for capturing thread dumps from the server.jar Java application.
deploy/docker/fs/opt/appsmith/thread-profile.sh New script for managing JFR profiling, including starting and stopping profiling sessions.

Poem

In Docker's realm, where Java runs,
New scripts arise, oh what fun!
Heap and thread dumps, all in play,
Profiling data saved today.
With each command, we find our way,
To chase those bugs and keep at bay! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Aug 8, 2024
@nidhi-nair
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

github-actions bot commented Aug 8, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10301842036.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 35546.
recreate: .

@github-actions
Copy link

github-actions bot commented Aug 8, 2024

Deploy-Preview-URL: https://ce-35546.dp.appsmith.com

Copy link
Contributor

@pratapaprasanna pratapaprasanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, My Suggestion is
Please check the permission . Lets not make files executable by default here.
rather modify permissions in Dockerfile

@nidhi-nair nidhi-nair marked this pull request as ready for review August 12, 2024 13:58
@nidhi-nair nidhi-nair requested a review from sharat87 as a code owner August 12, 2024 13:58
@nidhi-nair nidhi-nair merged commit deaf9f9 into release Aug 12, 2024
@nidhi-nair nidhi-nair deleted the chore/profiling-scripts branch August 12, 2024 13:59
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 061e376 and c684235.

Files selected for processing (4)
  • deploy/docker/fs/opt/appsmith/record-heap-dump.sh (1 hunks)
  • deploy/docker/fs/opt/appsmith/record-thread-dump.sh (1 hunks)
  • deploy/docker/fs/opt/appsmith/thread-profile-start.sh (1 hunks)
  • deploy/docker/fs/opt/appsmith/thread-profile-stop.sh (1 hunks)
Additional comments not posted (4)
deploy/docker/fs/opt/appsmith/thread-profile-start.sh (4)

1-1: Good practice: Use of shebang.

The script starts with a shebang (#!/bin/bash), which is a good practice to ensure the script runs with the correct interpreter.


3-6: Excellent use of shell options for safety.

The script uses set -o errexit, set -o pipefail, set -o nounset, and set -o noglob. These options enhance the script's safety by ensuring it exits on error, handles pipes correctly, avoids using unset variables, and prevents filename expansion.


10-10: Verify process identification and command execution.

The command jcmd $(pgrep -f -- "-jar\sserver.jar") JFR.start relies on pgrep to find the Java process. Ensure that the pattern uniquely identifies the correct process and that jcmd is available in the environment.


8-9: Ensure directory creation is secure.

The script creates a directory with mkdir -p $location. Ensure that the base path /appsmith-stacks/heap_dumps/ad-hoc/ is secure and not writable by unauthorized users to prevent potential security risks.

Comment on lines +1 to +6
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset
set -o noglob
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider enhancing error handling and logging.

While the script is set to fail on errors with set -o errexit, it would be beneficial to include logging for better traceability and debugging. Additionally, consider handling scenarios where pgrep might return multiple PIDs or none at all.

#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset
set -o noglob

process_id=$(pgrep -f -- "-jar\sserver.jar" || echo "")
if [ -z "$process_id" ]; then
  echo "Error: No Java process found." >&2
  exit 1
fi

jcmd $process_id JFR.dump name=profile
echo "JFR profile dumped successfully."

Comment on lines +8 to +10
location=/appsmith-stacks/heap_dumps/ad-hoc/$(date "+%Y_%m_%d_%H_%S")/heap-profile;
mkdir -p $location;
jcmd $(pgrep -f -- "-jar\sserver.jar") GC.heap_dump filename=$location/${HOSTNAME}.log No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance error handling and directory creation checks.

While the script is functional, adding checks for directory creation and process identification can improve robustness. Consider logging actions for better traceability.

location=/appsmith-stacks/heap_dumps/ad-hoc/$(date "+%Y_%m_%d_%H_%S")/heap-profile
mkdir -p "$location" || { echo "Error: Failed to create directory $location." >&2; exit 1; }

process_id=$(pgrep -f -- "-jar\sserver.jar" || echo "")
if [ -z "$process_id" ]; then
  echo "Error: No Java process found." >&2
  exit 1
fi

jcmd $process_id GC.heap_dump filename="$location/${HOSTNAME}.log"
echo "Heap dump recorded successfully at $location."

Comment on lines +8 to +10
location=/appsmith-stacks/heap_dumps/ad-hoc/$(date "+%Y_%m_%d_%H_%S")/thread-profile;
mkdir -p $location;
jcmd $(pgrep -f -- "-jar\sserver.jar") Thread.print > $location/trace-${HOSTNAME}.log No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling and directory creation checks.

To ensure robustness, add checks for directory creation and process identification. Logging actions can also aid in debugging and traceability.

location=/appsmith-stacks/heap_dumps/ad-hoc/$(date "+%Y_%m_%d_%H_%S")/thread-profile
mkdir -p "$location" || { echo "Error: Failed to create directory $location." >&2; exit 1; }

process_id=$(pgrep -f -- "-jar\sserver.jar" || echo "")
if [ -z "$process_id" ]; then
  echo "Error: No Java process found." >&2
  exit 1
fi

jcmd $process_id Thread.print > "$location/trace-${HOSTNAME}.log"
echo "Thread dump recorded successfully at $location."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants