From 09b7a2aca68f73963175bd3251c1ba905033b2e3 Mon Sep 17 00:00:00 2001
From: Abram
Date: Sun, 5 May 2024 15:03:48 +0100
Subject: [PATCH 1/6] Feat: created logs manager service
---
.../agenta_backend/services/logs_manager.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 agenta-backend/agenta_backend/services/logs_manager.py
diff --git a/agenta-backend/agenta_backend/services/logs_manager.py b/agenta-backend/agenta_backend/services/logs_manager.py
new file mode 100644
index 0000000000..98d6f6b412
--- /dev/null
+++ b/agenta-backend/agenta_backend/services/logs_manager.py
@@ -0,0 +1,18 @@
+import aiodocker
+
+
+async def retrieve_logs(container_id: str) -> str:
+ """
+ Retrieves and returns the last 10 lines of logs (both stdout and stderr)
+ for a specified Docker container.
+ Args:
+ container_id (str): The docker container identifier
+ Returns:
+ the last 10 lines of logs
+ """
+
+ async with aiodocker.Docker() as client:
+ container = await client.containers.get(container_id)
+ logs = await container.log(stdout=True, stderr=True)
+ outputs = logs[::-1][:10]
+ return "".join(outputs)
From 76cbc4a76489b849e94944622c5b8d0df29bb491 Mon Sep 17 00:00:00 2001
From: Abram
Date: Sun, 5 May 2024 15:04:59 +0100
Subject: [PATCH 2/6] Feat: created endpoint to fetch variant logs
---
.../agenta_backend/routers/variants_router.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
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",
From b229f40df1019835e892dacbefc3e5755a91148f Mon Sep 17 00:00:00 2001
From: Abram
Date: Sun, 5 May 2024 15:09:27 +0100
Subject: [PATCH 3/6] Improved error handling: Added Axios logic to fetch
variant logs and integrated display logic on playground for container error
---
.../components/Playground/ViewNavigation.tsx | 61 +++++++++++++------
agenta-web/src/lib/services/api.ts | 9 ++-
2 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/agenta-web/src/components/Playground/ViewNavigation.tsx b/agenta-web/src/components/Playground/ViewNavigation.tsx
index 851525383a..de5d177ce7 100644
--- a/agenta-web/src/components/Playground/ViewNavigation.tsx
+++ b/agenta-web/src/components/Playground/ViewNavigation.tsx
@@ -9,6 +9,7 @@ import {useState} from "react"
import axios from "axios"
import {createUseStyles} from "react-jss"
import {
+ fetchVariantLogs,
getAppContainerURL,
removeVariant,
restartAppVariantContainer,
@@ -36,6 +37,10 @@ const useStyles = createUseStyles({
restartBtnMargin: {
marginRight: "10px",
},
+ errorLogs: {
+ whiteSpace: "pre-wrap",
+ wordBreak: "break-all",
+ },
})
const ViewNavigation: React.FC = ({
@@ -69,6 +74,7 @@ const ViewNavigation: React.FC = ({
const [retrying, setRetrying] = useState(false)
const [isParamsCollapsed, setIsParamsCollapsed] = useState("1")
const [containerURI, setContainerURI] = useState("")
+ const [variantErrorLogs, setVariantErrorLogs] = useState("")
const [restarting, setRestarting] = useState(false)
const {currentApp} = useAppsData()
const retriedOnce = useRef(false)
@@ -101,7 +107,15 @@ const ViewNavigation: React.FC = ({
setRetrying(false)
})
}
- }, [netWorkError])
+
+ if (isError) {
+ const getLogs = async () => {
+ const logs = await fetchVariantLogs(variant.variantId)
+ setVariantErrorLogs(logs)
+ }
+ getLogs()
+ }
+ }, [netWorkError, isError, variant.variantId])
if (retrying || (!retriedOnce.current && netWorkError)) {
return (
@@ -115,7 +129,8 @@ const ViewNavigation: React.FC = ({
if (isError) {
let variantDesignator = variant.templateVariantName
- let imageName = `agentaai/${(currentApp?.app_name || "").toLowerCase()}_`
+ let appName = currentApp?.app_name || ""
+ let imageName = `agentaai/${appName.toLowerCase()}_`
if (!variantDesignator || variantDesignator === "") {
variantDesignator = variant.variantName
@@ -165,31 +180,39 @@ const ViewNavigation: React.FC = ({
Error connecting to the variant {variant.variantName}.{" "}
{(axios.isAxiosError(error) && error.response?.status === 404 && (
- Container is not running.
+
+ Container is not running. See logs below:
+
)) || {error.message} }
- To debug this issue, please follow the steps below:
-
- Verify whether the API is up by checking if {apiAddress} is
- accessible.
-
-
- Check if the Docker container for the variant {variantDesignator} is
- running. The image should be called {imageName}.
-
+ {isDemo() && (
+
+ )}
+ {!isDemo() && (
+
+ )}
- {" "}
- In case the docker container is not running. Please check the logs from
- docker to understand the issue. Most of the time it is a missing
- requirements. Also, please attempt restarting it (using cli or docker
- desktop)
+ Verify API accessibility at{" "}
+
+ {apiAddress}
+
{" "}
- If the issue persists please file an issue in github here:
- https://github.com/Agenta-AI/agenta/issues/new?title=Issue%20in%20ViewNavigation.tsx
+ If the issue persists please file an issue in github
+
+ {" "}
+ here
+
{
+ const response = await axios.get(`${getAgentaApiUrl()}/api/variants/${variantId}/logs`, {
+ _ignoreError: ignoreAxiosError,
+ } as any)
+ return response.data
+}
+
export function restartAppVariantContainer(variantId: string) {
return axios.post(`${getAgentaApiUrl()}/api/containers/restart_container/`, {
variant_id: variantId,
@@ -696,4 +703,4 @@ export const promptRevision = async (
)
return data
-}
+}
\ No newline at end of file
From d4f93258bc018d44954c26605577921c5431a4d3 Mon Sep 17 00:00:00 2001
From: Abram
Date: Mon, 6 May 2024 16:37:46 +0100
Subject: [PATCH 4/6] Style: format with prettier
---
agenta-web/src/lib/services/api.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/agenta-web/src/lib/services/api.ts b/agenta-web/src/lib/services/api.ts
index c7971a16b5..9bdcc66189 100644
--- a/agenta-web/src/lib/services/api.ts
+++ b/agenta-web/src/lib/services/api.ts
@@ -703,4 +703,4 @@ export const promptRevision = async (
)
return data
-}
\ No newline at end of file
+}
From 2cec7a60042e16afa5a96ed25f9a964d862e79f0 Mon Sep 17 00:00:00 2001
From: Abram
Date: Tue, 7 May 2024 22:21:19 +0100
Subject: [PATCH 5/6] Refactor: improve retrieve_variant_logs endpoint and
remove condition dupicate for view error logs on playground
---
.../agenta_backend/routers/variants_router.py | 6 +-----
.../src/components/Playground/ViewNavigation.tsx | 13 +++----------
2 files changed, 4 insertions(+), 15 deletions(-)
diff --git a/agenta-backend/agenta_backend/routers/variants_router.py b/agenta-backend/agenta_backend/routers/variants_router.py
index 08bdaf2ca1..c47bafb91d 100644
--- a/agenta-backend/agenta_backend/routers/variants_router.py
+++ b/agenta-backend/agenta_backend/routers/variants_router.py
@@ -320,11 +320,7 @@ 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)
+ logs_result = await logs_manager.retrieve_logs(deployment.container_id)
return logs_result
except Exception as exc:
logger.exception(f"An error occurred: {str(exc)}")
diff --git a/agenta-web/src/components/Playground/ViewNavigation.tsx b/agenta-web/src/components/Playground/ViewNavigation.tsx
index de5d177ce7..fb18d19c3b 100644
--- a/agenta-web/src/components/Playground/ViewNavigation.tsx
+++ b/agenta-web/src/components/Playground/ViewNavigation.tsx
@@ -186,16 +186,9 @@ const ViewNavigation: React.FC = ({
)) || {error.message} }
- {isDemo() && (
-
- )}
- {!isDemo() && (
-
- )}
+
Verify API accessibility at{" "}
From ebea11d64984813b86694bc00340641119996645 Mon Sep 17 00:00:00 2001
From: Kaosiso Ezealigo
Date: Wed, 8 May 2024 12:34:03 +0100
Subject: [PATCH 6/6] used antd text code component
---
agenta-web/src/components/Playground/ViewNavigation.tsx | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/agenta-web/src/components/Playground/ViewNavigation.tsx b/agenta-web/src/components/Playground/ViewNavigation.tsx
index fb18d19c3b..902dbdbecc 100644
--- a/agenta-web/src/components/Playground/ViewNavigation.tsx
+++ b/agenta-web/src/components/Playground/ViewNavigation.tsx
@@ -1,5 +1,5 @@
import React, {useEffect, useRef} from "react"
-import {Col, Row, Divider, Button, Tooltip, Spin, notification} from "antd"
+import {Col, Row, Divider, Button, Tooltip, Spin, notification, Typography} from "antd"
import TestView from "./Views/TestView"
import ParametersView from "./Views/ParametersView"
import {useVariant} from "@/lib/hooks/useVariant"
@@ -19,6 +19,8 @@ import {useAppsData} from "@/contexts/app.context"
import {isDemo} from "@/lib/helpers/utils"
import ResultComponent from "../ResultComponent/ResultComponent"
+const {Text} = Typography
+
interface Props {
variant: Variant
handlePersistVariant: (variantName: string) => void
@@ -39,7 +41,6 @@ const useStyles = createUseStyles({
},
errorLogs: {
whiteSpace: "pre-wrap",
- wordBreak: "break-all",
},
})
@@ -187,7 +188,9 @@ const ViewNavigation: React.FC = ({
-
{variantErrorLogs}
+
+ {variantErrorLogs}
+