【问题标题】:GitLab health endpoint before integrating code集成代码之前的 GitLab 健康端点
【发布时间】:2022-01-16 20:16:06
【问题描述】:

我是部署 ML 模型的新手,我想部署一个包含多个模块的模型,每个模块都由包含一些数据文件、.py 脚本和 Python 笔记本的“文件夹”组成。

我在 GitLab 中创建了一个项目,我正在尝试学习有关 FastAPI 的教程,因为这是我将要使用的。但有人告诉我,在开始集成代码之前,我需要设置一个健康端点。

我知道curl "https://gitlab.example.com/-/health" 的请求,但我需要设置什么吗?在进行requirements.txt、构建应用程序的骨架等之前,我还需要为项目设置做些什么吗?

【问题讨论】:

  • Git 没有运行状况端点。 GitLab 可能会提供一个,但那是 GitLab,而不是 Git。 (Git 本身没有端点。它不做那种事情。)
  • @torek 抱歉,标题中的错字,但在帖子中我提到了 GitLab 中的特定请求。但是在集成代码之前,我真的不明白在设置项目时如何处理健康端点。

标签: deployment gitlab fastapi health-check


【解决方案1】:

这完全取决于您的需求,fastapi 中没有原生实现的健康端点。

但有人告诉我,在开始集成代码之前,我需要设置一个健康端点。

这不一定是一个坏习惯,您可以从列出所有未来的健康检查开始,然后从那里构建您的路线。

评论更新:

但我不知道如何实现。我需要一个配置文件吗?我对此很陌生。

据我了解,您对 python api 非常陌生,因此您应该从关注 official fastapi user guide 开始。你也可以从this关注fastapi first steps。

按原样运行的非常基本的一个文件项目:

# main.py

from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
async def root():
    return {"message": "Alive!"}

请记住,以上内容不适用于生产,仅用于测试/学习目的,要制作生产api,您应该遵循官方advanced user guide并实现类似以下内容。

更高级的路由器:

你有 this health lib 的 fastapi 很好。

您可以像这样进行基本检查:

# 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

【讨论】:

  • 我想我只需要返回应用程序的状态(如果它运行与否),所以像@app.get(“/”) async def root(): return {“message ”:“应用程序正在运行”}。但我不知道如何实现这一点。我需要一个配置文件吗?我对此很陌生。
  • @johnnydoe 我已经更新了答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-28
  • 2023-04-03
  • 2017-05-18
相关资源
最近更新 更多