Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add health_check_no.sh script for Docker and non-Docker health checks #3108

Merged
merged 8 commits into from
Jan 1, 2025

Conversation

im-vedant
Copy link
Contributor

@im-vedant im-vedant commented Jan 1, 2025

Issue Number:

Fixes #2499

Summary by CodeRabbit

  • Chores
    • Enhanced health check procedures in GitHub Actions workflows for production and development applications.
    • Introduced a new shell script for performing application health checks.
    • Improved modularity and maintainability of health check processes.

@im-vedant im-vedant requested a review from palisadoes as a code owner January 1, 2025 13:13
Copy link
Contributor

coderabbitai bot commented Jan 1, 2025

Walkthrough

The pull request introduces a new Bash script app_health_check.sh to standardize and modularize health check procedures in GitHub Actions workflows. The script replaces inline health check logic in the .github/workflows/pull-request.yml file, providing a more flexible and maintainable approach to checking application availability. It supports health checks for both Docker and non-Docker environments across different application ports, with configurable timeout and logging capabilities.

Changes

File Change Summary
.github/workflows/pull-request.yml Replaced inline health check logic with calls to app_health_check.sh script for production and development app checks
.github/workflows/scripts/app_health_check.sh New script added to perform standardized health checks with parameters for port, timeout, and Docker environment

Assessment against linked issues

Objective Addressed Explanation
Create health check script
Test docker and non-docker functionality
Maintain original GitHub action functionality
CodeRabbit.ai approval Requires CodeRabbit.ai review

Possibly related PRs

Suggested reviewers

  • palisadoes
  • varshith257
  • AVtheking
  • gautam-divyanshu
  • pranshugupta54

Poem

🐰 In workflows where health checks dance,
A script emerges with rabbit's glance.
Ports open, timeouts tick away,
Docker or bare, we check today.
Efficiency hops, code leaps with glee! 🚀


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

github-actions bot commented Jan 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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: 5

🧹 Nitpick comments (2)
.github/workflows/pull-request.yml (1)

343-344: Improve script permissions handling

The current approach of setting execute permissions during workflow execution is not ideal. Consider:

  1. Setting permissions at repository level
  2. Adding error handling for chmod operations

Either:

  1. Set permissions in the repository:
git update-index --chmod=+x .github/workflows/scripts/health_check.sh
git update-index --chmod=+x .github/workflows/scripts/health_check_no.sh

Or 2. Add error handling:

-chmod +x .github/workflows/scripts/health_check.sh
+if ! chmod +x .github/workflows/scripts/health_check.sh; then
+  echo "Failed to set execute permissions on health check script"
+  exit 1
+fi

Also applies to: 356-357, 393-394

.github/workflows/scripts/health_check_no.sh (1)

8-14: Enhance error handling and logging

The health check loop could benefit from improved error handling and debug logging.

+debug="${DEBUG:-false}"
+
 while ! nc -z localhost "${port}" && [ "${timeout}" -gt 0 ]; do
+  if [ "${debug}" = "true" ]; then
+    echo "Debug: nc exit code: $?"
+  fi
   sleep 1
   timeout=$((timeout-1))
   if [ $((timeout % 10)) -eq 0 ]; then
     echo "Still waiting for app to start... ${timeout}s remaining"
   fi
 done
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a60179f and 4733fdc.

📒 Files selected for processing (2)
  • .github/workflows/pull-request.yml (3 hunks)
  • .github/workflows/scripts/health_check_no.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
.github/workflows/scripts/health_check_no.sh

[error] 2-2: The shebang must be on the first line. Delete blanks and move comments.

(SC1128)

🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/scripts/health_check_no.sh

[warning] 1-1:
File ignored by default.

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.48%. Comparing base (b25ad26) to head (e26074f).
Report is 9 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3108       +/-   ##
=====================================================
+ Coverage             24.64%   89.48%   +64.83%     
=====================================================
  Files                   301      322       +21     
  Lines                  7628     8451      +823     
  Branches               1668     1843      +175     
=====================================================
+ Hits                   1880     7562     +5682     
+ Misses                 5621      657     -4964     
- Partials                127      232      +105     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 2

♻️ Duplicate comments (1)
.github/workflows/scripts/health_check_no.sh (1)

4-6: 🛠️ Refactor suggestion

Add parameter validation

The script accepts parameters but doesn't validate them, which could lead to runtime errors.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4733fdc and 29e7fbb.

📒 Files selected for processing (2)
  • .github/workflows/pull-request.yml (3 hunks)
  • .github/workflows/scripts/health_check_no.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/pull-request.yml
🧰 Additional context used
🪛 Shellcheck (0.10.0)
.github/workflows/scripts/health_check_no.sh

[error] 2-2: The shebang must be on the first line. Delete blanks and move comments.

(SC1128)

🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/scripts/health_check_no.sh

[warning] 1-1:
File ignored by default.

🔇 Additional comments (3)
.github/workflows/scripts/health_check_no.sh (3)

16-24: Consider adding HTTP health validation

The script only verifies if the port is open but doesn't validate if the service is responding correctly.


1-24: Update script permissions

The script needs executable permissions to function properly.

🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 2-2: The shebang must be on the first line. Delete blanks and move comments.

(SC1128)

🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[warning] 1-1:
File ignored by default.


1-2: ⚠️ Potential issue

Move shebang to first line

The shebang must be on the first line for proper script execution.

-# .github/workflows/scripts/health_check_no.sh
-#!/bin/bash
+#!/bin/bash
+# .github/workflows/scripts/health_check_no.sh

Likely invalid or redundant comment.

🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 2-2: The shebang must be on the first line. Delete blanks and move comments.

(SC1128)

🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[warning] 1-1:
File ignored by default.

.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 1, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 1, 2025
@Cioppolo14 Cioppolo14 requested review from noman2002 and beingnoble03 and removed request for palisadoes January 1, 2025 14:39
@palisadoes palisadoes added the ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files label Jan 1, 2025
Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

See comments

.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
.github/workflows/scripts/health_check_no.sh Outdated Show resolved Hide resolved
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: 2

🧹 Nitpick comments (1)
.github/workflows/scripts/app_health_check.sh (1)

3-19: Enhance documentation with parameter validation and exit codes

The documentation is well-structured, but could be improved by adding:

  • Valid ranges/requirements for parameters (e.g., port number constraints)
  • Description of exit codes (currently only implicitly mentioned)

Add these sections to the documentation:

 # Variables:
 # port="$1"        - The port to check (passed as the first argument to the script).
+#                    Must be a valid port number between 1-65535.
 # timeout="${2:-120}" - The maximum time in seconds to wait for the application to start. Defaults to 120 seconds if not provided.
+#                    Must be a positive integer.
 # is_docker_test="${3:-false}" - A flag to indicate whether the script is being run in a Docker-based test. Defaults to false.
+#                    Must be either "true" or "false".
+
+# Exit codes:
+# 0 - Health check passed successfully
+# 1 - Health check failed (timeout or invalid parameters)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 960a4b9 and 089a4fd.

📒 Files selected for processing (2)
  • .github/workflows/pull-request.yml (3 hunks)
  • .github/workflows/scripts/app_health_check.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/pull-request.yml
🧰 Additional context used
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/scripts/app_health_check.sh

[warning] 1-1:
File ignored by default.

🔇 Additional comments (1)
.github/workflows/scripts/app_health_check.sh (1)

1-1: Ensure proper file permissions and line endings

The script needs to be executable in the GitHub Actions environment.

Run this script to verify and fix permissions:

✅ Verification successful

Script requires executable permissions for GitHub Actions

The script currently has read-only permissions (-rw-r--r--), which will prevent it from being executed in the GitHub Actions environment. While we attempted to fix the permissions with chmod +x and git update-index --chmod=+x, we should verify if the changes were successful.


Script permissions have been properly set

The file permissions have been successfully updated:

  • File mode is now -rwxr-xr-x (755), making it executable for all users
  • Git index shows the file with mode 100755, confirming the executable bit is properly tracked in the repository

The script is now correctly configured for execution in the GitHub Actions environment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check file permissions and line endings
ls -l .github/workflows/scripts/app_health_check.sh
file .github/workflows/scripts/app_health_check.sh

# Fix permissions if needed
chmod +x .github/workflows/scripts/app_health_check.sh
git update-index --chmod=+x .github/workflows/scripts/app_health_check.sh

Length of output: 429


Script:

#!/bin/bash
# Verify if permissions were updated
ls -l .github/workflows/scripts/app_health_check.sh

# Check if the file is tracked by git and its executable bit is set
git ls-files -s .github/workflows/scripts/app_health_check.sh

Length of output: 308

🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[warning] 1-1:
File ignored by default.

.github/workflows/scripts/app_health_check.sh Show resolved Hide resolved
.github/workflows/scripts/app_health_check.sh Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 1, 2025
@palisadoes palisadoes self-requested a review January 1, 2025 20:41
Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

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: 1

🧹 Nitpick comments (4)
.github/workflows/scripts/app_health_check.sh (4)

3-19: Enhance documentation with usage examples and exit codes

The documentation is well-structured but could be more helpful with:

  • Example usage: ./app_health_check.sh 4321 120 true
  • Exit codes: 0 for success, 1 for failures

Add these sections to the documentation:

 # 4. If the port is detected as open, print a success message and exit.
+
+# Usage:
+#   ./app_health_check.sh <port> [timeout] [is_docker_test]
+# Example:
+#   ./app_health_check.sh 4321 120 true
+
+# Exit codes:
+#   0 - Success: Application is running on the specified port
+#   1 - Error: Invalid parameters or health check failed

22-24: Improve variable initialization robustness

Make the variables readonly to prevent accidental modification and ensure proper quoting.

Apply this diff:

-port="$1"
-timeout="${2:-120}"
-is_docker_test="${3:-false}"
+readonly port="$1"
+readonly timeout="${2:-120}"
+readonly is_docker_test="${3:-false}"

74-74: Maintain consistent message format

The success message format doesn't match the error message format used elsewhere in the script.

Apply this diff:

-echo "App started successfully on port ${port}"
+echo "Success: Application is responding on port ${port}"

58-58: Add check for netstat command availability

The script uses netstat for debugging but doesn't verify its availability first.

Add command availability check at the beginning of the script:

 readonly DOCKER_CONTAINER_NAME="${DOCKER_CONTAINER_NAME:-talawa-admin-app-container}"
+
+# Check if netstat is available for debugging
+NETSTAT_AVAILABLE=false
+if command -v netstat >/dev/null 2>&1; then
+    NETSTAT_AVAILABLE=true
+fi

Then update the netstat usage:

-    netstat -an | grep "${port}" || true
+    if [ "${NETSTAT_AVAILABLE}" = true ]; then
+        netstat -an | grep "${port}" || true
+    else
+        echo "Note: netstat not available for additional debugging information"
+    fi

Also applies to: 65-65

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 089a4fd and 862d2d4.

📒 Files selected for processing (1)
  • .github/workflows/scripts/app_health_check.sh (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/scripts/app_health_check.sh

[warning] 1-1:
File ignored by default.

🔇 Additional comments (1)
.github/workflows/scripts/app_health_check.sh (1)

68-70: 🛠️ Refactor suggestion

Make Docker container name configurable

The Docker container name is hardcoded, which reduces script reusability.

Add container name configuration at the beginning of the script:

 readonly is_docker_test="${3:-false}"
+
+# Configuration
+readonly DOCKER_CONTAINER_NAME="${DOCKER_CONTAINER_NAME:-talawa-admin-app-container}"

 # Validate required port parameter

Then update the Docker logs section:

-    if ! docker logs talawa-admin-app-container; then
-      echo "Error: Failed to fetch logs from container talawa-admin-app-container"
+    if ! docker logs "${DOCKER_CONTAINER_NAME}"; then
+      echo "Error: Failed to fetch logs from container ${DOCKER_CONTAINER_NAME}"

Likely invalid or redundant comment.

.github/workflows/scripts/app_health_check.sh Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 1, 2025
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: 1

🧹 Nitpick comments (2)
.github/workflows/scripts/app_health_check.sh (2)

3-19: Enhance documentation with usage examples and dependencies

The documentation is well-structured, but could be improved by adding:

  1. Usage examples showing different parameter combinations
  2. List of required system dependencies (nc, netstat)

Add the following section after the existing documentation:

 # 4. If the port is detected as open, print a success message and exit.

+# Dependencies:
+# - netcat (nc): Required for port checking
+# - netstat: Required for port status information
+#
+# Usage examples:
+# Check port 4173 with default timeout:
+#   ./app_health_check.sh 4173
+#
+# Check port 4321 with 60s timeout:
+#   ./app_health_check.sh 4321 60
+#
+# Check port 4321 in Docker environment:
+#   ./app_health_check.sh 4321 120 true

22-24: Make Docker container name configurable

The Docker container name should be configurable via an environment variable to improve script flexibility.

Add this configuration at the beginning of the script:

 port="$1"
 timeout="${2:-120}"
 is_docker_test="${3:-false}"
+
+# Docker container name can be configured via environment variable
+DOCKER_CONTAINER=${DOCKER_CONTAINER:-talawa-admin-app-container}

Then update the Docker logs command accordingly:

-    if ! docker logs talawa-admin-app-container; then
-      echo "Error: Failed to fetch logs from container talawa-admin-app-container"
+    if ! docker logs "${DOCKER_CONTAINER}"; then
+      echo "Error: Failed to fetch logs from container ${DOCKER_CONTAINER}"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 862d2d4 and e26074f.

📒 Files selected for processing (1)
  • .github/workflows/scripts/app_health_check.sh (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/scripts/app_health_check.sh

[warning] 1-1:
File ignored by default.

🔇 Additional comments (1)
.github/workflows/scripts/app_health_check.sh (1)

27-43: LGTM! Comprehensive parameter validation

The validation logic is thorough and handles all edge cases correctly:

  • Port number validation ensures it's within valid range (1-65535)
  • Timeout validation ensures it's a positive integer
  • Docker test flag validation ensures it's a boolean value

.github/workflows/scripts/app_health_check.sh Show resolved Hide resolved
@palisadoes palisadoes self-requested a review January 1, 2025 22:00
@palisadoes palisadoes merged commit 96a343e into PalisadoesFoundation:develop-postgres Jan 1, 2025
16 checks passed
@im-vedant im-vedant deleted the temp branch January 11, 2025 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants