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: properly return 503 status when shutdown was initiated #65

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

rustatian
Copy link
Member

@rustatian rustatian commented Jun 17, 2024

Reason for This PR

closes: roadrunner-server/roadrunner#1924

Description of Changes

  • Do not stop the Status server on RR stop, instead, return 503 until the main process exits.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Introduced a new field shutdownInitiated to enhance the health, jobs, plugin, and ready handlers for better management of service shutdowns.
    • Added new test TestShutdown503 to simulate and verify graceful shutdown scenarios with HTTP status checks.
  • Chores

    • Updated GitHub Actions schedule from weekly to daily.
    • Upgraded golangci/golangci-lint-action to version v6.0.1 and golangci-lint to v1.59.
    • Expanded .gitignore to include composer lock files.
  • Configuration Changes

    • Removed skip directories and adjusted linters settings in .golangci.yml.
    • Added new server configuration settings in rr-status-503.yaml.

@rustatian rustatian added the bug Something isn't working label Jun 17, 2024
@rustatian rustatian requested a review from wolfy-j June 17, 2024 10:58
@rustatian rustatian self-assigned this Jun 17, 2024
Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

The recent updates enhance the GitHub Actions workflow, linter configurations, and introduce a mechanism for managing graceful shutdowns in the server. Key enhancements include more frequent dependency updates, updated linting tools, and refined linting rules. Additionally, server behavior is improved by adding an atomic.Pointer[bool] to monitor shutdowns, ensuring the server handles requests gracefully during shutdown periods.

Changes

File(s) Change Summary
.github/dependabot.yml Schedule interval for dependency updates changed from weekly to daily.
.github/workflows/linters.yml Updated the golangci/golangci-lint-action from v3.7.0 to v6.0.1 and golangci-lint version from v1.54 to v1.59.
.golangci.yml Removed skip directories for linters, adjusted linter settings, and added exclusion rules for issues.
health.go, jobs.go, plugin.go, ready.go Added shutdownInitiated field (type *atomic.Pointer[bool]) to manage graceful shutdowns and updated methods to incorporate this field.
.gitignore Ignored **/composer.lock files.
tests/configs/.rr-status-503.yaml Introduced configuration for a server with specific settings regarding RPC, server command and relay, status address, logging, HTTP address, worker pool size, and endure grace period.
tests/plugin_test.go Added TestShutdown503 to simulate and validate the behavior of graceful shutdowns with HTTP requests.

Assessment against linked issues

Objective (Issue) Addressed Explanation
Fix the availability of status during graceful shutdown (#1924)

Poem

In the realm where code does play,
Daily checks now greet the day.
Linters fresh, error-free,
Shutdown handled gracefully.
Git ignites with files to block,
Smooth as lyrics in a mock.
Change, oh change, you guide our way,
In code’s vast, intricate ballet. 🐇✨


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.

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 593f2a5 and e0ea40c.

Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
Files selected for processing (9)
  • .github/dependabot.yml (1 hunks)
  • .github/workflows/linters.yml (1 hunks)
  • .golangci.yml (2 hunks)
  • health.go (2 hunks)
  • jobs.go (2 hunks)
  • plugin.go (10 hunks)
  • ready.go (2 hunks)
  • tests/configs/.rr-status-503.yaml (1 hunks)
  • tests/plugin_test.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • .github/dependabot.yml
  • .golangci.yml
  • tests/configs/.rr-status-503.yaml
Additional comments not posted (18)
.github/workflows/linters.yml (1)

19-19: Updated the GitHub Action and linter version to the latest. This is a good practice as it ensures compatibility and access to the latest features and fixes.

Also applies to: 21-21

jobs.go (2)

21-21: Introduced a shutdownInitiated field to manage shutdown state. Using atomic.Pointer ensures thread safety, which is crucial for concurrent access in a server environment.

Also applies to: 24-29


34-37: Properly handles the shutdown scenario by checking the shutdownInitiated status and returning a 503 status code. This aligns with the PR's objectives to improve shutdown behavior.

health.go (2)

16-16: Added shutdownInitiated to the Health struct to manage shutdown states using atomic.Pointer for thread safety. Consistent and appropriate use of concurrency mechanisms.

Also applies to: 19-24


29-32: Correctly handles the shutdown scenario by checking the shutdownInitiated status and returning a 503 status code. Ensures graceful degradation of service during shutdowns.

ready.go (2)

19-19: Added shutdownInitiated to the Ready struct to manage shutdown states using atomic.Pointer for thread safety. Consistent and appropriate use of concurrency mechanisms.

Also applies to: 22-27


32-35: Correctly handles the shutdown scenario by checking the shutdownInitiated status and returning a 503 status code. Ensures readiness checks respond appropriately during shutdowns.

plugin.go (9)

8-8: Import of sync/atomic added to manage atomic operations, aligning with the new shutdown handling logic.


28-28: Addition of the Has method in the Configurer interface allows checking for configuration existence, improving robustness.


36-36: Definition of the Checker interface is crucial for status checks, ensuring plugins can report their own status.


48-48: Clarification in the Readiness interface comment helps in understanding the readiness logic related to worker pool status.


57-67: Introduction of shutdownInitiated using atomic.Pointer ensures thread-safe handling of shutdown state across various server components.


85-85: Proper initialization of shutdownInitiated to false at the start of the Init method, ensuring correct default state.


96-98: Modification of the Serve method to include shutdown state in handlers. This change is critical for returning a 503 status during shutdowns.


131-132: Setting shutdownInitiated to true in the Stop method ensures that the server correctly signals a shutdown state.


187-189: Utility function toPtr added for generic pointer conversion, aiding in clean and reusable code for handling pointers.

tests/plugin_test.go (2)

4-4: Import additions to support the testing environment setup, including context handling and HTTP operations.


464-549: New test TestShutdown503 added to simulate graceful shutdown and verify that the server returns a 503 status correctly during the shutdown process. This test is crucial for ensuring the new functionality works as intended.

Signed-off-by: Valery Piashchynski <[email protected]>
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 e0ea40c and a19c773.

Files selected for processing (2)
  • tests/configs/.rr-status-503.yaml (1 hunks)
  • tests/plugin_test.go (6 hunks)
Files skipped from review as they are similar to previous changes (2)
  • tests/configs/.rr-status-503.yaml
  • tests/plugin_test.go

Signed-off-by: Valery Piashchynski <[email protected]>
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 a19c773 and 398033e.

Files ignored due to path filters (1)
  • tests/php_test_files/composer.lock is excluded by !**/*.lock
Files selected for processing (4)
  • .gitignore (1 hunks)
  • plugin.go (11 hunks)
  • tests/configs/.rr-status-503.yaml (1 hunks)
  • tests/plugin_test.go (10 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Files skipped from review as they are similar to previous changes (1)
  • tests/configs/.rr-status-503.yaml
Additional comments not posted (12)
plugin.go (6)

8-8: Added import sync/atomic to handle atomic operations on boolean values for shutdown initiation.


64-65: Introduced a shutdownInitiated field to track if a shutdown has been initiated. This is crucial to ensure that the status server can respond appropriately during the shutdown.


85-85: Correctly initializing the shutdownInitiated atomic pointer to false on plugin initialization. This ensures the plugin starts in a non-shutdown state.


96-98: Updated the handlers for /health, /ready, and /jobs to check the shutdownInitiated state. This modification is central to the PR's objective of ensuring these endpoints return a 503 status during shutdown.


131-131: Setting the shutdownInitiated to true in the Stop method to signal that a shutdown is in progress. This change is essential for the correct behavior during shutdown.


197-199: Utility function toPtr added to simplify the creation of pointers, particularly useful in the context of handling atomic operations with sync/atomic.

tests/plugin_test.go (6)

4-4: Import of context added to support context management in HTTP requests, aligning with best practices for handling request cancellation and timeouts.


36-36: Setup of the test environment using the endure container with a new configuration. This setup is crucial for testing the new functionality in an isolated environment.

Also applies to: 39-39, 43-43, 49-49


102-104: Proper cleanup using t.Cleanup to ensure the HTTP server is stopped after tests, preventing side effects on subsequent tests.


176-178: Repetition of the cleanup pattern in another test function, maintaining consistency across test cases.


248-250: Consistent use of cleanup steps across all test functions, which is a good practice to ensure clean test states.


576-578: Ensuring that the HTTP server is stopped in the cleanup phase of the shutdown test, which is critical for testing the new 503 functionality during shutdown.

@rustatian rustatian merged commit 70f5bda into master Jun 17, 2024
6 checks passed
@rustatian rustatian deleted the fix/k8s-503 branch June 17, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[🐛 BUG]: Status is not available during graceful shutdown
1 participant