-
Notifications
You must be signed in to change notification settings - Fork 24
Implement health check for the Index container #395
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
Implement health check for the Index container #395
Conversation
5c71143
to
aa08bb2
Compare
aa08bb2
to
307b41d
Compare
307b41d
to
02f8bf5
Compare
02f8bf5
to
9aac0c9
Compare
This is how it looks while starting: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0496f94ce2f torrust-index "/usr/local/bin/entr…" 5 seconds ago Up 3 seconds (health: starting) 0.0.0.0:3001-3002->3001-3002/tcp, :::3001-3002->3001-3002/tcp torrust-index-1
2387a1402423 torrust/tracker:develop "/usr/local/bin/entr…" 5 seconds ago Up 3 seconds 0.0.0.0:1212->1212/tcp, :::1212->1212/tcp, 0.0.0.0:7070->7070/tcp, :::7070->7070/tcp, 0.0.0.0:6969->6969/udp, :::6969->6969/udp torrust-tracker-1
147594c5c442 mysql:8.0 "docker-entrypoint.s…" 5 seconds ago Up 4 seconds (healthy) 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp torrust-mysql-1
8a3d58ce84aa dockage/mailcatcher:0.8.2 "entrypoint mailcatc…" 5 seconds ago Up 4 seconds 0.0.0.0:1025->1025/tcp, :::1025->1025/tcp, 0.0.0.0:1080->1080/tcp, :::1080->1080/tcp torrust-mailcatcher-1 And this is when is healthy: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82ec9d15fb87 torrust-index "/usr/local/bin/entr…" 21 seconds ago Up 20 seconds (healthy) 0.0.0.0:3001-3002->3001-3002/tcp, :::3001-3002->3001-3002/tcp torrust-index-1
858c668d3cab torrust/tracker:develop "/usr/local/bin/entr…" 21 seconds ago Up 20 seconds 0.0.0.0:1212->1212/tcp, :::1212->1212/tcp, 0.0.0.0:7070->7070/tcp, :::7070->7070/tcp, 0.0.0.0:6969->6969/udp, :::6969->6969/udp torrust-tracker-1
b05a2efef1a5 mysql:8.0 "docker-entrypoint.s…" 21 seconds ago Up 20 seconds (healthy) 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp torrust-mysql-1
647055d30674 dockage/mailcatcher:0.8.2 "entrypoint mailcatc…" 21 seconds ago Up 20 seconds 0.0.0.0:1025->1025/tcp, :::1025->1025/tcp, 0.0.0.0:1080->1080/tcp, :::1080->1080/tcp |
9aac0c9
to
9c6c202
Compare
9c6c202
to
c3eedc0
Compare
The solution works, but in order to run tests with independent ports, I need to add a new option in the settings: #...
[net]
port = 3001
#...
[health_check]
port = 3002
#... Because we need to bind the service to different ports for each test to avoid port collisions. E2E tests work because they use only one shared env. I would prefer to add a healthcheck endpoint to the API, but since we also have the "statistics importer", I don't like to check if the importer is working from inside the API. Unless both services (The API and the importer) use another service to report their status. We could inject that service into both services. For the time being, I think prefer to continue with the current solution because I think API and importer should not be coupled anyway. The |
c3eedc0
to
c094557
Compare
c094557
to
05d7ac9
Compare
Finally, instead of having one new API only for the health checker service I decided to add an API to the importer (cronjob). So we have two APIs in the Index:
The reason why I changed my mind is we need to implement a communication mechanism between the cronjob and the health checker API, that couples the importer to the checker, so we would need anyway an API for the importer (I discarded other solutions because they seemed to be too complex). At this point, I prefer both services to have their own health checker and expose the status via an API endpoint. This way they are decoupled. I still have to add a new configuration option for the importer with the API port. Tests are failing because they are trying to bind the socket to the same address 3002. We need to add the config option and bind to free ports when we create ephemeral configurations for isolated servers. |
05d7ac9
to
a392ea1
Compare
f18bad5
to
2a2d625
Compare
2a2d625
to
af06cfb
Compare
ACK 0e8b32b |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #395 +/- ##
===========================================
+ Coverage 42.05% 42.27% +0.21%
===========================================
Files 79 80 +1
Lines 4829 4887 +58
===========================================
+ Hits 2031 2066 +35
- Misses 2798 2821 +23 ☔ View full report in Codecov by Sentry. |
For both services: - The Index API - The Tracker Stattistics Importer (console cronjob) An API was added for the Importer. The Importer API has two endpoints: - GET /health_check -> to get the crobjob status. It only checks that is running periodically. - POST /heartbeat -> used by the cronjob to inform it's alive. And a new endpoint was added the the Index API: - GET /health_check -> to check API responsiveness.
af06cfb
to
0e8b32b
Compare
Hi @da2ce7, this is ready for review. I can do the same for the Tracker. Although adding an API to the importer seems to be too much, the API is just a few lines and enormously increases the service's observability. It can be helpful for other things in the future. Some examples:
|
After discussing how to implement a proper container HEALTHCHECK for the Index this final implementation:
curl
,wget
or other system dependency to avoid maintaining that dependency and security attacks. It uses a new binary that you can use like this:cargo run --bin health_check http://localhost:PORT/health_check
./health_check
endpoint in both APIs: the Index API and the Importer API (console cronjob).You can run the
health_check
from inside the container with the following commands:For the API:
For the Importer:
NOTES
health_check
handlers like checking database connection, SMTP server, connection to the tracker, etcetera. However, I don't know if we should check those things here. This healthcheck is only to ensure the container's processes are up and running. Maybe it's not the right place to check its dependencies. Those dependencies can fail at runtime. Maybe a better approach would be to monitor each service independently./health_check
endpoint could be used for monitoring.healthy
afterdocker compose up
.