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

Conversation

rubys
Copy link
Contributor

@rubys rubys commented Feb 1, 2023

This makes the path discoverable even if the name or even the controller action changes.

Motivation / Background

Adding health checks (#46936) is a good idea. We are already seeing people varying the name. Or providing different implementations. All of that is fine, as long as the health check endpoint is discoverable. This pull request provides a way to discover the endpoint using something along the lines of:

Rails.application.routes.url_helpers.rails_health_check_path

Detail

This Pull Request adds as: :rails_health_check to health check path

Additional information

Rails 7.1 provides a rails/health#show controller action that does no application specific checks, which is goodness and satisfies many needs. The guide before this pull request goes further and recommends against providing application specific checks, which may be going too far.

A real world example, that actually happened at fly.io. A customer application was deployed in multiple geographic regions, something we support and highly recommend. That application happened to depend on S3, which is by no means atypical. It came to pass that a S3 regional outage occurred - something that isn't common, but not unheard of.

Health checks in instances of this application in affected regions started to fail. Fly's infrastructure used this information to route requests to instances where the request would succeed. The application remained up during this outage.

This is a scenario that I would very much like to support. And the cost of doing so to Rails is minimal: a named route and change in the guide from saying "don't do it" to something along the lines of "think carefully before you proceed".

cc: @dhh @rafaelfranca

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

It is not clear to me whether a CHANGELOG entry is needed for this change.

This makes the path discoverable even if the name or even the
controller action changes.
@dhh dhh merged commit 50cb28a into rails:main Feb 5, 2023
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/

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

Successfully merging this pull request may close these issues.

None yet

3 participants