Skip to content

Commit

Permalink
Merge branch 'master' into sendToGitHub/autocomplete-queues
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriceyap authored Feb 6, 2025
2 parents 30685d0 + 5412e6f commit 37c8830
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
10 changes: 8 additions & 2 deletions internal/binoculars/service/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
28 changes: 24 additions & 4 deletions internal/lookout/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down Expand Up @@ -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`).
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
27 changes: 18 additions & 9 deletions internal/lookout/ui/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import react from "@vitejs/plugin-react"
import { defineConfig, ProxyOptions } from "vite"

const PROXY_PATHS = ["/api", "/config"]
const PROXY_OPTIONS: Record<string, string | ProxyOptions> = PROXY_PATHS.reduce<Record<string, ProxyOptions>>(
(acc, path) => ({
...acc,
[path]: {
target: process.env.PROXY_TARGET || "http://localhost:10000",
changeOrigin: true,
secure: false,
},
}),
{},
)

export default defineConfig({
plugins: [
react({
Expand Down Expand Up @@ -36,17 +49,13 @@ export default defineConfig({
},
}),
],
preview: {
port: 4173,
proxy: PROXY_OPTIONS,
},
server: {
port: 3000,
proxy: ["/api", "/config"].reduce<Record<string, ProxyOptions>>(
(acc, path) => ({
...acc,
[path]: {
target: "http://localhost:10000",
},
}),
{},
),
proxy: PROXY_OPTIONS,
},
build: {
outDir: "build",
Expand Down

0 comments on commit 37c8830

Please sign in to comment.