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 Health Check endpoint #392

Merged

Conversation

mckennajones
Copy link
Contributor

@mckennajones mckennajones commented Jan 13, 2023

Adds a simple health check endpoint as mentioned in #375. The endpoint at /health simply returns the version of the app and a health status. It will return 'healthy` unless it is unable to connect to the DB. Could easily add other checks as deemed appropriate.

Also added the health check to the Dockerfile so it will report it's health status. Example:

(venv) ➜  ~/temp/linkding git:(feature/health-endpoint) docker-compose up -d
[+] Running 1/1
 ⠿ Container linkding  Started                                                                                                                                         0.3s
(venv) ➜  ~/temp/linkding git:(feature/health-endpoint) docker ps
CONTAINER ID   IMAGE             COMMAND            CREATED          STATUS                            PORTS                    NAMES
19cd852b2d49   linkding-test:1   "./bootstrap.sh"   39 seconds ago   Up 3 seconds (health: starting)   0.0.0.0:9090->9090/tcp   linkding
(venv) ➜  ~/temp/linkding git:(feature/health-endpoint) docker ps
CONTAINER ID   IMAGE             COMMAND            CREATED          STATUS                             PORTS                    NAMES
19cd852b2d49   linkding-test:1   "./bootstrap.sh"   51 seconds ago   Up 15 seconds (health: starting)   0.0.0.0:9090->9090/tcp   linkding
(venv) ➜  ~/temp/linkding git:(feature/health-endpoint) docker ps
CONTAINER ID   IMAGE             COMMAND            CREATED              STATUS                    PORTS                    NAMES
19cd852b2d49   linkding-test:1   "./bootstrap.sh"   About a minute ago   Up 38 seconds (healthy)   0.0.0.0:9090->9090/tcp   linkding
(venv) ➜  ~/temp/linkding git:(feature/health-endpoint) rm -rf ./data

Wait 1 min 30s for 3 retries to occur.

(venv) ➜  ~/temp/linkding git:(feature/health-endpoint) docker ps
CONTAINER ID   IMAGE             COMMAND            CREATED         STATUS                     PORTS                    NAMES
19cd852b2d49   linkding-test:1   "./bootstrap.sh"   2 minutes ago   Up 2 minutes (unhealthy)   0.0.0.0:9090->9090/tcp   linkding

Btw, I'm not super familiar with django. Let me know if a middleware is not the appropriate way to add an endpoint like this.

Closes #375

bookmarks/middlewares.py Outdated Show resolved Hide resolved
siteroot/settings/base.py Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
@mckennajones
Copy link
Contributor Author

Thanks for the commits @sissbruecker 🙂. Should be closer now.

I also saw this older issue #272 and PR #273 that might be able to be closed out with the addition of this endpoint. Unless there is a use-case for an endpoint that solely returns the version.

@sissbruecker
Copy link
Owner

Thanks, looks good now 👍

Thanks for the heads up, yes I think the health check endpoint should suffice for retrieving the version for now.

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

Successfully merging this pull request may close these issues.

Add Health Check Endpoint for Container
2 participants