Skip to content

Implement a proper heath check for containers #271

@josecelano

Description

@josecelano

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions