集成代码之前的 GitLab 健康端点
GitLab health endpoint before integrating code
我是部署 ML 模型的新手,我想部署一个包含多个模块的模型,每个模块都包含包含一些数据文件、.py 脚本和 Python 笔记本的“文件夹”。
我在 GitLab 中创建了一个项目,我正在尝试学习 FastAPI 上的教程,因为这是我要使用的。但有人告诉我,在开始集成代码之前,我需要设置一个健康端点。
我知道请求 curl "https://gitlab.example.com/-/health"
,但我需要设置什么吗?在执行 requirements.txt
、构建应用程序的框架等之前,我还需要为项目设置做些什么吗?
这完全取决于您的需求,fastapi 中没有原生实现健康端点。
But I’ve been told that before I start integrating the code, I need to set up a health endpoint.
不一定是坏习惯,您可以从列出所有未来的健康检查开始,然后从那里构建您的路线。
评论更新:
But I don’t know how to implement this. I need a config file? I’m very new to this.
据我了解,您是 python api 的新手,因此您应该首先遵循 official fastapi user guide. You can also follow fastapi first steps from this.
非常基本的一个文件项目,运行 原样:
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/health")
async def root():
return {"message": "Alive!"}
请记住,以上内容不适用于生产,仅用于 testing/learning 目的,要进行生产 api 你应该按照官方 advanced user guide 并实现如下内容。
更高级的路由器:
你有 this health lib 速度快api 很好。
您可以像这样进行基本检查:
# app.routers.health.py
from fastapi import APIRouter, status, Depends
from fastapi_health import health
from app.internal.health import healthy_condition, sick_condition
router = APIRouter(
tags=["healthcheck"],
responses={404: {"description": "not found"}},
)
@router.get('/health', status_code=status.HTTP_200_OK)
def perform_api_healthcheck(health_endpoint=Depends(health([healthy_condition, sick_condition]))):
return health_endpoint
# app.internal.health.py
def healthy_condition(): # just for testing puposes
return {"database": "online"}
def sick_condition(): # just for testing puposes
return True
我是部署 ML 模型的新手,我想部署一个包含多个模块的模型,每个模块都包含包含一些数据文件、.py 脚本和 Python 笔记本的“文件夹”。
我在 GitLab 中创建了一个项目,我正在尝试学习 FastAPI 上的教程,因为这是我要使用的。但有人告诉我,在开始集成代码之前,我需要设置一个健康端点。
我知道请求 curl "https://gitlab.example.com/-/health"
,但我需要设置什么吗?在执行 requirements.txt
、构建应用程序的框架等之前,我还需要为项目设置做些什么吗?
这完全取决于您的需求,fastapi 中没有原生实现健康端点。
But I’ve been told that before I start integrating the code, I need to set up a health endpoint.
不一定是坏习惯,您可以从列出所有未来的健康检查开始,然后从那里构建您的路线。
评论更新:
But I don’t know how to implement this. I need a config file? I’m very new to this.
据我了解,您是 python api 的新手,因此您应该首先遵循 official fastapi user guide. You can also follow fastapi first steps from this.
非常基本的一个文件项目,运行 原样:
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/health")
async def root():
return {"message": "Alive!"}
请记住,以上内容不适用于生产,仅用于 testing/learning 目的,要进行生产 api 你应该按照官方 advanced user guide 并实现如下内容。
更高级的路由器:
你有 this health lib 速度快api 很好。
您可以像这样进行基本检查:
# app.routers.health.py
from fastapi import APIRouter, status, Depends
from fastapi_health import health
from app.internal.health import healthy_condition, sick_condition
router = APIRouter(
tags=["healthcheck"],
responses={404: {"description": "not found"}},
)
@router.get('/health', status_code=status.HTTP_200_OK)
def perform_api_healthcheck(health_endpoint=Depends(health([healthy_condition, sick_condition]))):
return health_endpoint
# app.internal.health.py
def healthy_condition(): # just for testing puposes
return {"database": "online"}
def sick_condition(): # just for testing puposes
return True