Skip to content

Commit

Permalink
Feat: created endpoint to fetch variant logs
Browse files Browse the repository at this point in the history
  • Loading branch information
aybruhm committed May 5, 2024
1 parent 09b7a2a commit 76cbc4a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions agenta-backend/agenta_backend/routers/variants_router.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import inspect
import logging
from typing import Any, Optional, Union, List

Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 76cbc4a

Please sign in to comment.