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

Fix nodes not getting set to offline when disconnects #2131

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kradalby
Copy link
Collaborator

@kradalby kradalby commented Sep 13, 2024

Fixes #2129

Summary by CodeRabbit

  • New Features

    • Introduced a new test case to enhance testing for subnet router failover during node disconnections.
    • Added functionality for disconnecting multiple containers from a network, improving test management.
  • Bug Fixes

    • Enhanced validation processes for system resilience under network disruptions.
    • Improved logging and error handling for long polling operations.

Signed-off-by: Kristoffer Dalby <[email protected]>
Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

The pull request introduces enhancements to the integration testing framework by adding a new test case, TestHASubnetRouterFailoverWhenNodeDisconnects2129, which evaluates the failover functionality of a high-availability subnet router when a node disconnects. Additionally, new methods for managing container connections are introduced in integration/scenario.go. These changes aim to ensure better validation of system resilience under network disruptions.

Changes

Files Change Summary
.github/workflows/test-integration.yaml, integration/route_test.go Added a new test case TestHASubnetRouterFailoverWhenNodeDisconnects2129 to validate failover behaviour.
integration/scenario.go Introduced DisconnectContainers, DisconnectContainersFromScenario, and ConnectContainersToScenario functions to manage container disconnections and connections in the network.

Assessment against linked issues

Objective Addressed Explanation
Node should go offline after disconnection (#2129)
Validate failover of routes during node disconnection (#2129)

Possibly related PRs

Poem

In the realm of code, we hop and play,
With routers and tests, we pave the way.
A node disconnects, but fear not, my friend,
For failover's grace will surely transcend.
With containers in line, we manage with care,
Robustness achieved, in the code we share! 🐇✨

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

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

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

Outside diff range and nitpick comments (1)
integration/route_test.go (1)

1327-1328: Please address the commented-out line.

Either uncomment the line defer scenario.ShutdownAssertNoPanics(t) if it's required for the test, or remove it entirely to keep the code clean.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe68f50 and 1ec99c5.

Files selected for processing (3)
  • .github/workflows/test-integration.yaml (1 hunks)
  • integration/route_test.go (2 hunks)
  • integration/scenario.go (1 hunks)
Additional comments not posted (3)
.github/workflows/test-integration.yaml (1)

61-61: Excellent addition of a new test case!

The new test case TestHASubnetRouterFailoverWhenNodeDisconnects2129 is a great addition to improve the test coverage for the scenario described in issue #2129. The test name clearly describes the scenario it is testing and follows the naming convention of other test cases. It is added to the appropriate place in the existing list of integration tests.

No other changes are required in this file to support the addition of this test case.

integration/scenario.go (1)

653-665: LGTM!

The DisconnectContainers function is a valuable addition to the Scenario struct. It provides the ability to selectively disconnect containers from the network, enhancing the control and flexibility of the integration tests.

The implementation is sound, with proper error handling and checks for container existence. This function will be useful for simulating network disruptions and testing the system's behaviour under such conditions.

Great work on improving the test suite's capabilities!

integration/route_test.go (1)

1319-1517: The test implementation looks good!

The test effectively verifies the failover behaviour of HA subnet routers when a node disconnects. It sets up the scenario correctly, advertises and enables routes properly, simulates the node disconnection realistically, and makes relevant assertions at each stage. The test structure and flow are clear and comprehensive.

Signed-off-by: Kristoffer Dalby <[email protected]>
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

Outside diff range and nitpick comments (2)
integration/scenario.go (2)

656-662: Consider logging a warning if a container is not found in the pool.

The function correctly handles the case where a container might not exist in the pool by using the comma ok idiom. However, it might be beneficial to log a warning in such cases, as it could indicate a potential issue in the test setup.

Apply this diff to log a warning:

 if ctr, ok := s.pool.ContainerByName(container); ok {
   err := ctr.DisconnectFromNetwork(s.network)
   if err != nil {
     return err
   }
+} else {
+  log.Printf("Warning: Container %s not found in the pool", container)
 }

670-676: Consider logging a warning if a container is not found in the pool.

Similar to the DisconnectContainersFromScenario function, it might be beneficial to log a warning if a container is not found in the pool, as it could indicate a potential issue in the test setup.

Apply this diff to log a warning:

 if ctr, ok := s.pool.ContainerByName(container); ok {
   err := ctr.ConnectToNetwork(s.network)
   if err != nil {
     return err
   }
+} else {
+  log.Printf("Warning: Container %s not found in the pool", container)
 }
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1ec99c5 and 98a65c7.

Files selected for processing (3)
  • hscontrol/poll.go (4 hunks)
  • integration/route_test.go (2 hunks)
  • integration/scenario.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • integration/route_test.go
Additional comments not posted (4)
hscontrol/poll.go (4)

194-194: Capturing the start time is a good addition for logging purposes.

Introducing the start variable to record the start time of the long polling operation enables measuring the duration of various events within the function. This will provide valuable insights into the performance and timing of the long polling process, aiding in monitoring and debugging.


252-252: Including the duration in the cancellation log message adds valuable context.

Logging the time elapsed since the start of the long polling operation when a poll is cancelled provides additional insights into when the cancellation occurred. This information can be useful for understanding the timing and behaviour of poll cancellations, aiding in debugging and performance analysis.


256-257: Enhancing the context done log message with duration and error details improves debugging.

Logging the time elapsed since the start of the long polling operation and the associated error message when the poll context is done provides a more complete picture of the event. This additional information can greatly assist in understanding the timing and reason behind the context completion, making it easier to debug issues and monitor the system's behaviour.


348-348: Simplifying response handling and improving error messages enhances code clarity.

The changes made to directly use the http.Flusher interface for flushing responses, instead of relying on a ResponseController, streamline the response handling flow. This simplification makes the code easier to understand and maintain.

Additionally, the slight rephrasing of error messages related to keep-alive improves their clarity, making it easier for developers to comprehend and troubleshoot any issues that may arise.

Overall, these modifications enhance the code's readability and maintainability without altering the core functionality.

Also applies to: 362-372

Comment on lines +667 to +679
// ConnectContainersToScenario disconnects a list of containers from the network.
func (s *Scenario) ConnectContainersToScenario(containers ...string) error {
for _, container := range containers {
if ctr, ok := s.pool.ContainerByName(container); ok {
err := ctr.ConnectToNetwork(s.network)
if err != nil {
return err
}
}
}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting the common logic into a separate function to make the code more DRY.

The ConnectContainersToScenario and DisconnectContainersFromScenario functions share the same structure and logic, with the only difference being the specific action performed on the container (connect or disconnect). To make the code more DRY (Don't Repeat Yourself), consider extracting the common logic into a separate function that takes a function parameter for the specific action.

Here's an example of how the refactored code could look:

func (s *Scenario) performActionOnContainers(containers []string, action func(*dockertest.Container) error) error {
    for _, container := range containers {
        if ctr, ok := s.pool.ContainerByName(container); ok {
            err := action(ctr)
            if err != nil {
                return err
            }
        } else {
            log.Printf("Warning: Container %s not found in the pool", container)
        }
    }
    return nil
}

func (s *Scenario) DisconnectContainersFromScenario(containers ...string) error {
    return s.performActionOnContainers(containers, func(ctr *dockertest.Container) error {
        return ctr.DisconnectFromNetwork(s.network)
    })
}

func (s *Scenario) ConnectContainersToScenario(containers ...string) error {
    return s.performActionOnContainers(containers, func(ctr *dockertest.Container) error {
        return ctr.ConnectToNetwork(s.network)
    })
}

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.

[Bug] online status doesn't change if connection is interrupted
1 participant