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

add "as: :rails_health_check" to health check path #47217

Merged
merged 2 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions guides/source/action_controller_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -1297,10 +1297,12 @@ While any newly generated Rails applications will have the health check at `/up`

```ruby
Rails.application.routes.draw do
get "healthz" => "rails/health#show"
get "healthz" => "rails/health#show", as: :rails_health_check
end
```

The health check will now be accessible via the `/healthz` path.

NOTE: This endpoint is not designed to give the status of all of your application's dependencies, such as the database or redis cluster. It is also not recommended to use those for health checks, in general, as it can lead to situations where your application is being restarted due to a third-party service going bad. Ideally, you should design your application to handle those outages gracefully.
NOTE: This endpoint does not reflect the status of all of your service's dependencies, such as the database or redis cluster. Replace "rails/heath#show" with your own controller action if you have application specific needs.
Copy link
Member

Choose a reason for hiding this comment

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

@rubys My only knit is that we should be using "application's dependencies" here, I know it's bikeshedding but we refer to them as Rails Apps everywhere so trying to be consistent. When I first wrote this part, I also used "service" coincidentally 😂

I'm going to update this part, but appreciate you updating the docs here, it re-affirms my instincts about not putting too much cruft in a health check :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zzak go for it. Those weren't my words, so I didn't change them.

I'm afraid that we are going to need to agree to disagree about "putting too much cruft in a health check". 😄 Over the next few days I'll be writing up a blog post about health checks and fly.io. I'll be putting everything in a positive light, but the net of it will be that we provide tcp checks (i.e. "is the app listening on the socket?") without any need for any app support. Adding a http check (e.g., with a minimal "/up" endpoint) does add some value, but it is minimal. Routing around regional failures require a bit more, and there things like easymon or rails-healthcheck come in handy.

When the post is ready, it will be posted here: https://fly.io/ruby-dispatch/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And the promised post is finally live: https://fly.io/ruby-dispatch/health-checks/


Think carefully about what you what to check as it can lead to situations where your application is being restarted due to a third-party service going bad. Ideally, you should design your application to handle those outages gracefully.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Rails.application.routes.draw do

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show"
get "up" => "rails/health#show", as: :rails_health_check

# Defines the root path route ("/")
# root "articles#index"
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/health_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# ```ruby
# Rails.application.routes.draw do
# get "healthz" => "rails/health#show"
# get "healthz" => "rails/health#show", as: :rails_health_check
# end
# ```
#
Expand Down
2 changes: 1 addition & 1 deletion railties/test/application/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def index

app_file "config/routes.rb", <<-RUBY
Rails.application.routes.draw do
get "up" => "rails/health#show"
get "up" => "rails/health#show", as: :rails_health_check
end
RUBY

Expand Down
2 changes: 1 addition & 1 deletion railties/test/rails_health_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class HealthControllerTest < ActionController::TestCase

def setup
Rails.application.routes.draw do
get "/up" => "rails/health#show"
get "/up" => "rails/health#show", as: :rails_health_check
end
@routes = Rails.application.routes
end
Expand Down