From ee2aeb44d7b1489a1f9f6feb0f9bb8e00bc42d8e Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Thu, 15 May 2025 11:13:09 -0300 Subject: [PATCH] fix: avoid pulling containers when it is not enabled (#17855) We've been continuously pulling the containers endpoint even when the agent does not support containers. To optimize the requests, we can check if it is throwing an error and stop if it is a 403 status code. --- site/src/api/api.ts | 20 +++++--------------- site/src/modules/resources/AgentRow.tsx | 8 +++++++- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/site/src/api/api.ts b/site/src/api/api.ts index 85a9860bc5..206e6e5f46 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -2453,21 +2453,11 @@ class ApiMethods { const params = new URLSearchParams( labels?.map((label) => ["label", label]), ); - - try { - const res = - await this.axios.get( - `/api/v2/workspaceagents/${agentId}/containers?${params.toString()}`, - ); - return res.data; - } catch (err) { - // If the error is a 403, it means that experimental - // containers are not enabled on the agent. - if (isAxiosError(err) && err.response?.status === 403) { - return { containers: [] }; - } - throw err; - } + const res = + await this.axios.get( + `/api/v2/workspaceagents/${agentId}/containers?${params.toString()}`, + ); + return res.data; }; getInboxNotifications = async (startingBeforeId?: string) => { diff --git a/site/src/modules/resources/AgentRow.tsx b/site/src/modules/resources/AgentRow.tsx index c4d104501f..bc0751c332 100644 --- a/site/src/modules/resources/AgentRow.tsx +++ b/site/src/modules/resources/AgentRow.tsx @@ -10,6 +10,7 @@ import type { WorkspaceAgent, WorkspaceAgentMetadata, } from "api/typesGenerated"; +import { isAxiosError } from "axios"; import { DropdownArrow } from "components/DropdownArrow/DropdownArrow"; import type { Line } from "components/Logs/LogLine"; import { Stack } from "components/Stack/Stack"; @@ -160,7 +161,12 @@ export const AgentRow: FC = ({ select: (res) => res.containers.filter((c) => c.status === "running"), // TODO: Implement a websocket connection to get updates on containers // without having to poll. - refetchInterval: 10_000, + refetchInterval: (_, query) => { + const { error } = query.state; + return isAxiosError(error) && error.response?.status === 403 + ? false + : 10_000; + }, }); return (