Complete the code to define a basic health check endpoint in a microservice.
GET /health [1] 200 OK
The health check endpoint responds with a 200 OK status to indicate the service is healthy.
Complete the code to implement a health check that verifies database connectivity.
if database.[1](): return 'healthy' else: return 'unhealthy'
The ping() method is commonly used to check if the database connection is alive.
Fix the error in the health check code that incorrectly returns the status.
def health_check(): status = 'healthy' if service.is_up() else [1] return status
The health check should return 'unhealthy' when the service is down, not True or False.
Fill both blanks to complete the health check that verifies both cache and database status.
def health_check(): cache_status = cache.[1]() db_status = database.[2]() if cache_status and db_status: return 'healthy' else: return 'unhealthy'
The cache uses ping() to check connectivity, and the database uses connect() to verify connection.
Fill all three blanks to complete the health check dictionary comprehension filtering only healthy services.
health_status = {service: status for service, status in services.items() if status [1] 'healthy' and service.[2]() and not service.[3]()}The comprehension filters services where status is == 'healthy', the service ping() returns true, and the service is not is_down().