mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
## What this PR does Adds logs and resource-consumption views to the console, backed by the observability proxy from the design proposals [Tenant application logs](https://github.com/cozystack/community/pull/95) and [Tenant resource-consumption metrics](https://github.com/cozystack/community/pull/94). This PR is useful only together with #5214, which adds the console nginx route to the proxy. The application tabs need #5219 and the per-application roots from its follow-up PR. Until those are installed, each view shows a quiet "not available on this cluster" state instead of an error, so the order of merging does not break the console. What is added: - A "Logs" page at the namespace level, under a new "Observability" sidebar group, reading the namespace logs root. It lives at `/console/-/observability/logs`: every one- or two-segment console path is an application list or detail page, and `-` cannot start an application plural or name, so the page never shadows an application's own pages. - "Logs" and "Metrics" tabs on application pages (every application kind except VMDisk, which runs no containers), reading the per-application roots. - Logs view: - time range, a LogsQL filter, and pod and container pickers that turn into a stream filter; - "Follow" opens a live tail. The status shows "Live" as soon as the stream is open, even before the first line; on a dropped stream or a load refusal (`429`) it reconnects from the newest line seen, with backoff; it stops on `400`/`401`/`403`/`404`; - the reader can scroll up while lines stream; the newest 1000 lines are kept; - while a new range or filter loads, the previous lines stay on screen with a note saying so, or the view says it is loading; it never reports "no lines" for a query it has not read yet. - Metrics view: per-pod CPU and memory charts and application-wide network charts, refreshed every minute, with ranges from 1 hour to 7 days. The `rate` window is at least 5 minutes and four steps, so queries routed to the long-term store (coarser deduplication) still return data. No query names a namespace or kind; the proxy adds the scope. - Error handling by proxy status: scope-wide answers (`401`/`403`/`404`) replace the whole view with one notice; limit answers keep the proxy's own advice. A Kubernetes `Status` body on a proxy path means the request reached kube-apiserver instead of the proxy and is shown as "not available". - Shared UI pieces: an accessible `Select` and a text `Input` matching the console's controls, and an `EmptyState`. - `K8sClient.raw()` for untyped requests over the same credential path as `/apis`; the client now keeps caller headers given in any form. - Charts use uPlot, loaded in a separate lazy chunk, so the main bundle does not grow. #### How it was tested - `pnpm typecheck`, `pnpm test`, `pnpm lint` and `pnpm build` pass. - Screenshots of the views were taken against a mock API and on a test cluster. - Verified on a test cluster through the full browser chain (OIDC login, gatekeeper, gateway, console nginx, proxy), as a user with the `view` role in one tenant: the Logs page works; Follow keeps a single tail open for more than two minutes without reconnecting; Follow on a quiet filter shows "Live"; the Metrics tab of a Redis instance draws its charts; requests from the same session to another tenant's roots answer `403`. - Not verified: a screen reader (roles and names are asserted in tests only) and viewports narrower than 1440px. #### Known limitation The first lines a newly started pod writes can be missing from an already open tail, although a history query shows them. This comes from the log store's live-tail window relative to log collection delay, not from the console. ### Screenshots <img width="1440" height="900" alt="cluster-follow-live" src="https://github.com/user-attachments/assets/6efd9bfb-f05b-4498-bd20-0af4e5cda01f" /> <img width="1440" height="900" alt="cluster-logs-empty" src="https://github.com/user-attachments/assets/673d8295-cd3d-409d-b871-290705d0a6a2" /> <img width="1440" height="900" alt="cluster-logs" src="https://github.com/user-attachments/assets/621c2312-8427-4353-b199-44bdd12b78f7" /> <img width="1440" height="900" alt="cluster-pod-select" src="https://github.com/user-attachments/assets/92ea9c72-4a3c-4562-9c3a-2170730ab085" /> <img width="1400" height="1000" alt="cluster-redis-metrics" src="https://github.com/user-attachments/assets/3533d069-01b9-41de-bba9-70b940d05c6e" /> <img width="1440" height="900" alt="follow-waiting" src="https://github.com/user-attachments/assets/eb318d13-5188-4632-842a-43c0bbbcff5a" /> <img width="1440" height="900" alt="logs-empty" src="https://github.com/user-attachments/assets/c3d89e81-7249-444d-a3fa-9ab44c1ca86e" /> <img width="1440" height="900" alt="logs" src="https://github.com/user-attachments/assets/ec6caa9c-5eda-4361-99ea-359e5d002f04" /> <img width="1440" height="900" alt="metrics-empty" src="https://github.com/user-attachments/assets/db16da15-a618-4dbe-a531-593bc9b916dc" /> ### Downstream repositories - [ ] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: Downstream: no trigger matched. Candidate: none affected, because the whole diff is inside the vendored console (`packages/system/dashboard/images/console`), which per the trigger map belongs to this repository and has no downstream copy. A user guide page for the new console views on the website would be useful but is not required by the trigger map. ### Release note ```release-note feat(dashboard): the console gains a namespace Logs page and Logs and Metrics tabs on application pages, with live log following, per-pod CPU and memory charts, and application-wide network charts. The views need the observability proxy; without it they show "not available on this cluster". ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added Metrics and Logs tabs to supported application details, plus a tenant-wide Logs page in the sidebar. * View CPU, memory, and network charts over selectable time ranges, with optional sample tables and automatic refresh. * Search logs using pod and container filters, choose a history range, and follow live updates with connection status. * Added distinct loading, empty, and error messages for observability views, including guidance for unavailable services and query limits. <!-- end of auto-generated comment: release notes by coderabbit.ai -->