@skyhook-io/radar-app 1.20.1 → 1.21.0

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.
Files changed (215) hide show
  1. package/package.json +10 -9
  2. package/src/App.tsx +65 -16
  3. package/src/api/client.audit-gating.test.tsx +105 -5
  4. package/src/api/client.auditBadgesSync.test.tsx +118 -0
  5. package/src/api/client.capabilitiesPoll.test.ts +61 -0
  6. package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
  7. package/src/api/client.pauseDeployment.test.tsx +77 -0
  8. package/src/api/client.restartError.test.ts +14 -0
  9. package/src/api/client.revisionRefresh.test.tsx +44 -0
  10. package/src/api/client.rollbackError.test.ts +14 -0
  11. package/src/api/client.ts +347 -16
  12. package/src/api/namespaceScopeRetry.test.ts +14 -0
  13. package/src/api/networkAttachments.test.tsx +120 -0
  14. package/src/api/networkAttachments.ts +30 -0
  15. package/src/api/radarFeatures.test.ts +5 -0
  16. package/src/api/radarFeatures.ts +10 -0
  17. package/src/api/secretsStore.test.ts +33 -0
  18. package/src/api/secretsStore.ts +37 -0
  19. package/src/api/substrateHealth.ts +134 -0
  20. package/src/api/velero.test.ts +60 -0
  21. package/src/api/velero.ts +201 -0
  22. package/src/api/vulnerabilities.ts +255 -0
  23. package/src/components/ConnectionErrorView.test.tsx +11 -0
  24. package/src/components/ConnectionErrorView.tsx +19 -0
  25. package/src/components/ContextSwitcher.tsx +9 -2
  26. package/src/components/NamespaceSwitcher.tsx +3 -1
  27. package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
  28. package/src/components/applications/ApplicationsView.tsx +8 -11
  29. package/src/components/audit/AuditView.tsx +4 -0
  30. package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
  31. package/src/components/audit/ChecksViewTabs.tsx +11 -1
  32. package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
  33. package/src/components/audit/UpgradeReadinessView.tsx +60 -2
  34. package/src/components/audit/VulnerabilitiesView.tsx +907 -0
  35. package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
  36. package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
  37. package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
  38. package/src/components/cnpg/CNPGView.tsx +43 -117
  39. package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
  40. package/src/components/cnpg/host.tsx +2 -2
  41. package/src/components/cnpg/routes.ts +3 -1
  42. package/src/components/cnpg/shared.tsx +5 -53
  43. package/src/components/cnpg/useCNPGNavigate.ts +1 -21
  44. package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
  45. package/src/components/community.tsx +42 -0
  46. package/src/components/cost/CostView.tsx +27 -9
  47. package/src/components/diagnose/InvestigationView.tsx +12 -3
  48. package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
  49. package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
  50. package/src/components/diagnose/investigationEvidence/adapters/helm.ts +10 -0
  51. package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +82 -51
  52. package/src/components/diagnose/investigationEvidence/types.ts +5 -0
  53. package/src/components/diagnose/investigationMetrics.test.ts +20 -0
  54. package/src/components/diagnose/investigationMetrics.ts +2 -1
  55. package/src/components/dock/BottomDock.tsx +1 -0
  56. package/src/components/dock/LogsTab.tsx +3 -0
  57. package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
  58. package/src/components/dock/TerminalPreferences.test.tsx +68 -0
  59. package/src/components/dock/TerminalPreferences.tsx +73 -0
  60. package/src/components/gitops/GitOpsView.tsx +2 -10
  61. package/src/components/helm/HelmDrawerFrame.tsx +1 -1
  62. package/src/components/helm/HelmReleaseDrawer.tsx +24 -12
  63. package/src/components/helm/HelmView.tsx +25 -19
  64. package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
  65. package/src/components/helm/NotCheckedBadge.tsx +39 -0
  66. package/src/components/helm/OwnedResources.test.tsx +86 -0
  67. package/src/components/helm/OwnedResources.tsx +69 -11
  68. package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
  69. package/src/components/home/ClusterHealthCard.test.ts +44 -1
  70. package/src/components/home/ClusterHealthCard.tsx +25 -11
  71. package/src/components/home/HelmSummary.tsx +15 -15
  72. package/src/components/home/HomeAgentBlock.tsx +3 -0
  73. package/src/components/home/HomeView.tsx +7 -0
  74. package/src/components/home/MCPSetupDialog.test.tsx +19 -12
  75. package/src/components/home/MCPSetupDialog.tsx +4 -2
  76. package/src/components/home/mcpToolCatalog.ts +17 -4
  77. package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
  78. package/src/components/home/useVulnerabilitiesRow.ts +50 -0
  79. package/src/components/logs/LogsViewer.tsx +3 -1
  80. package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
  81. package/src/components/logs/MultiPodLogsTab.tsx +9 -5
  82. package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
  83. package/src/components/nav/PrimaryNavRail.tsx +174 -29
  84. package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
  85. package/src/components/resource/RightsizingStrip.test.ts +57 -0
  86. package/src/components/resource/RightsizingStrip.tsx +53 -4
  87. package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
  88. package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
  89. package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
  90. package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
  91. package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
  92. package/src/components/resources/ImageFilesystemModal.tsx +98 -6
  93. package/src/components/resources/PodFileUploadPanel.tsx +150 -0
  94. package/src/components/resources/PodFilesystemModal.tsx +246 -3
  95. package/src/components/resources/ResourcesView.tsx +12 -6
  96. package/src/components/resources/pod-file-upload.test.tsx +223 -0
  97. package/src/components/resources/pod-file-upload.ts +266 -0
  98. package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
  99. package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
  100. package/src/components/resources/renderers/PodRenderer.tsx +26 -1
  101. package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
  102. package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
  103. package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
  104. package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
  105. package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
  106. package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
  107. package/src/components/rightsizing/RightsizingScanView.tsx +19 -3
  108. package/src/components/rightsizing/model.test.ts +11 -0
  109. package/src/components/rightsizing/model.ts +3 -1
  110. package/src/components/rightsizing/presentation.test.ts +46 -0
  111. package/src/components/rightsizing/presentation.ts +17 -2
  112. package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
  113. package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
  114. package/src/components/timeline/TimelineView.tsx +3 -1
  115. package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
  116. package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
  117. package/src/components/traffic/TrafficData.test.tsx +37 -0
  118. package/src/components/traffic/TrafficData.tsx +27 -0
  119. package/src/components/traffic/TrafficFlowList.tsx +9 -7
  120. package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
  121. package/src/components/traffic/TrafficGraph.test.tsx +269 -0
  122. package/src/components/traffic/TrafficGraph.tsx +135 -64
  123. package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
  124. package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
  125. package/src/components/traffic/TrafficView.tsx +72 -155
  126. package/src/components/traffic/trafficFilters.test.ts +189 -1
  127. package/src/components/traffic/trafficFilters.ts +169 -1
  128. package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
  129. package/src/components/ui/Omnibar.tsx +4 -1
  130. package/src/components/ui/RadarOmnibar.test.tsx +55 -2
  131. package/src/components/ui/RadarOmnibar.tsx +7 -1
  132. package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
  133. package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
  134. package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
  135. package/src/components/ui/UpdateNotification.test.tsx +54 -3
  136. package/src/components/ui/UpdateNotification.tsx +60 -19
  137. package/src/components/ui/command-items.ts +24 -1
  138. package/src/components/ui/omnibar-match.test.ts +7 -0
  139. package/src/components/ui/omnibar-match.ts +1 -0
  140. package/src/components/ui/searchCoverageNote.test.ts +17 -0
  141. package/src/components/ui/searchCoverageNote.ts +31 -7
  142. package/src/components/useContextSwitchFlow.tsx +9 -1
  143. package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
  144. package/src/components/velero/VeleroBackupNow.tsx +143 -0
  145. package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
  146. package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
  147. package/src/components/velero/VeleroDetailPage.tsx +148 -0
  148. package/src/components/velero/VeleroKindLists.test.tsx +48 -0
  149. package/src/components/velero/VeleroKindLists.tsx +43 -0
  150. package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
  151. package/src/components/velero/VeleroLocations.test.tsx +86 -0
  152. package/src/components/velero/VeleroLocations.tsx +240 -0
  153. package/src/components/velero/VeleroOverview.test.tsx +311 -0
  154. package/src/components/velero/VeleroOverview.tsx +485 -0
  155. package/src/components/velero/VeleroPages.test.tsx +516 -0
  156. package/src/components/velero/VeleroPages.tsx +1056 -0
  157. package/src/components/velero/VeleroRunLists.tsx +309 -0
  158. package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
  159. package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
  160. package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
  161. package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
  162. package/src/components/velero/VeleroSchedules.tsx +255 -0
  163. package/src/components/velero/VeleroView.tsx +59 -0
  164. package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
  165. package/src/components/velero/attention.test.ts +178 -0
  166. package/src/components/velero/attention.ts +281 -0
  167. package/src/components/velero/backupDelete.test.tsx +91 -0
  168. package/src/components/velero/backupDelete.tsx +182 -0
  169. package/src/components/velero/coverage.test.ts +87 -0
  170. package/src/components/velero/coverage.ts +150 -0
  171. package/src/components/velero/host.tsx +86 -0
  172. package/src/components/velero/routes.ts +78 -0
  173. package/src/components/velero/runs.tsx +121 -0
  174. package/src/components/velero/shared.test.ts +84 -0
  175. package/src/components/velero/shared.tsx +423 -0
  176. package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
  177. package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
  178. package/src/components/velero/velero.fixtures.ts +61 -0
  179. package/src/components/velero/workspaceRoute.ts +21 -0
  180. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
  181. package/src/components/vulnerabilities/parts.test.ts +72 -0
  182. package/src/components/vulnerabilities/parts.tsx +291 -0
  183. package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
  184. package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
  185. package/src/components/workload/WorkloadView.tsx +114 -37
  186. package/src/components/workspace/DrawerTrailBack.tsx +32 -0
  187. package/src/components/workspace/WorkspaceFrame.tsx +71 -0
  188. package/src/components/workspace/coverage.ts +61 -0
  189. package/src/components/workspace/layout.test.tsx +29 -1
  190. package/src/components/workspace/layout.tsx +15 -5
  191. package/src/components/workspace/sidebar.ts +9 -0
  192. package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
  193. package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
  194. package/src/context/ConnectionContext.test.ts +1 -0
  195. package/src/context/ConnectionContext.tsx +2 -2
  196. package/src/desktop/AboutDialog.test.ts +12 -0
  197. package/src/desktop/AboutDialog.tsx +151 -0
  198. package/src/desktop/WindowsTitleBar.tsx +359 -0
  199. package/src/desktop/titleBar.test.ts +61 -0
  200. package/src/desktop/titleBar.ts +45 -0
  201. package/src/index.css +19 -0
  202. package/src/integrations/resourceHost.ts +5 -1
  203. package/src/integrations/resourceHosts.test.tsx +15 -3
  204. package/src/integrations/resourceHosts.tsx +26 -6
  205. package/src/integrations/workspaceRoute.ts +1 -1
  206. package/src/integrations/workspaceRoutes.test.ts +11 -0
  207. package/src/integrations/workspaceRoutes.ts +3 -1
  208. package/src/integrations/workspaceScreens.tsx +2 -0
  209. package/src/main.tsx +8 -0
  210. package/src/utils/desktop-zoom.test.ts +53 -0
  211. package/src/utils/desktop-zoom.ts +30 -0
  212. package/src/utils/namespacePick.test.ts +87 -0
  213. package/src/utils/namespacePick.ts +88 -0
  214. package/src/utils/staleAssetPrompt.test.tsx +76 -0
  215. package/src/utils/staleAssetPrompt.tsx +32 -0
@@ -0,0 +1,211 @@
1
+ // @vitest-environment jsdom
2
+ import { act, useEffect, type ReactNode } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { MemoryRouter, useLocation } from 'react-router-dom'
5
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
7
+ import type { AggregatedFlow, TrafficFlowsResponse } from '../../types'
8
+ import type { UseTrafficRecordsOptions } from '../../api/traffic'
9
+
10
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
11
+
12
+ vi.mock('elkjs/lib/elk.bundled.js', () => {
13
+ throw new Error('Failed to fetch dynamically imported module')
14
+ })
15
+
16
+ vi.mock('@xyflow/react', async importOriginal => ({
17
+ ...(await importOriginal<typeof import('@xyflow/react')>()),
18
+ ReactFlow: () => <div data-testid="flow" />,
19
+ }))
20
+
21
+ vi.mock('react-virtuoso', () => ({
22
+ Virtuoso: ({ data, itemContent }: { data: unknown[]; itemContent: (index: number, value: unknown) => ReactNode }) => (
23
+ <div>{data.map((value, index) => <div key={index}>{itemContent(index, value)}</div>)}</div>
24
+ ),
25
+ }))
26
+
27
+ const state = vi.hoisted(() => ({
28
+ flows: null as unknown,
29
+ recordsCalls: [] as unknown[],
30
+ }))
31
+
32
+ vi.mock('../../api/traffic', async importOriginal => {
33
+ const sources = {
34
+ cluster: {},
35
+ active: 'hubble',
36
+ detected: [{ name: 'hubble', status: 'available' }],
37
+ notDetected: [],
38
+ }
39
+ return {
40
+ ...(await importOriginal<typeof import('../../api/traffic')>()),
41
+ useTrafficSources: () => ({ data: sources, isLoading: false, detectAgain: () => Promise.resolve(sources) }),
42
+ useTrafficFlows: () => ({ data: state.flows, isFetching: false, dataUpdatedAt: 1, refetch: () => Promise.resolve() }),
43
+ useTrafficRecords: (options: unknown) => {
44
+ state.recordsCalls.push(options)
45
+ return { data: undefined, supported: false, tooLarge: false, isError: false, error: null, isLoading: false, refetch: () => Promise.resolve() }
46
+ },
47
+ useTrafficConnect: () => ({ mutate: (_vars: unknown, opts?: { onSuccess?: (d: unknown) => void }) => opts?.onSuccess?.({ connected: true }) }),
48
+ useSetTrafficSource: () => ({ mutate: () => {}, isPending: false }),
49
+ }
50
+ })
51
+
52
+ vi.mock('../../api/client', async importOriginal => ({
53
+ ...(await importOriginal<typeof import('../../api/client')>()),
54
+ useClusterInfo: () => ({ data: { context: 'test' } }),
55
+ useNamespaceScope: () => ({ data: undefined }),
56
+ }))
57
+
58
+ vi.mock('../dock', async importOriginal => ({
59
+ ...(await importOriginal<typeof import('../dock')>()),
60
+ useDock: () => ({ setLeftOffset: () => {}, addTab: () => 'flows', removeTab: () => {} }),
61
+ }))
62
+
63
+ vi.mock('../../context/ConnectionContext', async importOriginal => ({
64
+ ...(await importOriginal<typeof import('../../context/ConnectionContext')>()),
65
+ useConnection: () => ({ connection: { state: 'connected' } }),
66
+ }))
67
+
68
+ const { TrafficView } = await import('./TrafficView')
69
+
70
+ const endpoint = (namespace: string, name: string, kind = 'Deployment') => ({ namespace, name, kind })
71
+ const flow = (source: AggregatedFlow['source'], destination: AggregatedFlow['destination'], port: number, connections: number): AggregatedFlow => ({
72
+ source, destination, protocol: 'tcp', port, connections, lastSeen: '', flowCount: 1, bytesSent: 0, bytesRecv: 0,
73
+ })
74
+
75
+ // An addon talking to the API server is the edge grouping folds into the
76
+ // addon group; a plain workload edge is drawn as it is.
77
+ const aggregated = [
78
+ flow(endpoint('shop', 'prometheus'), endpoint('default', 'kubernetes', 'Service'), 443, 17),
79
+ flow(endpoint('shop', 'web'), endpoint('shop', 'api'), 80, 5),
80
+ ]
81
+
82
+ function flowsResponse(warning?: string): TrafficFlowsResponse {
83
+ return { source: 'hubble', timestamp: '', flows: [], aggregated, ...(warning && { warning }) } as TrafficFlowsResponse
84
+ }
85
+
86
+ const seen = { search: '' }
87
+ function LocationProbe() {
88
+ const { search } = useLocation()
89
+ useEffect(() => {
90
+ seen.search = search
91
+ }, [search])
92
+ return null
93
+ }
94
+
95
+ let container: HTMLDivElement
96
+ let root: Root
97
+
98
+ async function render() {
99
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, enabled: false } } })
100
+ await act(async () => {
101
+ root.render(
102
+ <QueryClientProvider client={queryClient}>
103
+ <MemoryRouter initialEntries={['/traffic']}>
104
+ <TrafficView namespaces={[]} />
105
+ <LocationProbe />
106
+ </MemoryRouter>
107
+ </QueryClientProvider>,
108
+ )
109
+ })
110
+ await settle()
111
+ }
112
+
113
+ async function settle() {
114
+ for (let i = 0; i < 3; i++) {
115
+ await act(async () => {
116
+ await new Promise(resolve => setTimeout(resolve, 0))
117
+ })
118
+ }
119
+ }
120
+
121
+ async function click(el: Element | undefined | null) {
122
+ expect(el).toBeTruthy()
123
+ await act(async () => {
124
+ (el as HTMLElement).click()
125
+ })
126
+ await settle()
127
+ }
128
+
129
+ const button = (text: string) => Array.from(container.querySelectorAll('button')).find(b => b.textContent?.trim() === text)
130
+ const toggle = (label: string) => Array.from(container.querySelectorAll('button')).find(b => b.textContent?.startsWith(label))
131
+ const rows = () => Array.from(container.querySelectorAll('[role="row"]'))
132
+ const lastMatch = () => (state.recordsCalls.at(-1) as UseTrafficRecordsOptions).match
133
+
134
+ beforeEach(() => {
135
+ vi.spyOn(console, 'error').mockImplementation(() => {})
136
+ state.recordsCalls = []
137
+ state.flows = flowsResponse()
138
+ container = document.createElement('div')
139
+ document.body.appendChild(container)
140
+ root = createRoot(container)
141
+ })
142
+
143
+ afterEach(() => {
144
+ act(() => root.unmount())
145
+ container.remove()
146
+ vi.restoreAllMocks()
147
+ })
148
+
149
+ describe('TrafficView when the layout engine cannot load', () => {
150
+ it('lists each connection as it is, with grouped addons, and selects and focuses real endpoints', async () => {
151
+ await render()
152
+ await click(toggle('Hide System'))
153
+ await click(button('group'))
154
+
155
+ expect(container.querySelector('[data-testid="flow"]')).toBeNull()
156
+ expect(container.textContent).toContain('The traffic map could not load its layout engine')
157
+ expect(button('Reload')).toBeDefined()
158
+
159
+ expect(rows()).toHaveLength(2)
160
+ expect(container.textContent).not.toMatch(/addon-group|addon-internet/)
161
+ const prometheus = rows().find(r => r.textContent?.includes('prometheus'))!
162
+ expect(prometheus.textContent).toContain('kubernetes')
163
+ expect(prometheus.textContent).toContain('17')
164
+ expect(rows().find(r => r.textContent?.includes('web'))?.textContent).toContain('5')
165
+
166
+ await click(prometheus)
167
+ expect(rows().find(r => r.textContent?.includes('prometheus'))?.getAttribute('aria-selected')).toBe('true')
168
+ expect(lastMatch()).toEqual({
169
+ pairs: [expect.objectContaining({
170
+ source: expect.objectContaining({ namespace: 'shop', name: 'prometheus' }),
171
+ destination: expect.objectContaining({ namespace: 'default', name: 'kubernetes' }),
172
+ port: 443,
173
+ })],
174
+ })
175
+
176
+ const focusPrometheus = Array.from(rows()[0].querySelectorAll('button')).find(b => b.textContent?.includes('prometheus'))
177
+ await click(focusPrometheus)
178
+ expect(new URLSearchParams(seen.search).get('focus')).toBe('shop/prometheus')
179
+ })
180
+
181
+ it("puts the source's warning above the explanation instead of over it", async () => {
182
+ state.flows = flowsResponse('Some nodes could not be reached.')
183
+ await render()
184
+
185
+ const warning = Array.from(container.querySelectorAll('[role="status"]')).find(el => el.textContent?.includes('Some nodes could not be reached.'))
186
+ expect(warning).toBeDefined()
187
+ expect(container.querySelectorAll('.top-14')).toHaveLength(0)
188
+ const panel = warning!.parentElement!
189
+ expect(panel.textContent).toContain('The traffic map could not load its layout engine')
190
+ expect(panel.textContent!.indexOf('Some nodes could not be reached.')).toBeLessThan(panel.textContent!.indexOf('The traffic map could not load its layout engine'))
191
+ })
192
+ })
193
+
194
+
195
+ describe('TrafficView protocol byte merges', () => {
196
+ for (const external of [false, true]) {
197
+ it(`keeps protocol buckets through ${external ? 'external service and Internet' : 'internal service'} collapse`, async () => {
198
+ const source = endpoint(external ? '' : 'demo', external ? '1.2.3.4' : 'client', external ? 'External' : 'Pod')
199
+ const destination = endpoint('demo', 'api', 'Pod')
200
+ const http = { ...flow(source, destination, 0, 1), protocol: 'http', bytesSent: 5969, bytesRecv: 260965, bytesByProtocol: { http: { bytesSent: 5969, bytesRecv: 260965 } } }
201
+ const tcp = { ...flow({ ...source, name: external ? '5.6.7.8' : source.name }, destination, 0, 1), bytesSent: 32699, bytesRecv: 391439, bytesByProtocol: { tcp: { bytesSent: 32699, bytesRecv: 391439 } } }
202
+ state.flows = { ...flowsResponse(), aggregated: [http, tcp] }
203
+ const snapshot = structuredClone(state.flows)
204
+ await render()
205
+ expect(rows()).toHaveLength(1)
206
+ expect(Array.from(rows()[0].querySelectorAll('div.whitespace-nowrap')).map(line => line.textContent)).toEqual(['HTTP 260.7 KB', 'TCP 414.2 KB'])
207
+ expect(rows()[0].textContent).not.toMatch(/674\.9 KB|691,?072/)
208
+ expect(state.flows).toEqual(snapshot)
209
+ })
210
+ }
211
+ })
@@ -1,5 +1,5 @@
1
1
  import { useState, useEffect, useMemo, useRef, useCallback } from 'react'
2
- import { useTrafficSources, useTrafficFlows, useTrafficRecords, useTrafficConnect, useSetTrafficSource, type TrafficEndpointPair } from '../../api/traffic'
2
+ import { useTrafficSources, useTrafficFlows, useTrafficRecords, useTrafficConnect, useSetTrafficSource } from '../../api/traffic'
3
3
  import { useClusterInfo, useNamespaceScope } from '../../api/client'
4
4
  import { useSearchParams } from 'react-router-dom'
5
5
  import type { TrafficWizardState, AggregatedFlow, TrafficFlow } from '../../types'
@@ -11,13 +11,26 @@ import { Filter, Plug, List, Activity, AlertTriangle, Clock, Crosshair, X } from
11
11
  import { TrafficFocusSearch } from './TrafficFocusSearch'
12
12
  import { TrafficSourcePill } from './TrafficSourcePill'
13
13
  import { TrafficGraphTooLarge } from './TrafficGraphTooLarge'
14
+ import { TrafficGraphUnavailable } from './TrafficGraphUnavailable'
14
15
  import { useQueryClient } from '@tanstack/react-query'
15
16
  import { useDock } from '../dock'
16
17
  import { AlertBanner, EmptyState, PaneLoader, FreshnessControl } from '@skyhook-io/k8s-ui'
17
18
  import { useConnection } from '../../context/ConnectionContext'
18
19
  import { Tooltip } from '../ui/Tooltip'
19
20
  import { SEVERITY_TEXT } from '@skyhook-io/k8s-ui/utils/badge-colors'
20
- import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, type VolumeUnit, isExternalKind, mergeFlowVolume, coverageLabel, type GraphFlow, endpointPair, graphEndpoint, graphEndpointId, mergeRawPairs, mergedEdgePort, selectedEdgeMatcher, selectionRawPairs, selectionMatch, graphSize, GRAPH_DRAW_BUDGET, GRAPH_DRAW_CEILING, parseFocus, focusParam, focusId, focusNeighborhood, touchesFocus, endpointSummaries, namespaceSummaries, verdictChoices, type TrafficFocus } from './trafficFilters'
21
+ import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, type VolumeUnit, isExternalKind, groupAddonFlows, mergeFlowVolume, coverageLabel, type GraphFlow, endpointPair, graphEndpoint, graphEndpointId, mergeRawPairs, mergedEdgePort, selectedEdgeMatcher, selectionRawPairs, selectionMatch, graphSize, GRAPH_DRAW_BUDGET, GRAPH_DRAW_CEILING, parseFocus, focusParam, focusId, focusNeighborhood, touchesFocus, endpointSummaries, namespaceSummaries, verdictChoices, type TrafficFocus, warningRetries, warningBannerTitle, emptyWarningHeadline, rateWindowSeconds } from './trafficFilters'
22
+
23
+ // Where a warning about which cluster the traffic belongs to points: how the map
24
+ // keeps to this cluster in a shared metrics store, and how to set its label.
25
+ const CLUSTER_SCOPE_DOCS_URL = 'https://github.com/skyhook-io/radar/blob/main/docs/configuration.md#traffic-map-in-a-shared-metrics-store'
26
+
27
+ function ClusterScopeDocsLink() {
28
+ return (
29
+ <a className="text-xs text-accent hover:underline" href={CLUSTER_SCOPE_DOCS_URL} target="_blank" rel="noopener noreferrer">
30
+ How to fix this
31
+ </a>
32
+ )
33
+ }
21
34
 
22
35
  // Consecutive 2s retries of an empty result that came with a transient warning.
23
36
  const MAX_EMPTY_RETRIES = 5
@@ -413,6 +426,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
413
426
  // The view the graph was last drawn for, and so keeps drawing (up to the
414
427
  // ceiling) as refreshes move its size: set by drawing it or by Draw anyway.
415
428
  const [drawnViewKey, setDrawnViewKey] = useState<string | null>(null)
429
+ const [layoutUnavailable, setLayoutUnavailable] = useState(false)
416
430
  const dock = useDock()
417
431
  const graphPaneRef = useRef<HTMLDivElement>(null)
418
432
 
@@ -498,27 +512,16 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
498
512
  enabled: wizardState === 'ready' && !isConnecting && !connectionError,
499
513
  })
500
514
 
501
- // A 'partial' warning is the source telling us this is as complete as it gets —
502
- // an attribute it does not export, traffic it cannot orient. Retrying returns
503
- // the same answer, so retrying forever is all cost and no progress.
504
- const warningIsPermanent = flowsData?.warningKind === 'partial'
515
+ // A partial, incomplete or cluster warning is the source's answer rather than
516
+ // a hiccup, so retrying it is all cost and no progress.
517
+ const warningRetriable = warningRetries(flowsData?.warningKind)
505
518
  const coverage = coverageLabel(flowsData?.coveredSince, flowsData?.timestamp)
506
- // An 'incomplete' one is a fetch that worked but could not see everything
507
- // (events lost, nodes unreachable). Not a failure, so not retried at once.
508
- const warningIsIncomplete = flowsData?.warningKind === 'incomplete'
509
519
  const flowsWarning = flowsData?.warning ? (
510
520
  <AlertBanner
511
521
  variant="warning"
512
- // The title follows the kind. A partial warning is about values
513
- // on edges that are shown — a port reported as 0, UDP as TCP, a
514
- // 5xx rate that failed to load — so it says "unreliable", not
515
- // "incomplete", which would send the reader looking for missing
516
- // workloads. An incomplete or transient one beside flows is
517
- // exactly that: a stream cut short, events lost, a node the
518
- // relay could not reach, a TCP query that failed — edges may
519
- // be missing from what is drawn.
520
- title={warningIsPermanent ? 'Some values on this map are unreliable' : 'Some traffic may be missing from this map'}
522
+ title={warningBannerTitle(flowsData.warningKind)}
521
523
  message={flowsData.warning}
524
+ action={flowsData.warningClusterScope ? <ClusterScopeDocsLink /> : undefined}
522
525
  />
523
526
  ) : null
524
527
 
@@ -537,14 +540,14 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
537
540
  emptyRetriesRef.current = 0
538
541
  return
539
542
  }
540
- if (!warningIsPermanent && !warningIsIncomplete && !flowsFetching && emptyRetriesRef.current < MAX_EMPTY_RETRIES) {
543
+ if (warningRetriable && !flowsFetching && emptyRetriesRef.current < MAX_EMPTY_RETRIES) {
541
544
  const timer = setTimeout(() => {
542
545
  emptyRetriesRef.current += 1
543
546
  refetchFlowsRaw()
544
547
  }, 2000)
545
548
  return () => clearTimeout(timer)
546
549
  }
547
- }, [flowsData, warningIsPermanent, warningIsIncomplete, flowsFetching, refetchFlowsRaw])
550
+ }, [flowsData, warningRetriable, flowsFetching, refetchFlowsRaw])
548
551
 
549
552
  // Filter flows based on user preferences
550
553
  // Note: namespace filtering is done server-side via the global namespace selector
@@ -931,113 +934,9 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
931
934
  // A focused view draws its endpoints as they are: grouping the addons would
932
935
  // fold the focus or its neighbors into the group.
933
936
  const groupAddons = addonMode === 'group' && !focus
934
- const finalFlows = useMemo<GraphFlow[]>(() => {
935
- if (!groupAddons) return focusedFlows
936
-
937
- // Track totals for aggregated edges
938
- let addonInternetTotal = 0
939
- let addonToK8sTotal = 0
940
- let addonInternetRate = 0
941
- let addonToK8sRate = 0
942
- const addonInternetPairs: TrafficEndpointPair[] = []
943
- const addonToK8sPairs: TrafficEndpointPair[] = []
944
- const processedFlows: GraphFlow[] = []
945
-
946
- // Check if destination is the kubernetes API server
947
- const isKubernetesAPI = (name: string, namespace: string | undefined) => {
948
- return name === 'kubernetes' && (!namespace || namespace === 'default')
949
- }
950
-
951
- focusedFlows.forEach(flow => {
952
- const sourceIsAddon = isClusterAddon(flow.source.name, flow.source.namespace)
953
- const destIsAddon = isClusterAddon(flow.destination.name, flow.destination.namespace)
954
- const sourceIsInternet = flow.source.kind === 'Internet'
955
- const destIsK8sAPI = isKubernetesAPI(flow.destination.name, flow.destination.namespace)
956
-
957
- // Internet → Addon: aggregate into single edge to group
958
- if (sourceIsInternet && destIsAddon) {
959
- addonInternetTotal += flow.connections
960
- addonInternetRate += flow.requestRate ?? 0
961
- for (const pair of flow.rawPairs ?? []) addonInternetPairs.push(pair)
962
- processedFlows.push({
963
- ...flow,
964
- source: {
965
- name: 'addon-internet',
966
- namespace: '',
967
- kind: 'SkipEdge', // Create addon node but skip individual edge
968
- },
969
- })
970
- }
971
- // Addon → Kubernetes API: aggregate into single edge from group
972
- else if (sourceIsAddon && destIsK8sAPI) {
973
- addonToK8sTotal += flow.connections
974
- addonToK8sRate += flow.requestRate ?? 0
975
- for (const pair of flow.rawPairs ?? []) addonToK8sPairs.push(pair)
976
- processedFlows.push({
977
- ...flow,
978
- destination: {
979
- ...flow.destination,
980
- kind: 'SkipEdge', // Create kubernetes node but skip individual edge
981
- },
982
- })
983
- }
984
- else {
985
- processedFlows.push(flow)
986
- }
987
- })
988
-
989
- // Add virtual flow for Internet → Addon Group edge
990
- if (addonInternetTotal > 0) {
991
- processedFlows.push({
992
- source: {
993
- name: 'addon-internet',
994
- namespace: '',
995
- kind: 'AddonInternet',
996
- },
997
- destination: {
998
- name: 'addon-group-target',
999
- namespace: '',
1000
- kind: 'AddonGroupTarget',
1001
- },
1002
- protocol: 'tcp',
1003
- port: 0,
1004
- connections: addonInternetTotal,
1005
- ...(addonInternetRate > 0 && { requestRate: addonInternetRate }),
1006
- rawPairs: addonInternetPairs,
1007
- bytesSent: 0,
1008
- bytesRecv: 0,
1009
- flowCount: 1,
1010
- lastSeen: new Date().toISOString(),
1011
- })
1012
- }
1013
-
1014
- // Add virtual flow for Addon Group → Kubernetes edge
1015
- if (addonToK8sTotal > 0) {
1016
- processedFlows.push({
1017
- source: {
1018
- name: 'addon-group-source',
1019
- namespace: '',
1020
- kind: 'AddonGroupSource',
1021
- },
1022
- destination: {
1023
- name: 'kubernetes',
1024
- namespace: 'default',
1025
- kind: 'Service',
1026
- },
1027
- protocol: 'tcp',
1028
- port: 443,
1029
- connections: addonToK8sTotal,
1030
- ...(addonToK8sRate > 0 && { requestRate: addonToK8sRate }),
1031
- rawPairs: addonToK8sPairs,
1032
- bytesSent: 0,
1033
- bytesRecv: 0,
1034
- flowCount: 1,
1035
- lastSeen: new Date().toISOString(),
1036
- })
1037
- }
1038
-
1039
- return processedFlows
1040
- }, [focusedFlows, groupAddons])
937
+ const finalFlows = useMemo<GraphFlow[]>(() =>
938
+ groupAddons ? groupAddonFlows(focusedFlows, isClusterAddon) : focusedFlows,
939
+ [focusedFlows, groupAddons])
1041
940
 
1042
941
  // The map is laid out on the main thread, so a view too large to draw is
1043
942
  // listed as a table instead of freezing the tab.
@@ -1055,9 +954,13 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1055
954
  if (finalFlows.length > 0 && fitsBudget) setDrawnViewKey(viewKey)
1056
955
  }, [finalFlows.length, fitsBudget, viewKey])
1057
956
 
957
+ // Listed as a table instead of drawn: too large, or the map's layout engine
958
+ // could not load.
959
+ const listed = tooLargeToDraw || layoutUnavailable
960
+
1058
961
  // The table lists the endpoints as they are, so a selection made from it is
1059
962
  // traced through the same flows.
1060
- const selectableFlows = tooLargeToDraw ? focusedFlows : finalFlows
963
+ const selectableFlows = listed ? focusedFlows : finalFlows
1061
964
  // The server edges behind the selection, as drawn: what its records are
1062
965
  // narrowed to, whichever form the lookup is sent in.
1063
966
  // The flow list follows the focus while nothing else is selected: closing
@@ -1066,8 +969,8 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1066
969
  () => graphSelection ?? (focusFound && focusKey ? { type: 'node', nodeId: focusKey } : null),
1067
970
  [graphSelection, focusFound, focusKey])
1068
971
  const selectionPairs = useMemo(
1069
- () => selectionRawPairs(selectableFlows, listSelection, groupAddons && !tooLargeToDraw ? e => isClusterAddon(e.name, e.namespace) : undefined),
1070
- [listSelection, selectableFlows, groupAddons, tooLargeToDraw])
972
+ () => selectionRawPairs(selectableFlows, listSelection, groupAddons && !listed ? e => isClusterAddon(e.name, e.namespace) : undefined),
973
+ [listSelection, selectableFlows, groupAddons, listed])
1071
974
  const selection = useMemo(() => selectionMatch(selectionPairs, listSelection), [selectionPairs, listSelection])
1072
975
  // Ungrouped, a workload focus is drawn as its pods, so no node carries its
1073
976
  // id; its records are still the workload's.
@@ -1086,12 +989,12 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1086
989
  // A selection names something in the representation it was made in: the
1087
990
  // table lists endpoints as they are, the graph may group addons. Switching
1088
991
  // between them keeps only a focus's selection, which means the same in both.
1089
- const prevTooLargeRef = useRef(tooLargeToDraw)
992
+ const prevListedRef = useRef(listed)
1090
993
  useEffect(() => {
1091
- if (prevTooLargeRef.current === tooLargeToDraw) return
1092
- prevTooLargeRef.current = tooLargeToDraw
994
+ if (prevListedRef.current === listed) return
995
+ prevListedRef.current = listed
1093
996
  setGraphSelection(prev => (prev?.type === 'node' && prev.nodeId === focusKey ? prev : null))
1094
- }, [tooLargeToDraw, focusKey])
997
+ }, [listed, focusKey])
1095
998
 
1096
999
  // Namespaces hidden in the sidebar are dropped at the source too, when the
1097
1000
  // request has room, so their traffic can't fill the records limit. Only
@@ -1553,7 +1456,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1553
1456
  />
1554
1457
  ) : finalFlows.length > 0 ? (
1555
1458
  <>
1556
- {flowsWarning && !tooLargeToDraw && (
1459
+ {flowsWarning && !listed && (
1557
1460
  // Sits below the two chip rows (both top-3) rather than beside
1558
1461
  // them: centred at that height it would cover the flow count and
1559
1462
  // the refresh control at common widths. role/aria-live because it
@@ -1585,18 +1488,33 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1585
1488
  notice={flowsWarning && <div role="status" aria-live="polite">{flowsWarning}</div>}
1586
1489
  />
1587
1490
  ) : (
1588
- <TrafficGraph
1589
- flows={finalFlows}
1590
- hotPathThreshold={hotPathThreshold}
1591
- showNamespaceGroups={showNamespaceGroups}
1592
- serviceCategories={serviceCategories}
1593
- addonMode={groupAddons ? 'group' : addonMode === 'group' ? 'show' : addonMode}
1594
- trafficSource={sourcesData?.active || ''}
1595
- selection={graphSelection}
1596
- onSelectionChange={setGraphSelection}
1597
- onFocus={setFocus}
1598
- focusedId={focusKey}
1599
- />
1491
+ <>
1492
+ {layoutUnavailable && (
1493
+ <TrafficGraphUnavailable
1494
+ flows={focusedFlows}
1495
+ isRateBased={isRateBased}
1496
+ selection={graphSelection}
1497
+ onSelect={setGraphSelection}
1498
+ onFocus={setFocus}
1499
+ focusedId={focusKey}
1500
+ notice={flowsWarning && <div role="status" aria-live="polite">{flowsWarning}</div>}
1501
+ />
1502
+ )}
1503
+ <TrafficGraph
1504
+ flows={finalFlows}
1505
+ hotPathThreshold={hotPathThreshold}
1506
+ showNamespaceGroups={showNamespaceGroups}
1507
+ serviceCategories={serviceCategories}
1508
+ addonMode={groupAddons ? 'group' : addonMode === 'group' ? 'show' : addonMode}
1509
+ trafficSource={sourcesData?.active || ''}
1510
+ selection={graphSelection}
1511
+ onSelectionChange={setGraphSelection}
1512
+ onFocus={setFocus}
1513
+ focusedId={focusKey}
1514
+ onLayoutUnavailable={setLayoutUnavailable}
1515
+ windowSeconds={rateWindowSeconds(timeRange)}
1516
+ />
1517
+ </>
1600
1518
  )}
1601
1519
  </>
1602
1520
  ) : focus && flowsData && !connectionError ? (
@@ -1612,6 +1530,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1612
1530
  onShowSystem={() => setHideSystem(false)}
1613
1531
  onSwitchNamespace={onSetNamespaces && !namespaceLocked && focus.namespace ? () => onSetNamespaces([focus.namespace!]) : undefined}
1614
1532
  warning={flowsData.warning}
1533
+ warningClusterScope={flowsData.warningClusterScope}
1615
1534
  onLeave={() => setFocus(null)}
1616
1535
  />
1617
1536
  </div>
@@ -1660,14 +1579,9 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1660
1579
  tone="neutral"
1661
1580
  variant="card"
1662
1581
  icon={AlertTriangle}
1663
- headline={
1664
- warningIsPermanent
1665
- ? 'No traffic Radar can place on the map'
1666
- : warningIsIncomplete
1667
- ? 'No traffic seen, but some may be missing'
1668
- : 'Unable to fetch traffic data'
1669
- }
1582
+ headline={emptyWarningHeadline(flowsData.warningKind)}
1670
1583
  body={flowsData.warning}
1584
+ action={flowsData.warningClusterScope ? <ClusterScopeDocsLink /> : undefined}
1671
1585
  className="max-w-md"
1672
1586
  />
1673
1587
  ) : (
@@ -1697,12 +1611,14 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1697
1611
  * one of them means the workload is quiet: Radar may have hidden its traffic,
1698
1612
  * or never fetched it.
1699
1613
  */
1700
- function FocusNotFound({ focus, hiddenByFilters, systemHidden, hideSystem, outsideNamespaces, window, onShowAll, onShowSystem, onSwitchNamespace, warning, onLeave }: {
1614
+ function FocusNotFound({ focus, hiddenByFilters, systemHidden, hideSystem, outsideNamespaces, window, onShowAll, onShowSystem, onSwitchNamespace, warning, warningClusterScope, onLeave }: {
1701
1615
  focus: TrafficFocus
1702
1616
  /** Hide System is on: traffic with system namespaces was never fetched. */
1703
1617
  hideSystem: boolean
1704
1618
  /** The fetch's own warning: with it, absence is not proof of quiet. */
1705
1619
  warning?: string
1620
+ /** The warning is about which cluster the traffic belongs to. */
1621
+ warningClusterScope?: boolean
1706
1622
  hiddenByFilters: boolean
1707
1623
  systemHidden: boolean
1708
1624
  outsideNamespaces: boolean
@@ -1755,6 +1671,7 @@ function FocusNotFound({ focus, hiddenByFilters, systemHidden, hideSystem, outsi
1755
1671
  >
1756
1672
  Leave focus
1757
1673
  </button>
1674
+ {warningClusterScope && <ClusterScopeDocsLink />}
1758
1675
  </div>
1759
1676
  }
1760
1677
  className="max-w-md"