feat(dashboard): show logs on application pages and per tenant

A Logs tab on application detail pages reads the application root of
the observability proxy, and a Logs page under a new Observability
sidebar group reads the tenant namespace root, so lines from before
the application identity labels existed stay reachable there.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-04 05:34:01 +07:00
1 parent b5a0ab8de6
commit f9ed2afad7
8 files changed
+79 -4

No files matched your search

@@ -15,6 +15,7 @@ import { MigrationSourceEditPage } from "./MigrationSourceEditPage.tsx"
import { MigrationTaskCreatePage } from "./MigrationTaskCreatePage.tsx"
import { MigrationTaskDetailPage } from "./MigrationTaskDetailPage.tsx"
import { ApplicationOrderPage } from "./ApplicationOrderPage.tsx"
import { LogsPage } from "./LogsPage.tsx"
export function ConsolePage() {
return (
@@ -96,6 +97,7 @@ export function ConsolePage() {
path="migration/vmimporttasks/:name"
element={<MigrationTaskDetailPage />}
/>
<Route path="logs" element={<LogsPage />} />
<Route path="new/:appName" element={<ApplicationOrderPage />} />
<Route path=":plural/:name/edit" element={<ApplicationEditRoute />} />
<Route path=":plural/:name/*" element={<ApplicationDetailPage />} />
@@ -0,0 +1,20 @@
import { describe, it, expect, vi } from "vitest"
import { render, screen } from "@testing-library/react"
vi.mock("../lib/tenant-context.tsx", () => ({
useTenantContext: () => ({ tenantNamespace: "tenant-a" }),
}))
vi.mock("../components/observability/LogsView.tsx", () => ({
LogsView: ({ scope }: { scope: object }) => <pre data-testid="scope">{JSON.stringify(scope)}</pre>,
}))
const { LogsPage } = await import("./LogsPage.tsx")
describe("LogsPage", () => {
it("reads logs from the selected tenant's namespace root", () => {
render(<LogsPage />)
expect(screen.getByRole("heading", { name: "Logs" })).toBeInTheDocument()
expect(JSON.parse(screen.getByTestId("scope").textContent ?? "")).toEqual({ namespace: "tenant-a" })
})
})
@@ -0,0 +1,15 @@
import { useTenantContext } from "../lib/tenant-context.tsx"
import { LogsView } from "../components/observability/LogsView.tsx"
export function LogsPage() {
const { tenantNamespace } = useTenantContext()
return (
<div className="flex h-full flex-col">
<div className="border-b border-slate-200 bg-white px-6 py-4">
<h1 className="text-lg font-semibold text-slate-900">Logs</h1>
<p className="text-xs text-slate-500">Every application in {tenantNamespace ?? "this tenant"}</p>
</div>
{tenantNamespace && <LogsView scope={{ namespace: tenantNamespace }} />}
</div>
)
}
@@ -60,6 +60,7 @@ vi.mock("./VncTab.tsx", () => ({ VncTab: () => null }))
vi.mock("./SerialTab.tsx", () => ({ SerialTab: () => null }))
vi.mock("./VMPowerControls.tsx", () => ({ VMPowerControls: () => null }))
vi.mock("./MetricsTab.tsx", () => ({ MetricsTab: () => null }))
vi.mock("./LogsTab.tsx", () => ({ LogsTab: () => null }))
const { ApplicationDetailPage } = await import("./ApplicationDetailPage.tsx")
@@ -113,6 +114,7 @@ describe("ApplicationDetailPage tabs for a virtual machine", () => {
"Workloads",
"Services",
"Metrics",
"Logs",
"Events",
])
})
@@ -133,14 +135,15 @@ describe("ApplicationDetailPage observability tabs", () => {
renderPage()
}
it("offers Metrics on any application kind, ahead of Events", () => {
it("offers Metrics and Logs on any application kind, ahead of Events", () => {
showKind("Postgres", "postgreses")
expect(h.tabLabels.slice(-3)).toEqual(["Secrets", "Metrics", "Events"])
expect(h.tabLabels.slice(-4)).toEqual(["Secrets", "Metrics", "Logs", "Events"])
})
it("leaves Metrics off a VM disk, which runs no containers", () => {
it("leaves Metrics and Logs off a VM disk, which runs no containers", () => {
showKind("VMDisk", "vmdisks")
expect(h.tabLabels).not.toContain("Metrics")
expect(h.tabLabels).not.toContain("Logs")
})
})
@@ -44,6 +44,7 @@ import { useResourceBasePath } from "../../lib/portal.ts"
import { useResourcePresence } from "./use-resource-presence.ts"
import { useApplicationConfigMaps } from "./use-app-configmaps.ts"
import { ConfigMapsTab } from "./ConfigMapsTab.tsx"
import { LogsTab } from "./LogsTab.tsx"
export function ApplicationDetailPage() {
const { plural, name } = useParams<{ plural: string; name: string }>()
@@ -146,6 +147,7 @@ export function ApplicationDetailPage() {
{ to: `${base}/workloads`, label: "Workloads", end: false },
{ to: `${base}/services`, label: "Services", end: false },
{ to: `${base}/metrics`, label: "Metrics", end: false },
{ to: `${base}/logs`, label: "Logs", end: false },
{ to: `${base}/events`, label: "Events", end: false },
)
} else {
@@ -167,6 +169,7 @@ export function ApplicationDetailPage() {
tabs.push(
{ to: `${base}/secrets`, label: "Secrets", end: false },
{ to: `${base}/metrics`, label: "Metrics", end: false },
{ to: `${base}/logs`, label: "Logs", end: false },
{ to: `${base}/events`, label: "Events", end: false },
)
}
@@ -274,6 +277,7 @@ export function ApplicationDetailPage() {
</Suspense>
}
/>
<Route path="logs" element={<LogsTab ad={ad} instance={instance} />} />
</Routes>
</div>
</div>
@@ -0,0 +1,15 @@
import type { ApplicationDefinition, ApplicationInstance } from "@cozystack/types"
import { useTenantContext } from "../../lib/tenant-context.tsx"
import { LogsView } from "../../components/observability/LogsView.tsx"
interface LogsTabProps {
ad: ApplicationDefinition
instance: ApplicationInstance
}
export function LogsTab({ ad, instance }: LogsTabProps) {
const { tenantNamespace } = useTenantContext()
const plural = ad.spec?.application.plural
if (!tenantNamespace || !plural) return null
return <LogsView scope={{ namespace: tenantNamespace, plural, name: instance.metadata.name }} />
}
@@ -110,6 +110,16 @@ describe("useConsoleSidebarSections — admin areas moved out", () => {
expect(findItem(result.current, "Imports")?.to).toBe("/console/migration/vmimporttasks")
expect(result.current.some((s) => s.title === "Migration")).toBe(true)
})
it("offers the tenant's namespace logs in an Observability group", async () => {
const client = makeClient({ nodes: true, backupclasses: true })
const { result } = renderHook(() => useConsoleSidebarSections(), {
wrapper: makeWrapper(client),
})
await waitFor(() => expect(result.current.length).toBeGreaterThan(0))
expect(findItem(result.current, "Logs")?.to).toBe("/console/logs")
expect(result.current.find((s) => s.title === "Observability")?.items).toHaveLength(1)
})
})
function appDef(name: string, kind: string, category: string, module = false) {
@@ -11,6 +11,7 @@ import {
Layers,
Network,
Package,
ScrollText,
Plug,
Server,
ToyBrick,
@@ -118,7 +119,12 @@ export function useConsoleSidebarSections(): SidebarSection[] {
],
}
return [...categorySections, backupsSection, migrationSection]
const observabilitySection: SidebarSection = {
title: "Observability",
items: [{ label: "Logs", to: "/console/logs", icon: ScrollText }],
}
return [...categorySections, backupsSection, migrationSection, observabilitySection]
}, [grouped])
}