fix: remove redundant and incorrect health check (#2571)
remove redundant health check and incorrect checks
This commit is contained in:
parent
f6636551bb
commit
7dcc716811
1 changed files with 12 additions and 51 deletions
|
|
@ -5,25 +5,22 @@ from loguru import logger
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
|
||||||
from langflow.services.auth.utils import get_password_hash
|
|
||||||
from langflow.services.database.models.flow import Flow
|
from langflow.services.database.models.flow import Flow
|
||||||
from langflow.services.database.models.folder.utils import create_default_folder_if_it_doesnt_exist
|
from langflow.services.deps import get_chat_service, get_session
|
||||||
from langflow.services.database.models.user.model import User
|
|
||||||
from langflow.services.deps import get_chat_service, get_session, get_variable_service
|
|
||||||
from langflow.services.variable.service import GENERIC_TYPE, VariableService
|
|
||||||
|
|
||||||
health_check_router = APIRouter(tags=["Health Check"])
|
health_check_router = APIRouter(tags=["Health Check"])
|
||||||
|
|
||||||
|
|
||||||
class HealthResponse(BaseModel):
|
class HealthResponse(BaseModel):
|
||||||
status: str = "nok"
|
status: str = "nok"
|
||||||
chat: str = "error"
|
chat: str = "error check the server logs"
|
||||||
db: str = "error"
|
db: str = "error check the server logs"
|
||||||
folder: str = "error"
|
"""
|
||||||
variables: str = "error"
|
Do not send exceptions and detailed error messages to the client because it might contain credentials and other sensitive server information.
|
||||||
|
"""
|
||||||
|
|
||||||
def has_error(self) -> bool:
|
def has_error(self) -> bool:
|
||||||
return any(v == "error" for v in self.model_dump().values())
|
return any(v.startswith("error") for v in self.model_dump().values())
|
||||||
|
|
||||||
|
|
||||||
# /health is also supported by uvicorn
|
# /health is also supported by uvicorn
|
||||||
|
|
@ -40,24 +37,13 @@ async def health():
|
||||||
@health_check_router.get("/health_check", response_model=HealthResponse)
|
@health_check_router.get("/health_check", response_model=HealthResponse)
|
||||||
async def health_check(
|
async def health_check(
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
variable_service: VariableService = Depends(get_variable_service),
|
|
||||||
):
|
):
|
||||||
response = HealthResponse()
|
response = HealthResponse()
|
||||||
test_id = uuid.uuid4()
|
# use a fixed valid UUId that UUID collision is very unlikely
|
||||||
user_id = "da93c2bd-c857-4b10-8c8c-60988103320f"
|
user_id = "da93c2bd-c857-4b10-8c8c-60988103320f"
|
||||||
try:
|
try:
|
||||||
if not session.exec(select(User).where(User.id == user_id)).first():
|
|
||||||
session.add(
|
|
||||||
User(
|
|
||||||
id=user_id,
|
|
||||||
username="health_check",
|
|
||||||
is_active=False,
|
|
||||||
password=get_password_hash("health_check"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
session.commit()
|
|
||||||
# Check database to query a bogus flow
|
# Check database to query a bogus flow
|
||||||
stmt = select(Flow).where(Flow.id == test_id)
|
stmt = select(Flow).where(Flow.id == uuid.uuid4())
|
||||||
session.exec(stmt).first()
|
session.exec(stmt).first()
|
||||||
response.db = "ok"
|
response.db = "ok"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -65,34 +51,9 @@ async def health_check(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chat = get_chat_service()
|
chat = get_chat_service()
|
||||||
await chat.set_cache("health_check", str(test_id))
|
await chat.set_cache("health_check", str(user_id))
|
||||||
if v := await chat.get_cache("health_check"):
|
await chat.get_cache("health_check")
|
||||||
if v.get("result") == str(test_id):
|
response.chat = "ok"
|
||||||
response.chat = "ok"
|
|
||||||
else:
|
|
||||||
logger.error("chat service get incorrect value")
|
|
||||||
except Exception as e:
|
|
||||||
logger.exception(e)
|
|
||||||
|
|
||||||
# use the same uuid for user_id for testing purpose
|
|
||||||
try:
|
|
||||||
variable_service.initialize_user_variables(user_id, session)
|
|
||||||
variable_service.create_variable(
|
|
||||||
user_id=user_id,
|
|
||||||
name="health_check_test",
|
|
||||||
value="ok",
|
|
||||||
default_fields=[],
|
|
||||||
_type=GENERIC_TYPE,
|
|
||||||
session=session,
|
|
||||||
)
|
|
||||||
variable_service.delete_variable(user_id=user_id, name="health_check_test", session=session)
|
|
||||||
response.variables = "ok"
|
|
||||||
except Exception as e:
|
|
||||||
logger.exception(e)
|
|
||||||
|
|
||||||
try:
|
|
||||||
create_default_folder_if_it_doesnt_exist(session, uuid.UUID(user_id))
|
|
||||||
response.folder = "ok"
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue