From 10984a3e9cee11a5a833d14078a67258e574de56 Mon Sep 17 00:00:00 2001 From: Maurice Yap Date: Thu, 6 Feb 2025 16:02:34 +0000 Subject: [PATCH 1/2] Lookout development: add and document Vite config for proxying API requests (#4191) When developing the Lookout UI locally, it is useful to be able to use deployed instances of Armada with realistic data. --- internal/lookout/ui/README.md | 28 ++++++++++++++++++++++++---- internal/lookout/ui/vite.config.mts | 27 ++++++++++++++++++--------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/internal/lookout/ui/README.md b/internal/lookout/ui/README.md index 2cb8547c6f1..7e1582d2cd7 100644 --- a/internal/lookout/ui/README.md +++ b/internal/lookout/ui/README.md @@ -37,15 +37,31 @@ yarn openapi You can run a Vite development server to see your changes in the browser in real-time. This serves the web app on -[http://localhost:3000](http://localhost:3000), and proxies API requests to a -locally-running instance of the Lookout API. Please see -[the main developer docs](../../../docs/developer/ui.md) for details of how to -set this up. +[http://localhost:3000](http://localhost:3000). It proxies API requests to the +target defined by your `PROXY_TARGET` environment variable, or otherwise your +locally-running instance of the Lookout server at `http://localhost:10000` +(please see [the main developer docs](../../../docs/developer/ui.md) for details +of how to set this up). ```bash +# Proxy requests to your locally-running Lookout server yarn dev + +# Proxy API requests to your staging environment +PROXY_TARGET=https://your-lookout-staging-environment.com yarn dev ``` +You should ensure the following for the instance of the Lookout server to which +you are proxying API requests: + +- if OIDC authentication is enabled, the OIDC client allows redirects to + `http://localhost:3000/oidc` +- the configured endpoints for the following services allow requests from the + `http://localhost:3000` origin in their responses' CORS headers (set in the + `applicationConfig.corsAllowedOrigins` path in their config file): + - Armada API + - Armada Binoculars + ### Run unit tests Unit tests are run using [Vitest](https://vitest.dev/). @@ -83,3 +99,7 @@ You can then run a server to serve this production bundle locally on ```bash yarn serve ``` + +In the same way as for `yarn dev`, you may supply a `PROXY_TARGET` environment +variable. The same requirements apply for the Lookout instance to which requests +are proxied (for `localhost:4173` instead of `localhost:3000`). diff --git a/internal/lookout/ui/vite.config.mts b/internal/lookout/ui/vite.config.mts index c0d8e4559e6..d2686496d5c 100644 --- a/internal/lookout/ui/vite.config.mts +++ b/internal/lookout/ui/vite.config.mts @@ -1,6 +1,19 @@ import react from "@vitejs/plugin-react" import { defineConfig, ProxyOptions } from "vite" +const PROXY_PATHS = ["/api", "/config"] +const PROXY_OPTIONS: Record = PROXY_PATHS.reduce>( + (acc, path) => ({ + ...acc, + [path]: { + target: process.env.PROXY_TARGET || "http://localhost:10000", + changeOrigin: true, + secure: false, + }, + }), + {}, +) + export default defineConfig({ plugins: [ react({ @@ -36,17 +49,13 @@ export default defineConfig({ }, }), ], + preview: { + port: 4173, + proxy: PROXY_OPTIONS, + }, server: { port: 3000, - proxy: ["/api", "/config"].reduce>( - (acc, path) => ({ - ...acc, - [path]: { - target: "http://localhost:10000", - }, - }), - {}, - ), + proxy: PROXY_OPTIONS, }, build: { outDir: "build", From 5412e6f20f5fa98d6fb7bc85e8d7aab89fbad6d8 Mon Sep 17 00:00:00 2001 From: Maurice Yap Date: Thu, 6 Feb 2025 16:15:53 +0000 Subject: [PATCH 2/2] Don't error when getting logs of deleted pod (#4195) --- internal/binoculars/service/logs.go | 10 ++++++++-- .../components/lookoutV2/sidebar/SidebarTabJobLogs.tsx | 7 ------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/binoculars/service/logs.go b/internal/binoculars/service/logs.go index 34ca6b417ce..65ce47f4a2b 100644 --- a/internal/binoculars/service/logs.go +++ b/internal/binoculars/service/logs.go @@ -5,7 +5,10 @@ import ( "strings" "time" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/armadaproject/armada/internal/common/armadacontext" @@ -66,8 +69,11 @@ func (l *KubernetesLogService) GetLogs(ctx *armadacontext.Context, params *LogPa GetLogs(params.PodName, params.LogOptions) result := req.Do(ctx) - if result.Error() != nil { - return nil, result.Error() + if err := result.Error(); err != nil { + if errors.IsNotFound(err) { + return nil, status.Error(codes.NotFound, "The pod with these logs doesn't exist - this is likely because the job has finished and the pod has been cleaned up") + } + return nil, err } rawLog, err := result.Raw() diff --git a/internal/lookout/ui/src/components/lookoutV2/sidebar/SidebarTabJobLogs.tsx b/internal/lookout/ui/src/components/lookoutV2/sidebar/SidebarTabJobLogs.tsx index 1479c48fefd..8d0d6c42910 100644 --- a/internal/lookout/ui/src/components/lookoutV2/sidebar/SidebarTabJobLogs.tsx +++ b/internal/lookout/ui/src/components/lookoutV2/sidebar/SidebarTabJobLogs.tsx @@ -112,13 +112,6 @@ export const SidebarTabJobLogs = ({ job }: SidebarTabJobLogsProps) => { // Get logs const getLogsEnabled = Boolean(cluster && namespace && job.jobId && selectedContainer && job.runs.length > 0) const getLogsResult = useGetLogs(cluster, namespace, job.jobId, selectedContainer, loadFromStart, getLogsEnabled) - useEffect(() => { - if (getLogsResult.status === "error") { - openSnackbar(`Failed to retrieve Job logs for Job with ID: ${job.jobId}: ${getLogsResult.error}`, "error", { - autoHideDuration: 5000, - }) - } - }, [getLogsResult.status, getLogsResult.error]) // Periodically refetch logs useEffect(() => {