diff --git a/agenta-backend/agenta_backend/routers/variants_router.py b/agenta-backend/agenta_backend/routers/variants_router.py index 41f67c623b..08bdaf2ca1 100644 --- a/agenta-backend/agenta_backend/routers/variants_router.py +++ b/agenta-backend/agenta_backend/routers/variants_router.py @@ -1,4 +1,5 @@ import os +import inspect import logging from typing import Any, Optional, Union, List @@ -24,11 +25,13 @@ Image_ as Image, AppVariantResponse_ as AppVariantResponse, ) + from agenta_backend.cloud.services import logs_manager else: from agenta_backend.models.api.api_models import ( Image, AppVariantResponse, ) + from agenta_backend.services import logs_manager from agenta_backend.models.api.api_models import ( URI, @@ -312,6 +315,22 @@ async def start_variant( return url +@router.get("/{variant_id}/logs/", operation_id="retrieve_variant_logs") +async def retrieve_variant_logs(variant_id: str, request: Request): + try: + app_variant = await db_manager.fetch_app_variant_by_id(variant_id) + deployment = await db_manager.get_deployment_by_appid(str(app_variant.app.id)) + is_coroutine_function = inspect.iscoroutinefunction(logs_manager.retrieve_logs) + if is_coroutine_function: + logs_result = await logs_manager.retrieve_logs(deployment.container_id) + else: + logs_result = logs_manager.retrieve_logs(deployment.container_id) + return logs_result + except Exception as exc: + logger.exception(f"An error occurred: {str(exc)}") + raise HTTPException(500, {"message": str(exc)}) + + @router.get( "/{variant_id}/", operation_id="get_variant",