Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Improve playground error message #1420

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d4e75d8
Update - improve playground error message
aybruhm Dec 1, 2023
33f2493
Refactor - clean up view navigation component
aybruhm Dec 1, 2023
ab99363
format fix
bekossy Dec 1, 2023
0f45864
Merge branch 'main' into gh/issue-885-resolve
bekossy Dec 5, 2023
3820110
Update - improve playground error message
aybruhm Dec 1, 2023
9537585
Feat - created cli app_logs command module
aybruhm Dec 6, 2023
319848e
Update - register app_logs command to cli
aybruhm Dec 6, 2023
956f208
Feat - created retrieve_app_logs cli client
aybruhm Dec 6, 2023
2ba848e
Update - created get_app_logs router skeleton
aybruhm Dec 6, 2023
f204f46
Cleanup - arrange imports
aybruhm Dec 7, 2023
339a233
Refactor - renamed app_logs to variant_logs
aybruhm Dec 7, 2023
5fe61c7
Refactor - renamed retrieve_app_logs to retrieve_variant_logs
aybruhm Dec 7, 2023
0e71231
Feat - implemented retrieve variant logs api router
aybruhm Dec 7, 2023
877be34
Feat - implemented retrieve cloudwatch logs function
aybruhm Dec 7, 2023
253029a
:art: Format - ran black and format-fix
aybruhm Dec 7, 2023
19e4862
Update - modified retrieve_cloudwatch_logs function
aybruhm Dec 8, 2023
ad0f1b5
Update - created get_deployment_by_appId db function
aybruhm Dec 8, 2023
86ba72b
Update - modified get_variant_logs_stream function
aybruhm Dec 8, 2023
73ebda9
Update - add different error messages based on feature-flag
aybruhm Dec 8, 2023
cd64de6
:art: Format - ran prettier --write .
aybruhm Dec 8, 2023
6556116
Update - created isCloud and isEnterprise utils function
aybruhm Dec 8, 2023
2558688
Update - include region_name to logs_manager boto client
aybruhm Dec 8, 2023
385d2e6
Update - modified error message for cloud users
aybruhm Dec 8, 2023
84ffae0
Update - include return type to get_app_variant_instance_by_id db fun…
aybruhm Dec 8, 2023
365f1ce
Refactor & Cleanup - modified process (cli->client->backend) to retri…
aybruhm Dec 8, 2023
58005a4
Refactor - move logs_manager to cloud/services/ and sync changes
aybruhm Dec 8, 2023
c19bcb7
Update - clean up retrieve_variant_logs api router
aybruhm Dec 11, 2023
0ab8b58
:art: Format - ran black
aybruhm Dec 11, 2023
a0ac49e
Update - modified retrieve_variant_logs api router
aybruhm Dec 11, 2023
7d58ab4
Update - refactor messages in click.style(...)
aybruhm Dec 11, 2023
f97c368
Refactor - renamed func to get_variant_logs
aybruhm Dec 11, 2023
195e26c
Cleanup - remove console log
aybruhm Dec 12, 2023
c2de01e
Merge branch 'main' into gh/issue-885-resolve
aybruhm Mar 5, 2024
cb5c9fc
Feat - created logs manager and retrieve_logs function
aybruhm Mar 5, 2024
e60ff28
Update - modified retrieve_variant_logs router and created axios logi…
aybruhm Mar 5, 2024
63aa0af
Refactor - modified playground to show variant error logs
aybruhm Mar 5, 2024
71a9732
Merge branch 'main' into gh/issue-885-improve-playground-error-message
aybruhm Mar 12, 2024
89650e8
Update - added pre-wrap to frontend for cloud logs
aybruhm Mar 12, 2024
565bc54
fixed prettier formatter
bekossy Mar 12, 2024
6f7102e
Minor refactor - added missing import for variant_logs module
aybruhm Mar 26, 2024
34c9a0c
Merge branch 'main' into gh/issue-885-improve-playground-error-message
aybruhm May 5, 2024
3715318
Cleanup: remove variant_logs command for cli
aybruhm May 5, 2024
a63694b
Cleanup: remove variant_logs cli import
aybruhm May 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions agenta-backend/agenta_backend/services/logs_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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)
61 changes: 42 additions & 19 deletions agenta-web/src/components/Playground/ViewNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {useState} from "react"
import axios from "axios"
import {createUseStyles} from "react-jss"
import {
fetchVariantLogs,
getAppContainerURL,
removeVariant,
restartAppVariantContainer,
Expand Down Expand Up @@ -36,6 +37,10 @@ const useStyles = createUseStyles({
restartBtnMargin: {
marginRight: "10px",
},
errorLogs: {
whiteSpace: "pre-wrap",
wordBreak: "break-all",
},
})

const ViewNavigation: React.FC<Props> = ({
Expand Down Expand Up @@ -69,6 +74,7 @@ const ViewNavigation: React.FC<Props> = ({
const [retrying, setRetrying] = useState(false)
const [isParamsCollapsed, setIsParamsCollapsed] = useState("1")
const [containerURI, setContainerURI] = useState("")
const [variantErrorLogs, setVariantErrorLogs] = useState("")
const [restarting, setRestarting] = useState<boolean>(false)
const {currentApp} = useAppsData()
const retriedOnce = useRef(false)
Expand Down Expand Up @@ -101,7 +107,15 @@ const ViewNavigation: React.FC<Props> = ({
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 (
Expand All @@ -115,7 +129,8 @@ const ViewNavigation: React.FC<Props> = ({

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
Expand Down Expand Up @@ -165,31 +180,39 @@ const ViewNavigation: React.FC<Props> = ({
<p>
Error connecting to the variant {variant.variantName}.{" "}
{(axios.isAxiosError(error) && error.response?.status === 404 && (
<span>Container is not running.</span>
<span>
Container is not running. <b>See logs below:</b>
</span>
)) || <span>{error.message}</span>}
</p>
<p>To debug this issue, please follow the steps below:</p>
<ul>
<li>
Verify whether the API is up by checking if {apiAddress} is
accessible.
</li>
<li>
Check if the Docker container for the variant {variantDesignator} is
running. The image should be called {imageName}.
</li>
{isDemo() && (
<div>
<pre className={classes.errorLogs}>{variantErrorLogs}</pre>
</div>
)}
{!isDemo() && (
<div>
<pre className={classes.errorLogs}>{variantErrorLogs}</pre>
</div>
)}
</ul>
<p>
{" "}
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{" "}
<a href={apiAddress} target="_blank">
Fixed Show fixed Hide fixed
{apiAddress}
</a>
</p>
<p>
{" "}
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
<a
href="https://github.com/Agenta-AI/agenta/issues/new?title=Issue%20in%20ViewNavigation.tsx"
target="_blank"
>
{" "}
here
</a>
</p>

<Button
Expand Down
7 changes: 7 additions & 0 deletions agenta-web/src/lib/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ export async function fetchVariants(
return []
}

export const fetchVariantLogs = async (variantId: string, ignoreAxiosError: boolean = false) => {
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,
Expand Down
Loading