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

chore: Remove shelljs use from backup command #37356

Merged
merged 5 commits into from
Nov 14, 2024
Merged

chore: Remove shelljs use from backup command #37356

merged 5 commits into from
Nov 14, 2024

Conversation

sharat87
Copy link
Member

@sharat87 sharat87 commented Nov 13, 2024

This is towards fixing appsmithctl into a modern component of the project. First order of business is to get rid of the shelljs dependency, since we don't really need it that seriously, and since it does weird stuff with require() that we can't use esbuild to build appsmithctl.

Further PRs will remove shelljs from other commands as well, and then we'll remove shelljs from our dependencies.

Automation

/test sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11814325698
Commit: 98261ee
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Wed, 13 Nov 2024 09:58:36 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Improved backup process with enhanced error handling and asynchronous checks for available disk space.
    • New function for executing commands with output capture added to utility functions.
  • Bug Fixes

    • Refined error messages for insufficient disk space and password mismatches during backup.
  • Tests

    • Expanded test suite for backup utilities and command execution, ensuring robust coverage of various scenarios.
  • Documentation

    • Updated formatting of numeric constants for better readability.

Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes in this pull request primarily focus on enhancing the backup.js script and its associated test suite. Key modifications include transitioning from synchronous to asynchronous operations for checking the supervisor status and available backup space. The error handling has been improved, and several constants have been reformatted for better readability. Additionally, new utility functions for command execution have been introduced, along with corresponding tests to ensure robustness and accuracy in the backup process.

Changes

File Path Change Summary
deploy/docker/fs/opt/appsmith/utils/bin/backup.js - Replaced synchronous shell command with asynchronous utils.execCommandSilent.
- Updated getAvailableBackupSpaceInBytes to be asynchronous with a path parameter.
- Scoped backupRootPath within try block.
- Refined error handling for encryption password retrieval.
- Adjusted cleanup process in finally block.
deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js - Updated tests for available space to use asynchronous checks.
- Modified error handling in checkAvailableBackupSpace.
- Expanded tests for backup path generation and cleanup scenarios.
- Refined tests for encryption password matching.
deploy/docker/fs/opt/appsmith/utils/bin/constants.js - Reformatted constants for readability: MIN_REQUIRED_DISK_SPACE_IN_BYTES and DURATION_BETWEEN_BACKUP_ERROR_MAILS_IN_MILLI_SEC.
- Added newline at the end of the file.
deploy/docker/fs/opt/appsmith/utils/bin/utils.js - Introduced execCommandReturningOutput for capturing command output.
- Updated execCommandSilent to use close event for process completion.
deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js - Added tests for execCommandReturningOutput covering various output scenarios.
- Included a simple test for execCommandSilent.

Possibly related PRs

Suggested labels

Bug, Task, Backend, DevOps Pod, Git Product, Git Platform Pod

Suggested reviewers

  • pratapaprasanna
  • abhvsn

🎉 In the realm of code, where backups reside,
Asynchronous magic now takes the stride.
With clearer paths and constants refined,
Error handling shines, leaving worries behind.
So let’s celebrate this code’s new grace,
In the world of backups, we’ve found our place! 🎊


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5f4a1f8 and 98261ee.

📒 Files selected for processing (2)
  • deploy/docker/fs/opt/appsmith/utils/bin/utils.js (2 hunks)
  • deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js
🔇 Additional comments (4)
deploy/docker/fs/opt/appsmith/utils/bin/utils.js (4)

157-157: LGTM: Improved stdio configuration

Setting stdio: "ignore" is appropriate for silent execution mode.


Line range hint 160-169: Good change: Using 'close' instead of 'exit' event

The 'close' event is more reliable as it ensures all stdio streams are flushed and closed.


177-177: Better error handling with error object propagation

Good improvement passing the actual error object instead of just rejecting.


Line range hint 156-179: Previous review feedback still applies

The implementation would benefit from additional safeguards as mentioned in the previous review:

  • Timeout mechanism for long-running commands
  • Stream backpressure handling
  • Error handling for spawn failures

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 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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 13, 2024
@sharat87
Copy link
Member Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

@sharat87
Copy link
Member Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

@sharat87 sharat87 marked this pull request as ready for review November 13, 2024 06:18
@sharat87 sharat87 added the ok-to-test Required label for CI label Nov 13, 2024
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

🧹 Outside diff range and nitpick comments (6)
deploy/docker/fs/opt/appsmith/utils/bin/backup.js (2)

20-25: LGTM! Consider enhancing the error message.

The supervisor check implementation is correct, but the error message could be more helpful.

-    console.error('Supervisor is not running, exiting.');
+    console.error('Supervisor service is not running. Please ensure the supervisor service is started before running backup.');

Line range hint 1-263: Excellent modernization of the backup utility.

The transition from shelljs to native Node.js features is well-executed. The consistent use of async/await, proper error handling, and secure backup encryption make this a robust implementation.

Consider adding retry mechanisms for critical operations like database export and archive creation, as these operations might fail due to temporary system conditions.

deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js (4)

15-18: Consider using a test-specific directory instead of root path

Using "/" as the test path might cause issues in different environments. Consider using a test-specific directory or mocking fsPromises.statfs.

-  const res = expect(await backup.getAvailableBackupSpaceInBytes("/"))
+  const testDir = os.tmpdir();
+  const res = expect(await backup.getAvailableBackupSpaceInBytes(testDir))

24-24: Fix test naming typos and improve clarity

Several test names contain typos or are unclear:

  • "Checkx" should be "Checks"
  • "hould" is duplicated
  • "Generates t" is incomplete
-it('Checkx the constant is 2 GB', () => {
+it('Checks if the constant is 2 GB', () => {

-it('Should not hould throw Error when the available size is >= MIN_REQUIRED_DISK_SPACE_IN_BYTES', () => {
+it('Should not throw Error when the available size is >= MIN_REQUIRED_DISK_SPACE_IN_BYTES', () => {

-it('Generates t', async () => {
+it('Generates temporary backup path', async () => {

Also applies to: 30-30, 33-33


Line range hint 147-157: Remove duplicate test case

This test case is duplicated. The second occurrence can be removed as it's identical to the previous test.

-test('Cleanup Backups when limit is 4 and there are 2 files', async () => {
-  const backupArchivesLimit = 4;
-  fsPromises.rm = jest.fn().mockImplementation(async (a) => console.log(a));
-  var backupFiles = ['file1','file2']
-  var expectedBackupFiles = ['file1','file2']
-  const res = await backup.removeOldBackups(backupFiles,backupArchivesLimit)
-  console.log(res)
-  expect(res).toEqual(expectedBackupFiles)
-})

Line range hint 10-13: Remove console.log statements from tests

Debug console.log statements should be removed from test cases. They add noise to test output and don't provide value in production code.

Also applies to: 116-119, 147-157, 190-193

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 38c2859 and 5f4a1f8.

📒 Files selected for processing (5)
  • deploy/docker/fs/opt/appsmith/utils/bin/backup.js (3 hunks)
  • deploy/docker/fs/opt/appsmith/utils/bin/backup.test.js (1 hunks)
  • deploy/docker/fs/opt/appsmith/utils/bin/constants.js (2 hunks)
  • deploy/docker/fs/opt/appsmith/utils/bin/utils.js (4 hunks)
  • deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • deploy/docker/fs/opt/appsmith/utils/bin/constants.js
🔇 Additional comments (5)
deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js (1)

1-3: LGTM! Clean and focused imports.

deploy/docker/fs/opt/appsmith/utils/bin/utils.js (2)

186-186: LGTM! Improved error handling and process management.

Good improvements:

  • Using "close" event ensures all streams are closed
  • Passing error object provides better debugging context
  • Ignoring stdio is appropriate for silent execution

Also applies to: 189-189, 206-206


221-221: LGTM! Export addition follows existing pattern.

deploy/docker/fs/opt/appsmith/utils/bin/backup.js (2)

235-237: LGTM! Efficient implementation using native fs promises.

The change from shell commands to native Node.js fs promises is a good improvement for performance and reliability.


263-263: LGTM! All necessary functions are exported.

The module exports are complete and well-organized.

deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js Outdated Show resolved Hide resolved
deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js Outdated Show resolved Hide resolved
deploy/docker/fs/opt/appsmith/utils/bin/utils.test.js Outdated Show resolved Hide resolved
deploy/docker/fs/opt/appsmith/utils/bin/utils.js Outdated Show resolved Hide resolved
@sharat87 sharat87 merged commit 748a5ec into release Nov 14, 2024
46 checks passed
@sharat87 sharat87 deleted the chore/ctl1 branch November 14, 2024 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI 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