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

Healthcheck feature #564

Open
delanym opened this issue Aug 28, 2024 · 6 comments
Open

Healthcheck feature #564

delanym opened this issue Aug 28, 2024 · 6 comments

Comments

@delanym
Copy link

delanym commented Aug 28, 2024

How about creating a healthcheck?

I'd like my proxy to wait until redmine container is ready before starting.

@jcormier
Copy link
Collaborator

Any suggestions would be appreciated.

@delanym
Copy link
Author

delanym commented Aug 30, 2024

A default healthcheck was added in Rails 7.1
https://guides.rubyonrails.org/action_controller_overview.html#built-in-health-check-endpoint

Which will be available in Redmine 6
https://www.redmine.org/issues/36320

So until then one would need to create a custom healthcheck as described in
https://blog.saeloun.com/2023/02/27/rails-introduces-default-health-check-controller/

@delanym
Copy link
Author

delanym commented Aug 30, 2024

Dockerfile:

COPY routes.rb /usr/src/redmine/config/
COPY health_check_controller.rb /usr/src/redmine/app/controllers/
COPY healthcheck.sh /usr/src/redmine/
RUN chmod +x /usr/src/redmine/healthcheck.sh

healthcheck.sh:

#!/bin/sh
wget --no-verbose --tries=1 --spider http://localhost:3000/health_check 1>/dev/null 2>&1 

Use like

    healthcheck:
      test: ["CMD-SHELL", "healthcheck.sh"]
      start_period: 3s                                   
      interval: 10s                                
      timeout: 5s
      retries: 3

Now only problem is the logs fill up with 13 lines of health check every 10 seconds

redmine-1  | I, [2024-08-30T11:55:51.934301 #1]  INFO -- : Started HEAD "/health_check" for 127.0.0.1 at 2024-08-30 11:55:51 +0000
redmine-1  | I, [2024-08-30T11:55:51.935076 #1]  INFO -- : Processing by HealthCheckController#show as */*
redmine-1  | I, [2024-08-30T11:55:51.938317 #1]  INFO -- :   Current user: anonymous
redmine-1  | I, [2024-08-30T11:55:51.939111 #1]  INFO -- : Redirected to http://localhost:3000/login?back_url=http%3A%2F%2Flocalhost%3A3000%2Fhealth_check
redmine-1  | I, [2024-08-30T11:55:51.939247 #1]  INFO -- : Filter chain halted as :check_if_login_required rendered or redirected
redmine-1  | I, [2024-08-30T11:55:51.939408 #1]  INFO -- : Completed 302 Found in 4ms (ActiveRecord: 1.2ms | Allocations: 639)
redmine-1  | I, [2024-08-30T11:55:51.941697 #1]  INFO -- : Started HEAD "/login?back_url=http%3A%2F%2Flocalhost%3A3000%2Fhealth_check" for 127.0.0.1 at 2024-08-30 11:55:51 +0000
redmine-1  | I, [2024-08-30T11:55:51.942605 #1]  INFO -- : Processing by AccountController#login as */*
redmine-1  | I, [2024-08-30T11:55:51.942683 #1]  INFO -- :   Parameters: {"back_url"=>"http://localhost:3000/health_check"}
redmine-1  | I, [2024-08-30T11:55:51.946135 #1]  INFO -- :   Current user: anonymous
redmine-1  | I, [2024-08-30T11:55:51.949176 #1]  INFO -- :   Rendered account/login.html.erb within layouts/base (Duration: 2.0ms | Allocations: 521)
redmine-1  | I, [2024-08-30T11:55:52.109646 #1]  INFO -- :   Rendered layout layouts/base.html.erb (Duration: 162.5ms | Allocations: 28559)
redmine-1  | I, [2024-08-30T11:55:52.109955 #1]  INFO -- : Completed 200 OK in 167ms (Views: 112.2ms | ActiveRecord: 52.3ms | Allocations: 29208)

@delanym
Copy link
Author

delanym commented Aug 30, 2024

@jcormier
Copy link
Collaborator

COPY routes.rb /usr/src/redmine/config/
COPY health_check_controller.rb /usr/src/redmine/app/controllers/

I don't think we should be making changes to the redmine application in this docker image. Can we get away with fetching the /login URL until redmine adds a valid healthcheck?

@delanym
Copy link
Author

delanym commented Aug 30, 2024

Well its not the Redmine application per se we're changing - we're adding a route and a controller to the underlying Rails web server. If its set to /up then it pre-empts the coming healthcheck in Rails 7.1 anyway so there's no chance of a collision.

The problem with hitting /login (apart from confusing metrics consumers) is all the logs, and to silence them requires changing controllers anyway. I'm still figuring out how to silence calls to an endpoint.

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

No branches or pull requests

2 participants