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

(OraklNode) Check network condition and shutdown if necessary #2181

Merged
merged 4 commits into from
Aug 23, 2024

Conversation

nick-bisonai
Copy link
Collaborator

Description

Ping 3 major DNS which are expected to be stable enough
If all 3 DNS ping fails twice in a row, will shut down the application

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Aug 22, 2024
@nick-bisonai nick-bisonai requested a review from a team as a code owner August 22, 2024 15:34
Copy link
Contributor

coderabbitai bot commented Aug 22, 2024

Walkthrough

Walkthrough

The changes introduce a new ping check mechanism to the application, allowing for the monitoring of endpoint reachability. A cancellable context is implemented to manage the ping operation, which is executed asynchronously after a delay. Additionally, a new ping package is created, containing an application that configures and executes pings to specified endpoints, along with associated unit tests to ensure functionality and reliability.

Changes

Files Change Summary
node/cmd/node/main.go Added a ping check mechanism in the main function with a cancellable context and asynchronous execution after a 5-second delay.
node/pkg/checker/ping/app.go Introduced the app.go file to the ping package, implementing a configurable pinging application with an interface for ping operations and result handling.
node/pkg/checker/ping/app_test.go Created unit tests for the ping package, including cases for successful pings, failed pings, and application shutdown on multiple failures.

Poem

🐇 In the meadow, hops a rabbit bright,
With pings to check, oh what a sight!
Endpoints to reach, they leap and bound,
In code they frolic, new features found.
Hooray for changes, let joy take flight,
For every ping, the future is bright! 🌈


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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 39ae053 and 9a5e086.

Files ignored due to path filters (3)
  • go.work.sum is excluded by !**/*.sum, !**/*.sum
  • node/go.mod is excluded by !**/*.mod
  • node/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (3)
  • node/cmd/node/main.go (2 hunks)
  • node/pkg/checker/ping/app.go (1 hunks)
  • node/pkg/checker/ping/app_test.go (1 hunks)
Additional comments not posted (11)
node/cmd/node/main.go (3)

12-12: Import statement for ping package is correctly added.

The import statement is necessary for the new functionality and is correctly placed.


23-24: Context creation and cancellation are correctly implemented.

The use of context.WithCancel is appropriate for managing the lifecycle of the ping operation. The deferred cancellation ensures resources are properly released.


26-30: Goroutine for ping operation is correctly implemented.

The goroutine allows the ping operation to run asynchronously, which is suitable for non-blocking execution. The delay provides a buffer for application readiness.

However, consider verifying if the 5-second delay is optimal for your use case.

node/pkg/checker/ping/app_test.go (3)

30-53: Test case TestApp_Start_SuccessfulPing is well-structured.

The test verifies that a successful ping does not increment the fail count, and the use of a mock pinger allows for controlled testing of the ping logic.


55-75: Test case TestApp_Start_FailedPing is well-structured.

The test verifies that a failed ping increments the fail count, and the mock pinger simulates a ping failure effectively.


77-102: Test case TestApp_Start_ShutdownOnAllFailures is comprehensive.

The test verifies that the application shuts down when all endpoints fail to ping, and it uses mock pingers to simulate failures effectively.

node/pkg/checker/ping/app.go (5)

12-24: Constants and global endpoints are well-defined.

The constants provide clear configuration defaults, and the global endpoints are well-chosen for network stability checks.


26-40: PingerInterface and related types are well-structured.

The interface and types provide a clear abstraction for ping operations and results.


42-66: AppConfig and option functions are well-implemented.

The use of option functions is a common pattern for flexible configuration, and it is well-implemented here.


80-120: New function and initialization logic are comprehensive.

The initialization logic sets up pingers and result buffers correctly, ensuring the application is ready to run pings.


131-182: Start function and ping logic are effectively implemented.

The function manages concurrency and context well, and the logic for handling fail counts and shutdowns is crucial for resilience.

However, consider verifying the shutdown logic to ensure it behaves as expected under all failure scenarios.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9a5e086 and fb57a29.

Files selected for processing (1)
  • node/cmd/node/main.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • node/cmd/node/main.go

@Intizar-T
Copy link
Contributor

Intizar-T commented Aug 23, 2024

while the current implemetation is a good start, I think we can make it more robust considering these points:

  • Using more endpoints that the node app actually depends on (maybe few websocket connections as well). Since ICMP pings are lightweight, we might end up with false positives (thinking the network is fine when it's not).
  • Would be great to work with the infra team to spin up a gcp/aws instance for node until idc network recovers

i think both of these suggestions require quite a bit of work so not sure if they are realistic to implement within our current deadline

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fb57a29 and 36f8d1d.

Files selected for processing (3)
  • node/cmd/node/main.go (2 hunks)
  • node/pkg/checker/ping/app.go (1 hunks)
  • node/pkg/checker/ping/app_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • node/cmd/node/main.go
  • node/pkg/checker/ping/app.go
  • node/pkg/checker/ping/app_test.go

@nick-bisonai
Copy link
Collaborator Author

while the current implemetation is a good start, I think we can make it more robust considering these points:

  • Using more endpoints that the node app actually depends on (maybe few websocket connections as well). Since ICMP pings are lightweight, we might end up with false positives (thinking the network is fine when it's not).
  • Would be great to work with the infra team to spin up a gcp/aws instance for node until idc network recovers

i think both of these suggestions require quite a bit of work so not sure if they are realistic to implement within our current deadline

  • for the first suggestion we can add more endpoints, but since the logic is checking failure only when all endpoints fail, I'm not sure if it is highly possible to end up in false positive.

  • for the second one I'll ask if they have any plans

Copy link
Contributor

@Intizar-T Intizar-T left a comment

Choose a reason for hiding this comment

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

lgtm!

@nick-bisonai nick-bisonai merged commit dbf85c0 into master Aug 23, 2024
2 checks passed
@nick-bisonai nick-bisonai deleted the feat/network-check branch August 23, 2024 06:39
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