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

include django-health-check #4428

Open
goatwu1993 opened this issue Jun 29, 2023 · 6 comments
Open

include django-health-check #4428

goatwu1993 opened this issue Jun 29, 2023 · 6 comments

Comments

@goatwu1993
Copy link
Contributor

Description

  1. Installing the django-health-check.
  2. Add "health_check", "health_check.db" to INSTALLED_APPS
  3. Add "health_check.cache" to INSTALLED_APPS if cache enabled
  4. Add a health check endpoint to URL.
  5. Add Healthcheck to container image by adding this line to Dockerfile: HEALTHCHECK --interval=5m --timeout=3s --start-period=30s --retries=3 CMD python ./manage.py health_check

Not really sure if this sure be included in dev docker image.

Rationale

In a live setup, we use health-checks to see if an app or container is working right. AWS Application Load Balancer (ALB) uses an HTTP call to check health. AWS Elastic Container Service (ECS) does a health-check with a built-in method or a custom script. Other platforms like Kubernetes do similar checks.

@akashverma0786
Copy link

I am new here, can you please tell me what should i check in the function? connection with database or what else? Or Can someone help me here.

@goatwu1993
Copy link
Contributor Author

@akashverma0786 possibly create a flag in cookiecutter, include django healthcheck, and add the URL in the urls.py

@browniebroke
Copy link
Member

I think that's a pretty standard need when you need to deploy to prod, especially with Docker. One notable exception might be Heroku, maybe?

Not really sure if this sure be included in dev docker image.

Agree, I don't think it's needed for local development.

Side note, I wonder if the Celery checks would help resolve this old issue: #2727

@luzfcb
Copy link
Collaborator

luzfcb commented Jul 11, 2023

@browniebroke I've been using this lib in production and with the recent change in how Sentry charges things, one of the pending tasks for my team is to exclude any logs generated by this lib from being sent to Sentry. I unfortunately haven't had time to work on it yet.

@goatwu1993
Copy link
Contributor Author

goatwu1993 commented Jul 14, 2023

I think that's a pretty standard need when you need to deploy to prod, especially with Docker. One notable exception might be Heroku, maybe?

Not really sure if this sure be included in dev docker image.

Agree, I don't think it's needed for local development.

Side note, I wonder if the Celery checks would help resolve this old issue: #2727

@browniebroke

It seems Heroku does not have some health check mechanism.

#2727 Root cause is celery beat startup without the django_celery_beat_periodictask table. Using docker-compose's depends statement, making celery beat depends on the django service healthy will also do the trick.

     depends_on:
       django:
         condition: service_healthy

However, it is overkilled and over-complicated IMO. It can be fixed by including python manage.py migrate django_celery_beat or python manage.py migrate in celery-beat start up script.

#4459 to fix #2727

@foarsitter
Copy link
Collaborator

foarsitter commented Oct 24, 2023

I'm in for adding django-health-check as library but against adding or using it as HEALTHCHECK.

In my opinion Python is to slow for using it in aa healthcheck. 30s start-period is not something that is usable I think.

I found this snippet a while ago but don't remember where. It checks if there is something running at port 5000 and perfectly suitable for rolling updates with docker swarm services.

services:
  django:
    <<: *default-opts    
    command: /start
    healthcheck:
      test: /bin/bash -c "timeout 1 bash -c '</dev/tcp/localhost/5000' 2>/dev/null"
      start_period: 100s
      interval: 30s
      timeout: 30s
      retries: 5
    deploy:
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 24
      rollback_config:
        parallelism: 0
        order: stop-first
      update_config:
         order: start-first
         failure_action: rollback
         delay: 10s   

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

5 participants