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

Implement a proper heath check for containers #271

Closed
josecelano opened this issue Sep 7, 2023 · 2 comments
Closed

Implement a proper heath check for containers #271

josecelano opened this issue Sep 7, 2023 · 2 comments
Labels

Comments

@josecelano
Copy link
Member

josecelano commented Sep 7, 2023

Relates to: #254

Context

We use docker-compose to start the E2E testing environment.

The bash script to start the environment is: https://github.com/torrust/torrust-index-backend/blob/develop/docker/bin/e2e/run-e2e-tests.sh

As you can see there a proper health check is implemented only for the MySQL container.

When we start the container, we should wait until they are "healthy" before using them.

There is no health check for the tracker and index backend container. We only wait for 20 seconds.

Problem

Sometimes workflows are broken because there are broken tests but the reason they are broken is because the service is not up and running (for example the tracker).

We should detect that problem before even running the tests.

Solution 1: Implement health-check for all container

The best one.

Solution 2: Detect that container are not running parsing the docker output

We can run docker ps and check that at least all containers are running.

Cons:

  • Volatile solution.

Solution 3: Add some custom checks to the bash script

We can make some basic requests to the public endpoints to check that the service is up.

For example, for the tracker:

TRACKER_STATUS_ENDPOINT="http://localhost:1212/api/v1/stats?token=MyAccessToken"

# Use curl to get the HTTP status code
HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $API_ENDPOINT)

# Check the status code
if [ $HTTP_STATUS -ne 200 ]; then
    echo "Error: Tracker service is not available"
    exit 1
fi

In the future, we should add a new status endpoint.

Conclusion

I would implement solution 3 now to avoid misleading error messages on workflow executions. And solution 1 in the long term.

We should do the same in the Tracker and Frontend projects, wherever we need to wait until the containers are ready.

cc @da2ce7

@josecelano
Copy link
Member Author

Solution 1 depends on #254

@josecelano
Copy link
Member Author

Done via #395

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

No branches or pull requests

1 participant