-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from juan-apa/add-healthcheck-request-silencer
Add healthcheck request silencer
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
# Taken from https://github.com/rails/rails/pull/52789. | ||
# Once the app is updated to Rails 8, this file can be removed. | ||
# | ||
# | ||
# Allows you to silence requests made to a specific path. | ||
# This is useful for preventing recurring requests like healthchecks from clogging the logging. | ||
# This middleware is used to do just that against the path /up in production by default. | ||
# | ||
# Example: | ||
# | ||
# config.middleware.insert_before \ | ||
# Rails::Rack::Logger, Rails::Rack::SilenceRequest, path: "/up" | ||
# | ||
class SilenceRequest | ||
def initialize(app, path:) | ||
@app = app | ||
@path = path | ||
end | ||
|
||
def call(env) | ||
if env['PATH_INFO'] == @path | ||
Rails.logger.silence { @app.call(env) } | ||
else | ||
@app.call(env) | ||
end | ||
end | ||
end |