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

Iainland/healthz html response #158

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions evolver/app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import asyncio
import socket
from contextlib import asynccontextmanager

from fastapi import FastAPI
from fastapi.responses import HTMLResponse

import evolver.util
from evolver import __project__, __version__
Expand Down Expand Up @@ -81,9 +83,24 @@ async def get_history(
)


@app.get("/healthz", operation_id="healthcheck")
@app.get("/healthz", operation_id="healthcheck", response_class=HTMLResponse)
async def healthz():
return {"message": f"Running '{__project__}' ver: '{__version__}'"}
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider #164

html_content = f"""
<html>
<head>
<title>Evolver</title>
</head>
<body>
<h1>Health Check</h1>
<p>Running '{__project__}' ver: '{__version__}'</p>
<p>Hostname: {hostname}</p>
<p>IP Address: {ip_address}</p>
</body>
</html>
"""
return html_content


async def evolver_async_loop():
Expand Down
5 changes: 4 additions & 1 deletion evolver/app/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ def test_docs(self, app_client):
def test_healthz(self, app_client):
response = app_client.get("/healthz")
assert response.status_code == 200
assert response.headers["content-type"] == "text/html; charset=utf-8"

html_content = response.text
if __version__:
assert __version__ in response.json()["message"], response.json()
assert __version__ in html_content

def test_evolver_app_default_config_dump_endpoint(self, app_client):
response = app_client.get("/")
Expand Down
Loading