-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
38 lines (30 loc) · 1.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
from logging.config import dictConfig
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from starlette.responses import PlainTextResponse
from app import __version__
from app.routers import views, apis
from app.config import log_config
from app.config.settings import settings
from kubernetes import config as kubernetes_config
# Disable health check logs (https://stackoverflow.com/a/70810102)
class EndpointFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
return record.args and len(record.args) >= 3 and record.args[2] != "/health"
app = FastAPI(title=settings.APP_NAME, version=__version__)
app.include_router(apis.router)
app.include_router(views.router)
app.mount("/static", StaticFiles(directory="app/static"), name="static")
# Setup Logging
dictConfig(log_config.logger_config)
log = logging.getLogger(__name__)
logging.getLogger("uvicorn.access").addFilter(EndpointFilter())
# Connect to Kubernetes
try:
kubernetes_config.load_incluster_config()
except:
kubernetes_config.load_config()
@app.get("/health")
async def health():
return PlainTextResponse('UP')