[Bugfix][Frontend] Fix missing /metrics endpoint (#6463)

This commit is contained in:
Cyrus Leung
2024-07-19 11:55:13 +08:00
committed by GitHub
parent dbe5588554
commit 6366efc67b
2 changed files with 70 additions and 5 deletions

View File

@@ -73,11 +73,13 @@ async def lifespan(app: fastapi.FastAPI):
router = APIRouter()
# Add prometheus asgi middleware to route /metrics requests
route = Mount("/metrics", make_asgi_app())
# Workaround for 307 Redirect for /metrics
route.path_regex = re.compile('^/metrics(?P<path>.*)$')
router.routes.append(route)
def mount_metrics(app: fastapi.FastAPI):
# Add prometheus asgi middleware to route /metrics requests
metrics_route = Mount("/metrics", make_asgi_app())
# Workaround for 307 Redirect for /metrics
metrics_route.path_regex = re.compile('^/metrics(?P<path>.*)$')
app.routes.append(metrics_route)
@router.get("/health")
@@ -167,6 +169,8 @@ def build_app(args):
app.include_router(router)
app.root_path = args.root_path
mount_metrics(app)
app.add_middleware(
CORSMiddleware,
allow_origins=args.allowed_origins,