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

Handle retry for syncLoop and watchLoop #863

Merged
merged 2 commits into from
Jul 8, 2024
Merged

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented Jul 8, 2024

What this PR does / why we need it?

Handle retry for syncLoop and watchLoop based on ConnectError

This commit addresses the need to retry the syncLoop and watchLoop functions based on different error codes from ConnectError.

The Connect guide indicates that for error codes like ResourceExhausted and Unavailable, retries should be attempted following their guidelines: Error Codes.

Additionally, the Unknown and Canceled are added separately as it typically occurs when the server is stopped unexpectedly.

To enhance visibility into the status of syncLoop and watchLoop, Conditions has been added.

Any background context you want to provide?

What are the relevant tickets?

Fixes #

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Added support for network failure retry logic in the client.
    • Introduced ClientCondition for better client state management.
  • Improvements

    • Log level is now configurable and set to Debug by default for better troubleshooting.

Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

The recent updates introduce an enumeration ClientCondition to manage different states (SyncLoop and WatchLoop) within the Client class. Additionally, methods to set, retrieve, and utilize these conditions have been implemented. Error handling for retryable connection errors has been added, accompanied by necessary test cases. Exports have been updated to include the new ClientCondition and adjust the export of LogLevel in yorkie.ts. Finally, logging settings are modified in public/index.html.

Changes

Files Change Summary
src/client/client.ts Added ClientCondition enum and conditions property; updated processing property initialization; added and modified methods for managing conditions.
src/yorkie.ts Added ClientCondition to exported entities and changed LogLevel export from type to regular export.
test/integration/client_test.ts Added ClientCondition import and implemented a test case for retry logic.
public/index.html Set the log level to Debug using yorkie.setLogLevel(yorkie.LogLevel.Debug).

Poem

In code, new loops we now define,
With Sync and Watch in a line.
Conditions named, the client's might,
Retry and log through day and night.
Debug we set, to see it all,
Yorkie stands proud, answers the call. 🌟


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

@hackerwins hackerwins force-pushed the retrable-connect-error branch from 872fb03 to a35e640 Compare July 8, 2024 03:46
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.

Project coverage is 80.93%. Comparing base (4f7dcce) to head (69bc8c3).

Files Patch % Lines
src/client/client.ts 78.94% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #863      +/-   ##
==========================================
+ Coverage   80.89%   80.93%   +0.04%     
==========================================
  Files          60       60              
  Lines        4600     4615      +15     
  Branches      936      937       +1     
==========================================
+ Hits         3721     3735      +14     
- Misses        610      612       +2     
+ Partials      269      268       -1     

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

@hackerwins hackerwins marked this pull request as ready for review July 8, 2024 03:50
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4f7dcce and a35e640.

Files selected for processing (3)
  • src/client/client.ts (8 hunks)
  • src/yorkie.ts (2 hunks)
  • test/integration/client_test.ts (3 hunks)
Additional comments not posted (11)
src/yorkie.ts (2)

28-28: Export Addition Approved.

The addition of ClientCondition to the exports is correct.


116-116: Export Modification Approved.

The change to export LogLevel as a regular export is correct.

src/client/client.ts (7)

92-105: Enum Addition Approved.

The ClientCondition enum is correctly defined with SyncLoop and WatchLoop keys.


176-176: Property Addition Approved.

The conditions property is correctly added to hold boolean values for ClientCondition.


198-201: Property Initialization Approved.

The conditions property is correctly initialized in the constructor.


558-563: Method Addition Approved.

The getCondition method is correctly defined to return the condition of the client.


Line range hint 566-599: Method Addition Approved.

The runSyncLoop method is correctly defined to run the sync loop and handle retryable errors.


Line range hint 603-678: Method Addition Approved.

The runWatchLoop method is correctly defined to run the watch loop for the given document and handle retryable errors.


787-808: Method Addition Approved.

The isRetryableConnectError method is correctly defined to identify retryable errors.

test/integration/client_test.ts (2)

6-6: Import Addition Approved.

The import of ClientCondition from @yorkie-js-sdk/src/yorkie is correct.


768-802: Test Case Addition Approved.

The test case for network failure retry logic is correctly defined.

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a35e640 and 69bc8c3.

Files selected for processing (3)
  • public/index.html (1 hunks)
  • src/client/client.ts (8 hunks)
  • src/yorkie.ts (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/client/client.ts
  • src/yorkie.ts
Additional comments not posted (1)
public/index.html (1)

319-319: Ensure the log level setting is appropriate for the production environment.

Setting the log level to Debug is useful for development and debugging but may expose sensitive information or generate excessive logs in production. Ensure this setting is configured appropriately based on the environment.

@hackerwins hackerwins merged commit ff7d63a into main Jul 8, 2024
2 checks passed
@hackerwins hackerwins deleted the retrable-connect-error branch July 8, 2024 07:01
@@ -763,4 +765,39 @@ describe.sequential('Client', function () {
await cli.deactivate();
}
});

it('Should retry on network failure and eventually succeed', async ({

Choose a reason for hiding this comment

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

@hackerwins
Would you please explain why this tc doesn't assert the condition of WatchLoop?

err instanceof ConnectError &&
err.code != ConnectErrorCode.Canceled
) {
if (this.isRetryableConnectError(err)) {

Choose a reason for hiding this comment

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

@hackerwins
If the watchLoop stops due to this condition, when should it restart?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants