@skyhook-io/radar-app 1.20.3 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -9
- package/src/App.tsx +67 -15
- package/src/api/client.audit-gating.test.tsx +105 -5
- package/src/api/client.auditBadgesSync.test.tsx +118 -0
- package/src/api/client.capabilitiesPoll.test.ts +61 -0
- package/src/api/client.ts +129 -5
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/radarFeatures.ts +11 -0
- package/src/api/substrateHealth.ts +134 -0
- package/src/api/velero.test.ts +60 -0
- package/src/api/velero.ts +377 -0
- package/src/api/vulnerabilities.ts +313 -0
- package/src/components/NamespaceSwitcher.tsx +3 -1
- package/src/components/audit/AuditView.tsx +4 -0
- package/src/components/audit/ChecksViewTabs.test.tsx +35 -5
- package/src/components/audit/ChecksViewTabs.tsx +12 -1
- package/src/components/audit/Java4ShellPanel.test.tsx +31 -0
- package/src/components/audit/Java4ShellPanel.tsx +313 -0
- package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
- package/src/components/audit/UpgradeReadinessView.tsx +60 -2
- package/src/components/audit/VulnerabilitiesView.tsx +944 -0
- package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
- package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
- package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
- package/src/components/cnpg/CNPGView.tsx +43 -117
- package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
- package/src/components/cnpg/host.tsx +2 -2
- package/src/components/cnpg/routes.ts +3 -1
- package/src/components/cnpg/shared.tsx +5 -53
- package/src/components/cnpg/useCNPGNavigate.ts +1 -21
- package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
- package/src/components/community.tsx +42 -0
- package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
- package/src/components/diagnose/investigationMetrics.test.ts +20 -0
- package/src/components/diagnose/investigationMetrics.ts +2 -1
- package/src/components/dock/BottomDock.tsx +1 -0
- package/src/components/dock/LogsTab.tsx +3 -0
- package/src/components/gitops/FluxOperatorCard.test.tsx +37 -0
- package/src/components/gitops/FluxOperatorCard.tsx +27 -0
- package/src/components/gitops/GitOpsView.rowsSummary.test.tsx +59 -0
- package/src/components/gitops/GitOpsView.tsx +8 -5
- package/src/components/gitops/gitopsRowEvents.test.ts +48 -0
- package/src/components/gitops/gitopsRowEvents.ts +31 -0
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmView.tsx +20 -16
- package/src/components/helm/OwnedResources.tsx +4 -3
- package/src/components/home/ClusterHealthCard.tsx +3 -1
- package/src/components/home/HomeAgentBlock.tsx +3 -0
- package/src/components/home/HomeView.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +19 -12
- package/src/components/home/MCPSetupDialog.tsx +4 -2
- package/src/components/home/mcpToolCatalog.ts +15 -2
- package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
- package/src/components/home/useVulnerabilitiesRow.ts +50 -0
- package/src/components/logs/LogsViewer.tsx +3 -1
- package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
- package/src/components/logs/MultiPodLogsTab.tsx +9 -5
- package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
- package/src/components/nav/PrimaryNavRail.tsx +174 -29
- package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
- package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
- package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
- package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
- package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
- package/src/components/resources/ResourcesView.tsx +12 -6
- package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
- package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
- package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
- package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +3 -2
- package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
- package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
- package/src/components/timeline/TimelineView.tsx +3 -1
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
- package/src/components/traffic/TrafficData.test.tsx +37 -0
- package/src/components/traffic/TrafficData.tsx +27 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -7
- package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
- package/src/components/traffic/TrafficGraph.test.tsx +269 -0
- package/src/components/traffic/TrafficGraph.tsx +135 -64
- package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
- package/src/components/traffic/TrafficView.tsx +46 -129
- package/src/components/traffic/trafficFilters.test.ts +172 -1
- package/src/components/traffic/trafficFilters.ts +139 -0
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +31 -2
- package/src/components/ui/UpdateNotification.tsx +34 -17
- package/src/components/ui/command-items.ts +24 -1
- package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
- package/src/components/velero/VeleroBackupNow.tsx +143 -0
- package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
- package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
- package/src/components/velero/VeleroDetailPage.tsx +158 -0
- package/src/components/velero/VeleroKindLists.test.tsx +48 -0
- package/src/components/velero/VeleroKindLists.tsx +43 -0
- package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
- package/src/components/velero/VeleroLocations.test.tsx +86 -0
- package/src/components/velero/VeleroLocations.tsx +240 -0
- package/src/components/velero/VeleroOverview.test.tsx +311 -0
- package/src/components/velero/VeleroOverview.tsx +485 -0
- package/src/components/velero/VeleroPages.test.tsx +516 -0
- package/src/components/velero/VeleroPages.tsx +1056 -0
- package/src/components/velero/VeleroRunArtifacts.test.tsx +241 -0
- package/src/components/velero/VeleroRunArtifacts.tsx +112 -0
- package/src/components/velero/VeleroRunLists.tsx +309 -0
- package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
- package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
- package/src/components/velero/VeleroRunVolumes.test.tsx +247 -0
- package/src/components/velero/VeleroRunVolumes.tsx +122 -0
- package/src/components/velero/VeleroSchedulePause.test.tsx +211 -0
- package/src/components/velero/VeleroSchedulePause.tsx +191 -0
- package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
- package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
- package/src/components/velero/VeleroSchedules.tsx +255 -0
- package/src/components/velero/VeleroView.tsx +59 -0
- package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
- package/src/components/velero/attention.test.ts +178 -0
- package/src/components/velero/attention.ts +281 -0
- package/src/components/velero/backupDelete.test.tsx +91 -0
- package/src/components/velero/backupDelete.tsx +182 -0
- package/src/components/velero/coverage.test.ts +87 -0
- package/src/components/velero/coverage.ts +150 -0
- package/src/components/velero/host.tsx +92 -0
- package/src/components/velero/routes.ts +78 -0
- package/src/components/velero/runs.tsx +121 -0
- package/src/components/velero/shared.test.ts +84 -0
- package/src/components/velero/shared.tsx +423 -0
- package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
- package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
- package/src/components/velero/velero.fixtures.ts +61 -0
- package/src/components/velero/workspaceRoute.ts +21 -0
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +179 -0
- package/src/components/vulnerabilities/parts.test.ts +72 -0
- package/src/components/vulnerabilities/parts.tsx +291 -0
- package/src/components/whats-new/WhatsNewDialog.test.tsx +6 -4
- package/src/components/whats-new/releaseNotes.ts +67 -1
- package/src/components/workload/WorkloadView.tsx +64 -27
- package/src/components/workspace/DrawerTrailBack.tsx +32 -0
- package/src/components/workspace/WorkspaceFrame.tsx +71 -0
- package/src/components/workspace/coverage.ts +61 -0
- package/src/components/workspace/layout.test.tsx +29 -1
- package/src/components/workspace/layout.tsx +15 -5
- package/src/components/workspace/sidebar.ts +9 -0
- package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
- package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
- package/src/desktop/AboutDialog.test.ts +12 -0
- package/src/desktop/AboutDialog.tsx +151 -0
- package/src/desktop/WindowsTitleBar.tsx +359 -0
- package/src/desktop/titleBar.test.ts +61 -0
- package/src/desktop/titleBar.ts +45 -0
- package/src/index.css +19 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +14 -2
- package/src/integrations/resourceHosts.tsx +22 -6
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.test.ts +11 -0
- package/src/integrations/workspaceRoutes.ts +3 -1
- package/src/integrations/workspaceScreens.tsx +2 -0
- package/src/main.tsx +8 -0
- package/src/utils/desktop-zoom.test.ts +53 -0
- package/src/utils/desktop-zoom.ts +30 -0
- package/src/utils/staleAssetPrompt.test.tsx +76 -0
- package/src/utils/staleAssetPrompt.tsx +32 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, type ReactNode } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { guardRadarFeature, type RadarFeatureSupport } from '../../api/radarFeatures'
|
|
7
|
+
import type { VeleroRunContentsResponse, VeleroRunLogResponse } from '../../api/velero'
|
|
8
|
+
|
|
9
|
+
const state = vi.hoisted(() => ({
|
|
10
|
+
support: 'supported' as RadarFeatureSupport,
|
|
11
|
+
fetch: vi.fn(),
|
|
12
|
+
}))
|
|
13
|
+
vi.mock('../../api/client', async (original) => ({
|
|
14
|
+
...(await original<typeof import('../../api/client')>()),
|
|
15
|
+
useRadarFeature: () => ({
|
|
16
|
+
gatedKey: [state.support],
|
|
17
|
+
guard: <T,>(request: () => Promise<T>) => guardRadarFeature('veleroRunArtifacts', state.support, { currentVersion: 'v1.16.0' }, request),
|
|
18
|
+
}),
|
|
19
|
+
fetchJSON: (path: string, init: RequestInit) => state.fetch(path, init),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
import { ApiError } from '../../api/client'
|
|
23
|
+
import { VeleroRunContents, VeleroRunLog } from './VeleroRunArtifacts'
|
|
24
|
+
|
|
25
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
26
|
+
let host: HTMLDivElement
|
|
27
|
+
let root: Root
|
|
28
|
+
let client: QueryClient
|
|
29
|
+
const props = { kind: 'restores' as const, namespace: 'velero', name: 'recovery' }
|
|
30
|
+
const contents = (patch: Partial<VeleroRunContentsResponse> = {}): VeleroRunContentsResponse => ({
|
|
31
|
+
groups: [{ kind: 'v1/ConfigMap', count: 6001, matched: 6001, items: [{ namespace: 'app', name: 'first', action: 'created' }] }],
|
|
32
|
+
total: 6002, matched: 6002, namespaces: ['app', 'empty-app'], actions: { created: 6001, failed: 1 }, truncated: true, ...patch,
|
|
33
|
+
})
|
|
34
|
+
const log = (patch: Partial<VeleroRunLogResponse> = {}): VeleroRunLogResponse => ({
|
|
35
|
+
lines: [{ number: 42, level: 'warning', text: 'level=warning msg="storage retry"' }],
|
|
36
|
+
counts: { error: 0, warning: 1, info: 9999, debug: 7, other: 2 }, matched: 1, truncated: false, partial: false, decodedBytes: 4096, levels: ['error', 'warning'], ...patch,
|
|
37
|
+
})
|
|
38
|
+
async function mount(node: ReactNode) {
|
|
39
|
+
await act(async () => { root.render(<QueryClientProvider client={client}>{node}</QueryClientProvider>) })
|
|
40
|
+
}
|
|
41
|
+
async function settle(test: () => boolean) {
|
|
42
|
+
for (let i = 0; i < 50 && !test(); i++) await act(async () => { await new Promise((resolve) => setTimeout(resolve, 10)) })
|
|
43
|
+
expect(test()).toBe(true)
|
|
44
|
+
}
|
|
45
|
+
function button(label: string) {
|
|
46
|
+
return [...host.querySelectorAll('button')].find((b) => b.textContent?.startsWith(label))!
|
|
47
|
+
}
|
|
48
|
+
async function search(label: string, text: string) {
|
|
49
|
+
const input = host.querySelector<HTMLInputElement>(`input[aria-label="${label}"]`)!
|
|
50
|
+
await act(async () => {
|
|
51
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, text)
|
|
52
|
+
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
53
|
+
})
|
|
54
|
+
await act(async () => { input.closest('form')!.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })) })
|
|
55
|
+
}
|
|
56
|
+
function lastParams() { return new URL(state.fetch.mock.calls.at(-1)![0], 'http://localhost').searchParams }
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
state.support = 'supported'
|
|
60
|
+
state.fetch.mockReset()
|
|
61
|
+
host = document.createElement('div')
|
|
62
|
+
document.body.append(host)
|
|
63
|
+
root = createRoot(host)
|
|
64
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
65
|
+
})
|
|
66
|
+
afterEach(async () => {
|
|
67
|
+
await act(async () => root.unmount())
|
|
68
|
+
client.clear()
|
|
69
|
+
host.remove()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
for (const [label, Component] of [['contents', VeleroRunContents], ['log', VeleroRunLog]] as const) {
|
|
73
|
+
describe(label, () => {
|
|
74
|
+
it('loads only when mounted, using a POST', async () => {
|
|
75
|
+
state.fetch.mockImplementation(() => new Promise(() => {}))
|
|
76
|
+
expect(state.fetch).not.toHaveBeenCalled()
|
|
77
|
+
await mount(<Component {...props} />)
|
|
78
|
+
expect(host.textContent).toContain(`Loading ${label}…`)
|
|
79
|
+
expect(state.fetch.mock.calls[0][0]).toContain(`/velero/restores/velero/recovery/${label}?`)
|
|
80
|
+
expect(state.fetch.mock.calls[0][1].method).toBe('POST')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('fetches again when the user reopens the tab', async () => {
|
|
84
|
+
state.fetch.mockResolvedValue(label === 'contents' ? contents() : log())
|
|
85
|
+
await mount(<Component {...props} />)
|
|
86
|
+
await settle(() => state.fetch.mock.calls.length === 1 && !host.textContent!.includes('Loading'))
|
|
87
|
+
await mount(null)
|
|
88
|
+
await mount(<Component {...props} />)
|
|
89
|
+
await settle(() => state.fetch.mock.calls.length === 2)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it.each([['Velero has no '+label+' for this run', 404], ['no access to this Velero Restore', 403], ['the object store refused it', 503]])('shows the server answer: %s', async (message, status) => {
|
|
93
|
+
state.fetch.mockRejectedValue(new ApiError(message, status))
|
|
94
|
+
await mount(<Component {...props} />)
|
|
95
|
+
await settle(() => host.textContent!.includes(message))
|
|
96
|
+
expect(host.textContent).toContain('Retry')
|
|
97
|
+
expect(host.textContent).not.toContain('No matching')
|
|
98
|
+
expect(state.fetch).toHaveBeenCalledTimes(1)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('gates an older Radar without posting', async () => {
|
|
102
|
+
state.support = 'unsupported'
|
|
103
|
+
await mount(<Component {...props} />)
|
|
104
|
+
await settle(() => host.textContent!.includes('needs a newer Radar'))
|
|
105
|
+
expect(state.fetch).not.toHaveBeenCalled()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
describe('Contents rows and filters', () => {
|
|
111
|
+
it('shows groups, whole-file counts, empty namespaces and truncation without live links', async () => {
|
|
112
|
+
state.fetch.mockResolvedValue(contents())
|
|
113
|
+
await mount(<VeleroRunContents {...props} />)
|
|
114
|
+
await settle(() => host.textContent!.includes('6,000') || host.textContent!.includes('6,002') || host.textContent!.includes('6002 items'))
|
|
115
|
+
expect(host.textContent).toContain('v1/ConfigMap')
|
|
116
|
+
expect(host.textContent).toContain('Counts and filters cover the whole file')
|
|
117
|
+
expect(host.querySelector('option[value="empty-app"]')).not.toBeNull()
|
|
118
|
+
expect(host.querySelector('a')).toBeNull()
|
|
119
|
+
expect([...host.querySelectorAll('[role="tablist"] button')].map((el) => el.textContent)).toEqual(['All actions6002', 'Failed1', 'Created6001', 'Updated0', 'Skipped0'])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('posts action, namespace and text filters and displays a late failed result', async () => {
|
|
123
|
+
state.fetch.mockResolvedValue(contents())
|
|
124
|
+
await mount(<VeleroRunContents {...props} />)
|
|
125
|
+
await settle(() => host.textContent!.includes('first'))
|
|
126
|
+
state.fetch.mockResolvedValue(contents({ matched: 1, truncated: false, groups: [{ kind: 'v1/ConfigMap', count: 6001, matched: 1, items: [{ namespace: 'app', name: 'late-failure', action: 'failed' }] }] }))
|
|
127
|
+
await act(async () => button('Failed').click())
|
|
128
|
+
await settle(() => host.textContent!.includes('late-failure'))
|
|
129
|
+
expect(lastParams().get('action')).toBe('failed')
|
|
130
|
+
await search('Filter contents', 'late-failure')
|
|
131
|
+
await settle(() => lastParams().get('q') === 'late-failure' && !!host.querySelector('option[value="app"]'))
|
|
132
|
+
const select = host.querySelector('select')!
|
|
133
|
+
await act(async () => { select.value = 'app'; select.dispatchEvent(new Event('change', { bubbles: true })) })
|
|
134
|
+
await settle(() => lastParams().get('namespace') === 'app')
|
|
135
|
+
expect(lastParams().get('action')).toBe('failed')
|
|
136
|
+
expect(lastParams().get('q')).toBe('late-failure')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('reads failed entries of a restore that settled without errors as with warnings, in their own segment', async () => {
|
|
140
|
+
state.fetch.mockResolvedValue(contents({
|
|
141
|
+
total: 9, matched: 9, truncated: false, actions: { warned: 6, created: 3 },
|
|
142
|
+
groups: [{ kind: 'v1/ConfigMap', count: 9, matched: 9, items: [{ namespace: 'demo-copy', name: 'settings', action: 'warned' }, { namespace: 'demo-copy', name: 'fresh', action: 'created' }] }],
|
|
143
|
+
}))
|
|
144
|
+
await mount(<VeleroRunContents {...props} />)
|
|
145
|
+
await settle(() => host.textContent!.includes('settings'))
|
|
146
|
+
const tabs = [...host.querySelectorAll('[role="tablist"] button')].map((el) => el.textContent)
|
|
147
|
+
expect(tabs).toEqual(['All actions9', 'Failed0', 'With warnings6', 'Created3', 'Updated0', 'Skipped0'])
|
|
148
|
+
const row = [...host.querySelectorAll('tr')].find((tr) => tr.textContent!.includes('settings'))!
|
|
149
|
+
expect(row.textContent).toContain('With warnings')
|
|
150
|
+
expect(row.textContent).not.toContain('Failed')
|
|
151
|
+
expect(host.textContent).toContain('finished with no errors')
|
|
152
|
+
expect(host.textContent).toContain('the restore’s warning count is Velero’s messages, and the Log counts log lines')
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('keeps Velero’s failed entries and explains its vocabulary otherwise', async () => {
|
|
156
|
+
state.fetch.mockResolvedValue(contents({
|
|
157
|
+
total: 2, matched: 2, truncated: false, actions: { failed: 1, created: 1 },
|
|
158
|
+
groups: [{ kind: 'v1/ConfigMap', count: 2, matched: 2, items: [{ namespace: 'demo-copy', name: 'settings', action: 'failed' }, { namespace: 'demo-copy', name: 'fresh', action: 'created' }] }],
|
|
159
|
+
}))
|
|
160
|
+
await mount(<VeleroRunContents {...props} />)
|
|
161
|
+
await settle(() => host.textContent!.includes('settings'))
|
|
162
|
+
const tabs = [...host.querySelectorAll('[role="tablist"] button')].map((el) => el.textContent)
|
|
163
|
+
expect(tabs).toEqual(['All actions2', 'Failed1', 'Created1', 'Updated0', 'Skipped0'])
|
|
164
|
+
expect(host.textContent).toContain('Velero records an item as failed when any warning or error was reported for it.')
|
|
165
|
+
expect(host.textContent).not.toContain('finished with no errors')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('counts in the singular when there is one', async () => {
|
|
169
|
+
state.fetch.mockResolvedValue(contents({ total: 1, matched: 1, namespaces: ['app'], truncated: false, groups: [{ kind: 'v1/ConfigMap', count: 1, matched: 1, items: [{ namespace: 'app', name: 'first', action: 'created' }] }] }))
|
|
170
|
+
await mount(<VeleroRunContents {...props} />)
|
|
171
|
+
await settle(() => host.textContent!.includes('1 item · 1 namespace · 1 matching item'))
|
|
172
|
+
expect(host.textContent).not.toContain('1 namespaces')
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it.each([true, false])('distinguishes an empty file from an empty filter (empty file: %s)', async (empty) => {
|
|
176
|
+
state.fetch.mockResolvedValue(contents({ total: empty ? 0 : 6002, matched: 0, groups: [], truncated: false }))
|
|
177
|
+
await mount(<VeleroRunContents {...props} />)
|
|
178
|
+
await settle(() => host.textContent!.includes(empty ? 'Velero recorded no items' : 'No contents match these filters'))
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
describe('Log rows and filters', () => {
|
|
183
|
+
it('opens on errors and warnings, with counts from all levels', async () => {
|
|
184
|
+
state.fetch.mockResolvedValue(log())
|
|
185
|
+
await mount(<VeleroRunLog {...props} />)
|
|
186
|
+
await settle(() => host.textContent!.includes('storage retry'))
|
|
187
|
+
expect(lastParams().get('levels')).toBe('auto')
|
|
188
|
+
expect(button('Errors + warnings').getAttribute('aria-selected')).toBe('true')
|
|
189
|
+
expect(button('Info').textContent).toBe('Info9999')
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
// The server picks every level for a clean log, so opening it is one
|
|
193
|
+
// download, not a problems read followed by an everything read.
|
|
194
|
+
it('opens a run with no errors or warnings on every level, in one request', async () => {
|
|
195
|
+
const clean = log({ counts: { error: 0, warning: 0, info: 3, debug: 0, other: 0 }, lines: [{ number: 1, level: 'info', text: 'level=info msg="backup completed"' }], matched: 3, levels: ['error', 'warning', 'info', 'debug', 'other'] })
|
|
196
|
+
state.fetch.mockResolvedValue(clean)
|
|
197
|
+
await mount(<VeleroRunLog {...props} />)
|
|
198
|
+
await settle(() => host.textContent!.includes('backup completed'))
|
|
199
|
+
expect(lastParams().get('levels')).toBe('auto')
|
|
200
|
+
expect(button('Show all levels').getAttribute('aria-pressed')).toBe('true')
|
|
201
|
+
expect(state.fetch).toHaveBeenCalledTimes(1)
|
|
202
|
+
state.fetch.mockResolvedValue(log({ ...clean, lines: [], matched: 0, levels: ['error', 'warning'] }))
|
|
203
|
+
await act(async () => button('Errors + warnings').click())
|
|
204
|
+
await settle(() => lastParams().get('levels') === 'error,warning' && host.textContent!.includes('No matching log lines'))
|
|
205
|
+
expect(state.fetch).toHaveBeenCalledTimes(2)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('posts level and text filters and wraps on demand', async () => {
|
|
209
|
+
state.fetch.mockResolvedValue(log())
|
|
210
|
+
await mount(<VeleroRunLog {...props} />)
|
|
211
|
+
await settle(() => host.textContent!.includes('storage retry'))
|
|
212
|
+
await act(async () => button('Debug').click())
|
|
213
|
+
await settle(() => lastParams().get('levels') === 'debug')
|
|
214
|
+
await act(async () => button('Show all levels').click())
|
|
215
|
+
await settle(() => lastParams().get('levels') === 'error,warning,info,debug,other')
|
|
216
|
+
await search('Search log', 'retry')
|
|
217
|
+
await settle(() => lastParams().get('q') === 'retry')
|
|
218
|
+
const checkbox = host.querySelector<HTMLInputElement>('input[type="checkbox"]')!
|
|
219
|
+
expect(checkbox.checked).toBe(true)
|
|
220
|
+
await act(async () => checkbox.click())
|
|
221
|
+
expect(checkbox.checked).toBe(false)
|
|
222
|
+
expect(host.querySelector('td div.whitespace-pre')).not.toBeNull()
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('names the decoded prefix separately from the matching-row cap', async () => {
|
|
226
|
+
state.fetch.mockResolvedValue(log({ partial: true, truncated: true, decodedBytes: 64 << 20, limit: '64 MiB decoded limit' }))
|
|
227
|
+
await mount(<VeleroRunLog {...props} />)
|
|
228
|
+
await settle(() => host.textContent!.includes('Counts and search cover the first 64.00 MiB'))
|
|
229
|
+
expect(host.textContent).toContain('Showing the first 1 matching line.')
|
|
230
|
+
expect(host.textContent).toContain('the decoded prefix')
|
|
231
|
+
expect(button('Error').textContent).toBe('Errors + warnings')
|
|
232
|
+
expect([...host.querySelectorAll('[role="tab"]')].some((el) => el.textContent === 'Error≥0')).toBe(true)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
it.each([true, false])('gives an honest empty state (partial: %s)', async (partial) => {
|
|
236
|
+
state.fetch.mockResolvedValue(log({ lines: [], matched: 0, partial, limit: partial ? '64 KiB line limit' : undefined }))
|
|
237
|
+
await mount(<VeleroRunLog {...props} />)
|
|
238
|
+
await settle(() => host.textContent!.includes('No matching log lines'))
|
|
239
|
+
expect(host.textContent).toContain(partial ? 'in the decoded prefix' : 'Try another level or search')
|
|
240
|
+
})
|
|
241
|
+
})
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { Badge, RadarUpgradeAction, pluralize, getRadarUpgradeRequirement, radarUpgradeDetail, radarUpgradeHeadline } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { useVeleroRunContents, useVeleroRunLog, type VeleroLogLevel } from '../../api/velero'
|
|
4
|
+
import { Notice, SectionTable, Segments } from '../workspace/layout'
|
|
5
|
+
|
|
6
|
+
type RunProps = { kind: 'backups' | 'restores'; namespace: string; name: string }
|
|
7
|
+
const actions = ['failed', 'warned', 'created', 'updated', 'skipped'] as const
|
|
8
|
+
// warned is a "failed" entry of a restore that settled with no errors
|
|
9
|
+
// (classified by the server).
|
|
10
|
+
const actionLabels: Record<string, string> = { failed: 'Failed', warned: 'With warnings', created: 'Created', updated: 'Updated', skipped: 'Skipped' }
|
|
11
|
+
const actionSeverity = (action: string) => action === 'failed' ? 'error' : action === 'warned' ? 'warning' : 'neutral'
|
|
12
|
+
const levels: VeleroLogLevel[] = ['error', 'warning', 'info', 'debug', 'other']
|
|
13
|
+
const inputClass = 'rounded-lg border border-theme-border bg-theme-elevated px-3 py-1.5 text-sm text-theme-text-primary'
|
|
14
|
+
|
|
15
|
+
export function ArtifactError({ error, retry, hasData, label = 'Velero run contents and log' }: { error: Error; retry: () => void; hasData: boolean; label?: string }) {
|
|
16
|
+
const upgrade = getRadarUpgradeRequirement(error)
|
|
17
|
+
return <Notice>{hasData && <div>The last refresh failed; the previous result is shown below.</div>}{upgrade ? <>{radarUpgradeHeadline(label)}<div>{radarUpgradeDetail(upgrade)}</div><RadarUpgradeAction requirement={upgrade} /></> : <>{error.message} <button type="button" className="btn-secondary px-2 py-1" onClick={retry}>Retry</button></>}</Notice>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function VeleroRunContents({ kind, namespace, name }: RunProps) {
|
|
21
|
+
const [text, setText] = useState('')
|
|
22
|
+
const [q, setQuery] = useState('')
|
|
23
|
+
const [action, setAction] = useState('')
|
|
24
|
+
const [selectedNamespace, setNamespace] = useState('')
|
|
25
|
+
const query = useVeleroRunContents(kind, namespace, name, { q, action, namespace: selectedNamespace })
|
|
26
|
+
const data = query.data
|
|
27
|
+
return <div className="space-y-3 p-4">
|
|
28
|
+
<form className="flex flex-wrap items-center gap-2" onSubmit={(e) => { e.preventDefault(); setQuery(text) }}>
|
|
29
|
+
<input aria-label="Filter contents" placeholder="Kind, namespace or name" className={`${inputClass} w-64 max-w-full`} value={text} onChange={(e) => setText(e.target.value)} />
|
|
30
|
+
<button type="submit" className="btn-secondary px-3 py-1.5 text-sm">Search</button>
|
|
31
|
+
<select aria-label="Contents namespace" className={inputClass} value={selectedNamespace} onChange={(e) => setNamespace(e.target.value)}>
|
|
32
|
+
<option value="">All namespaces</option>
|
|
33
|
+
{(data?.namespaces ?? (selectedNamespace ? [selectedNamespace] : [])).map((ns) => <option key={ns} value={ns}>{ns}</option>)}
|
|
34
|
+
</select>
|
|
35
|
+
</form>
|
|
36
|
+
{kind === 'restores' && <Segments label="Restore action" value={action} onChange={setAction} options={[
|
|
37
|
+
{ id: '', label: 'All actions', count: data?.total },
|
|
38
|
+
...actions.filter((id) => id !== 'warned' || (data?.actions[id] ?? 0) > 0 || action === id).map((id) => ({ id, label: actionLabels[id], count: data ? data.actions[id] ?? 0 : undefined })),
|
|
39
|
+
]} />}
|
|
40
|
+
{query.error && <ArtifactError error={query.error} hasData={!!data} retry={() => void query.refetch()} />}
|
|
41
|
+
{query.isPending && <p className="text-sm text-theme-text-secondary">Loading contents…</p>}
|
|
42
|
+
{data && <>
|
|
43
|
+
<p className="text-sm text-theme-text-secondary">{pluralize(data.total, 'item')} · {pluralize(data.namespaces.length, 'namespace')} · {pluralize(data.matched, 'matching item')}</p>
|
|
44
|
+
{kind === 'restores' && ((data.actions.failed ?? 0) > 0 || (data.actions.warned ?? 0) > 0) && <p className="text-xs text-theme-text-secondary">
|
|
45
|
+
Velero records an item as failed when any warning or error was reported for it. {(data.actions.warned ?? 0) > 0 ? 'This restore finished with no errors, so those items read With warnings. ' : ''}These counts are items; the restore’s warning count is Velero’s messages, and the Log counts log lines, so the three can differ.
|
|
46
|
+
</p>}
|
|
47
|
+
{data.truncated && <Notice>Showing the first 5,000 matching items. Counts and filters cover the whole file.</Notice>}
|
|
48
|
+
{data.matched === 0 && <Notice>{data.total === 0 ? 'Velero recorded no items in this run.' : 'No contents match these filters.'}</Notice>}
|
|
49
|
+
{data.groups.filter((g) => g.matched > 0).map((group) => <SectionTable
|
|
50
|
+
key={group.kind}
|
|
51
|
+
title={group.kind}
|
|
52
|
+
subtitle={`${group.count} total · ${group.matched} matching`}
|
|
53
|
+
minWidth={480}
|
|
54
|
+
columns={[
|
|
55
|
+
{ header: 'Namespace', width: '180px', cell: (item) => item.namespace || 'Cluster-scoped' },
|
|
56
|
+
{ header: 'Name', cell: (item) => <span className="font-mono text-xs break-all">{item.name}</span> },
|
|
57
|
+
...(kind === 'restores' ? [{ header: 'Action', width: '140px', cell: (item: (typeof group.items)[number]) => item.action ? <Badge severity={actionSeverity(item.action)}>{actionLabels[item.action] ?? item.action}</Badge> : 'Not recorded' }] : []),
|
|
58
|
+
]}
|
|
59
|
+
rows={group.items}
|
|
60
|
+
rowKey={(item) => `${item.namespace}/${item.name}/${item.action ?? ''}`}
|
|
61
|
+
empty="Matching items omitted by the row limit. Narrow the filters to see them."
|
|
62
|
+
/>)}
|
|
63
|
+
</>}
|
|
64
|
+
</div>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function VeleroRunLog({ kind, namespace, name }: RunProps) {
|
|
68
|
+
const [text, setText] = useState('')
|
|
69
|
+
const [q, setQuery] = useState('')
|
|
70
|
+
// Until the user picks levels, the server chooses (levels=auto): a run with
|
|
71
|
+
// errors or warnings opens on them, a clean run on every level, in one
|
|
72
|
+
// download.
|
|
73
|
+
const [chosen, setSelected] = useState<string | null>(null)
|
|
74
|
+
const [wrap, setWrap] = useState(true)
|
|
75
|
+
const requested = chosen === null ? 'auto' : chosen === 'all' ? levels.join(',') : chosen === 'problems' ? 'error,warning' : chosen
|
|
76
|
+
const query = useVeleroRunLog(kind, namespace, name, requested, q)
|
|
77
|
+
const data = query.data
|
|
78
|
+
const selected = chosen ?? (data?.levels.includes('info') ? 'all' : 'problems')
|
|
79
|
+
const count = (level: VeleroLogLevel) => data ? `${data.partial ? '≥' : ''}${data.counts[level]}` : undefined
|
|
80
|
+
return <div className="space-y-3 p-4">
|
|
81
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
82
|
+
<Segments label="Log levels" value={selected} onChange={setSelected} options={[
|
|
83
|
+
{ id: 'problems', label: 'Errors + warnings' },
|
|
84
|
+
...levels.map((id) => ({ id, label: id[0].toUpperCase() + id.slice(1), count: count(id) })),
|
|
85
|
+
]} />
|
|
86
|
+
<button type="button" aria-pressed={selected === 'all'} className="btn-secondary px-3 py-1.5 text-sm" onClick={() => setSelected('all')}>Show all levels</button>
|
|
87
|
+
</div>
|
|
88
|
+
<form className="flex flex-wrap items-center gap-3" onSubmit={(e) => { e.preventDefault(); setQuery(text) }}>
|
|
89
|
+
<input aria-label="Search log" placeholder="Search log text" className={inputClass} value={text} onChange={(e) => setText(e.target.value)} />
|
|
90
|
+
<button type="submit" className="btn-secondary px-3 py-1.5 text-sm">Search</button>
|
|
91
|
+
<label className="flex items-center gap-2 text-sm text-theme-text-secondary"><input type="checkbox" checked={wrap} onChange={(e) => setWrap(e.target.checked)} />Wrap lines</label>
|
|
92
|
+
</form>
|
|
93
|
+
{query.error && <ArtifactError error={query.error} hasData={!!data} retry={() => void query.refetch()} />}
|
|
94
|
+
{query.isPending && <p className="text-sm text-theme-text-secondary">Loading log…</p>}
|
|
95
|
+
{data?.partial && <Notice>Counts and search cover the first {(data.decodedBytes / (1 << 20)).toFixed(2)} MiB of decoded log ({data.limit}). Later lines were not read.</Notice>}
|
|
96
|
+
{kind === 'restores' && <p className="text-xs text-theme-text-secondary">Velero stores a restore’s log when its main pass ends. Failures it records after that, such as failed post-restore hooks, are in the Overview’s messages, not here.</p>}
|
|
97
|
+
{data?.truncated && <Notice>Showing the first {pluralize(data.lines.length, 'matching line')}. Counts and search cover {data.partial ? 'the decoded prefix' : 'the whole log'}.</Notice>}
|
|
98
|
+
{data && <SectionTable
|
|
99
|
+
title="Run log"
|
|
100
|
+
subtitle={`${data.matched} matching lines`}
|
|
101
|
+
minWidth={480}
|
|
102
|
+
columns={[
|
|
103
|
+
{ header: 'Line', width: '70px', cell: (line) => line.number },
|
|
104
|
+
{ header: 'Level', width: '100px', cell: (line) => <Badge severity={line.level === 'error' ? 'error' : line.level === 'warning' ? 'warning' : 'neutral'}>{line.level}</Badge> },
|
|
105
|
+
{ header: 'Text', cell: (line) => <div className={wrap ? 'font-mono text-xs whitespace-pre-wrap [overflow-wrap:anywhere]' : 'overflow-x-auto font-mono text-xs whitespace-pre'}>{line.text}</div> },
|
|
106
|
+
]}
|
|
107
|
+
rows={data.lines}
|
|
108
|
+
rowKey={(line) => String(line.number)}
|
|
109
|
+
empty={data.partial ? 'No matching log lines in the decoded prefix.' : 'No matching log lines. Try another level or search.'}
|
|
110
|
+
/>}
|
|
111
|
+
</div>
|
|
112
|
+
}
|