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 asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web, web_log
|
||||||
|
|
||||||
from providers.chatgpt import ChatGPTProvider
|
from providers.chatgpt import ChatGPTProvider
|
||||||
from providers.base import Provider
|
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}
|
background_tasks: dict[str, asyncio.Task | None] = {name: None for name in PROVIDERS}
|
||||||
|
|
||||||
|
|
||||||
@web.middleware
|
class AccessLogger(web_log.AccessLogger):
|
||||||
async def request_log_middleware(request: web.Request, handler):
|
def log(
|
||||||
response = await handler(request)
|
self, request: web.BaseRequest, response: web.StreamResponse, time: float
|
||||||
logger.info("%s %s -> %s", request.method, request.path_qs, response.status)
|
) -> None:
|
||||||
return response
|
if request.path == "/health":
|
||||||
|
return
|
||||||
|
super().log(request, response, time)
|
||||||
|
|
||||||
|
|
||||||
def build_limit(usage_percent: int, prepare_threshold: int) -> dict[str, int | bool]:
|
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:
|
def create_app() -> web.Application:
|
||||||
app = web.Application(middlewares=[request_log_middleware])
|
|
||||||
app.on_startup.append(on_startup)
|
app.on_startup.append(on_startup)
|
||||||
app.on_cleanup.append(on_cleanup)
|
app.on_cleanup.append(on_cleanup)
|
||||||
app.router.add_get("/health", health_handler)
|
app.router.add_get("/health", health_handler)
|
||||||
|
|
@ -232,4 +233,9 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
logger.info("Available providers: %s", ", ".join(PROVIDERS.keys()))
|
logger.info("Available providers: %s", ", ".join(PROVIDERS.keys()))
|
||||||
app = create_app()
|
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