Skip to content

Commit

Permalink
@pcrespov review: change names
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Dec 8, 2022
1 parent 1f0d62b commit 51d3751
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
28 changes: 10 additions & 18 deletions services/autoscaling/src/simcore_service_autoscaling/api/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,28 @@ async def health_check():


class _ComponentStatus(BaseModel):
initialized: bool
connection_state: bool


class _RabbitMQStatus(_ComponentStatus):
...


class _EC2Status(_ComponentStatus):
...
is_enabled: bool
is_responsive: bool


class _StatusGet(BaseModel):
rabbitmq: _RabbitMQStatus
ec2: _EC2Status
rabbitmq: _ComponentStatus
ec2: _ComponentStatus


@router.get("/status", include_in_schema=True, response_model=_StatusGet)
async def get_status(app: FastAPI = Depends(get_app)) -> _StatusGet:

return _StatusGet(
rabbitmq=_RabbitMQStatus(
initialized=bool(app.state.rabbitmq_client),
connection_state=await get_rabbitmq_client(app).ping()
rabbitmq=_ComponentStatus(
is_enabled=bool(app.state.rabbitmq_client),
is_responsive=await get_rabbitmq_client(app).ping()
if app.state.rabbitmq_client
else False,
),
ec2=_EC2Status(
initialized=bool(app.state.ec2_client),
connection_state=await app.state.ec2_client.ping()
ec2=_ComponentStatus(
is_enabled=bool(app.state.ec2_client),
is_responsive=await app.state.ec2_client.ping()
if app.state.ec2_client
else False,
),
Expand Down
36 changes: 18 additions & 18 deletions services/autoscaling/tests/unit/test_api_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ async def test_status_no_rabbit(
status_response = response.json()
assert "rabbitmq" in status_response
rabbitmq_status = status_response["rabbitmq"]
assert "initialized" in rabbitmq_status
assert rabbitmq_status["initialized"] is False
assert rabbitmq_status["connection_state"] is False
assert "is_enabled" in rabbitmq_status
assert rabbitmq_status["is_enabled"] is False
assert rabbitmq_status["is_responsive"] is False

assert "ec2" in status_response
ec2_status = status_response["ec2"]
assert "initialized" in ec2_status
assert ec2_status["initialized"] is True
assert ec2_status["connection_state"] is True
assert "is_enabled" in ec2_status
assert ec2_status["is_enabled"] is True
assert ec2_status["is_responsive"] is True


async def test_status(
Expand All @@ -65,15 +65,15 @@ async def test_status(
status_response = response.json()
assert "rabbitmq" in status_response
rabbitmq_status = status_response["rabbitmq"]
assert "initialized" in rabbitmq_status
assert rabbitmq_status["initialized"] is True
assert rabbitmq_status["connection_state"] is True
assert "is_enabled" in rabbitmq_status
assert rabbitmq_status["is_enabled"] is True
assert rabbitmq_status["is_responsive"] is True

assert "ec2" in status_response
ec2_status = status_response["ec2"]
assert "initialized" in ec2_status
assert ec2_status["initialized"] is True
assert ec2_status["connection_state"] is False
assert "is_enabled" in ec2_status
assert ec2_status["is_enabled"] is True
assert ec2_status["is_responsive"] is False

# restart the server
mocked_aws_server.start()
Expand All @@ -84,12 +84,12 @@ async def test_status(
status_response = response.json()
assert "rabbitmq" in status_response
rabbitmq_status = status_response["rabbitmq"]
assert "initialized" in rabbitmq_status
assert rabbitmq_status["initialized"] is True
assert rabbitmq_status["connection_state"] is True
assert "is_enabled" in rabbitmq_status
assert rabbitmq_status["is_enabled"] is True
assert rabbitmq_status["is_responsive"] is True

assert "ec2" in status_response
ec2_status = status_response["ec2"]
assert "initialized" in ec2_status
assert ec2_status["initialized"] is True
assert ec2_status["connection_state"] is True
assert "is_enabled" in ec2_status
assert ec2_status["is_enabled"] is True
assert ec2_status["is_responsive"] is True

0 comments on commit 51d3751

Please sign in to comment.