Project

General

Profile

Actions

Feature #42008

closed

Expose default Rails health check endpoint "/up" for load balancers and uptime monitoring

Added by Lorenz Schori about 1 year ago. Updated 12 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Administration
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

There is a default health check controller available since rails 7.1 (PR).

Newly generated rails apps automatically expose this at the /up route (routes.rb.tt). Add this to redmine routes.rb as well.

Exposing a dedicated health check route makes deployments in containers and behind load balancers more robust and simplifies service monitoring.


Files

rails-health-check.diff (919 Bytes) rails-health-check.diff Lorenz Schori, 2024-12-17 15:25
Actions #1

Updated by Go MAEDA 12 months ago

  • Category set to Administration
  • Target version set to Candidate for next major release
Actions #2

Updated by Go MAEDA 11 months ago

  • Target version changed from Candidate for next major release to 6.0.4

Setting the target version to 6.0.4.

Actions #3

Updated by Go MAEDA 11 months ago

  • Subject changed from Expose default rails health check to Expose default Rails health check endpoint "/up" for load balancers and uptime monitoring
Actions #4

Updated by Go MAEDA 11 months ago

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch in r23487.
Thank you for your contribution.

Actions #5

Updated by Go MAEDA 10 months ago

  • Status changed from Resolved to Closed

Merged the change into the 6.0-stable branch in r23490.

Actions #6

Updated by Turnip Zoink 9 months ago

Lorenz Breu is there some way to silence the logs?

Every 10 seconds its 3 extra lines

│   I, [2025-03-19T22:19:49.434437 #1]  INFO -- : [29b001e9-fc72-4550-bdd2-748e155de0ea] Started HEAD "/up" for 127.0.0.1 at 2025-03-19 22:19:49 +0000                                                                                                       │
│   I, [2025-03-19T22:19:49.435432 #1]  INFO -- : [29b001e9-fc72-4550-bdd2-748e155de0ea] Processing by Rails::HealthController#show as */*                                                                                                                   │
│   I, [2025-03-19T22:19:49.436235 #1]  INFO -- : [29b001e9-fc72-4550-bdd2-748e155de0ea] Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)                                                                      │
│   I, [2025-03-19T22:19:59.509741 #1]  INFO -- : [20473365-09e2-4e80-9074-03c525c8f6ce] Started HEAD "/up" for 127.0.0.1 at 2025-03-19 22:19:59 +0000                                                                                                       │
│   I, [2025-03-19T22:19:59.510972 #1]  INFO -- : [20473365-09e2-4e80-9074-03c525c8f6ce] Processing by Rails::HealthController#show as */*                                                                                                                   │
│   I, [2025-03-19T22:19:59.512125 #1]  INFO -- : [20473365-09e2-4e80-9074-03c525c8f6ce] Completed 200 OK in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)                                                                      │
│   I, [2025-03-19T22:20:09.589080 #1]  INFO -- : [6470de22-e067-4b72-96ba-f6c7bacc9fd0] Started HEAD "/up" for 127.0.0.1 at 2025-03-19 22:20:09 +0000                                                                                                       │
│   I, [2025-03-19T22:20:09.590081 #1]  INFO -- : [6470de22-e067-4b72-96ba-f6c7bacc9fd0] Processing by Rails::HealthController#show as */*                                                                                                                   │
│   I, [2025-03-19T22:20:09.590881 #1]  INFO -- : [6470de22-e067-4b72-96ba-f6c7bacc9fd0] Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)                                                                      │
│   I, [2025-03-19T22:20:19.665771 #1]  INFO -- : [2b8759ba-54fa-4bea-96c1-6fbe7b29b1c7] Started HEAD "/up" for 127.0.0.1 at 2025-03-19 22:20:19 +0000                                                                                                       │
│   I, [2025-03-19T22:20:19.667103 #1]  INFO -- : [2b8759ba-54fa-4bea-96c1-6fbe7b29b1c7] Processing by Rails::HealthController#show as */*                                                                                                                   │
│   I, [2025-03-19T22:20:19.668246 #1]  INFO -- : [2b8759ba-54fa-4bea-96c1-6fbe7b29b1c7] Completed 200 OK in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)                                                                      │
│   I, [2025-03-19T22:20:29.746049 #1]  INFO -- : [8c019b39-2d7a-4efc-885d-9ebe952c2c83] Started HEAD "/up" for 127.0.0.1 at 2025-03-19 22:20:29 +0000                                                                                                       │
│   I, [2025-03-19T22:20:29.746955 #1]  INFO -- : [8c019b39-2d7a-4efc-885d-9ebe952c2c83] Processing by Rails::HealthController#show as */*                                                                                                                   │
│   I, [2025-03-19T22:20:29.747738 #1]  INFO -- : [8c019b39-2d7a-4efc-885d-9ebe952c2c83] Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)                                                                      │
│   I, [2025-03-19T22:20:39.823671 #1]  INFO -- : [d2579f09-c949-4956-9cbc-cb50f40c3065] Started HEAD "/up" for 127.0.0.1 at 2025-03-19 22:20:39 +0000                                                                                                       │
│   I, [2025-03-19T22:20:39.824705 #1]  INFO -- : [d2579f09-c949-4956-9cbc-cb50f40c3065] Processing by Rails::HealthController#show as */*                                                                                                                   │
│   I, [2025-03-19T22:20:39.825525 #1]  INFO -- : [d2579f09-c949-4956-9cbc-cb50f40c3065] Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)

I tried mounting

# app/controllers/rails/health_controller.rb
module Rails
  class HealthController < ActionController::Base
    def show
      puts "Custom HealthController is being used!" # Debug statement
      head :ok
    end

    # Silence logging for this action
    def log_process_action(payload)
      # Do nothing to prevent logging
    end
  end
end

and although I see the debug statement in the logs, the logs still show.

Then I tried disabling all logs

# app/controllers/rails/health_controller.rb
module Rails
  class HealthController < ActionController::Base
    def show
      # Silence all logs for this action
      Rails.logger.silence do
        head :ok
      end
    end
  end
end

but the logs still show.

Actions #7

Updated by Adam Heath 12 days ago

The logging happens outside the show method, so I'm not surprised that doesn't work. It definitely would be nice to have them turned off, I agree with the request. At least maybe change the level to TRACE or some such.

Actions #8

Updated by Holger Just 12 days ago

Rails 8 (which will be used with the upcoming Redmine 7.0) introduces a config.silence_healthcheck configuration option.

In older versions, a similar result could likely be achieve by setting a suitable log_at level for the HealthController, e.g log_at :error.

In any case though, this issue is closed. To discuss further improvements, you may open a new issue.

Actions

Also available in: Atom PDF