chore: remove noisy healthcheck messages
This commit is contained in:
parent
42282ce8cb
commit
79460e4998
2 changed files with 14 additions and 26 deletions
|
|
@ -1,18 +0,0 @@
|
|||
import os
|
||||
import urllib.request
|
||||
|
||||
|
||||
def main() -> int:
|
||||
port = os.environ.get("PORT", "80")
|
||||
url = f"http://127.0.0.1:{port}/health"
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=2) as resp:
|
||||
body = resp.read().decode("utf-8").strip()
|
||||
return 0 if resp.status == 200 and body == "ok" else 1
|
||||
except Exception:
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import asyncio
|
||||
import logging
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp import web, web_log
|
||||
|
||||
from providers.chatgpt import ChatGPTProvider
|
||||
from providers.base import Provider
|
||||
|
|
@ -19,11 +19,13 @@ PROVIDERS: dict[str, Provider] = {
|
|||
background_tasks: dict[str, asyncio.Task | None] = {name: None for name in PROVIDERS}
|
||||
|
||||
|
||||
@web.middleware
|
||||
async def request_log_middleware(request: web.Request, handler):
|
||||
response = await handler(request)
|
||||
logger.info("%s %s -> %s", request.method, request.path_qs, response.status)
|
||||
return response
|
||||
class AccessLogger(web_log.AccessLogger):
|
||||
def log(
|
||||
self, request: web.BaseRequest, response: web.StreamResponse, time: float
|
||||
) -> None:
|
||||
if request.path == "/health":
|
||||
return
|
||||
super().log(request, response, time)
|
||||
|
||||
|
||||
def build_limit(usage_percent: int, prepare_threshold: int) -> dict[str, int | bool]:
|
||||
|
|
@ -210,7 +212,6 @@ async def on_cleanup(app: web.Application):
|
|||
|
||||
|
||||
def create_app() -> web.Application:
|
||||
app = web.Application(middlewares=[request_log_middleware])
|
||||
app.on_startup.append(on_startup)
|
||||
app.on_cleanup.append(on_cleanup)
|
||||
app.router.add_get("/health", health_handler)
|
||||
|
|
@ -232,4 +233,9 @@ if __name__ == "__main__":
|
|||
)
|
||||
logger.info("Available providers: %s", ", ".join(PROVIDERS.keys()))
|
||||
app = create_app()
|
||||
web.run_app(app, host="0.0.0.0", port=PORT)
|
||||
web.run_app(
|
||||
app,
|
||||
host="0.0.0.0",
|
||||
port=PORT,
|
||||
access_log_class=AccessLogger,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue