@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,193 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, type ComponentProps } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import type { AggregatedFlow } from '../../types'
|
|
6
|
+
import type { TrafficGraph as TrafficGraphType } from './TrafficGraph'
|
|
7
|
+
|
|
8
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
9
|
+
|
|
10
|
+
type ElkGraph = { children: Array<{ id: string }>; edges: unknown[] }
|
|
11
|
+
|
|
12
|
+
let pendingLayouts: Array<{ resolve: () => void }> = []
|
|
13
|
+
|
|
14
|
+
// The engine module is mocked per test: a failed import has to come from the
|
|
15
|
+
// module itself, and a resolved one stays cached in TrafficGraph.
|
|
16
|
+
function mockElk(fail: boolean) {
|
|
17
|
+
vi.doMock('elkjs/lib/elk.bundled.js', () => {
|
|
18
|
+
if (fail) throw new Error('Failed to fetch dynamically imported module')
|
|
19
|
+
return {
|
|
20
|
+
default: class {
|
|
21
|
+
layout(graph: ElkGraph) {
|
|
22
|
+
return new Promise(resolve => {
|
|
23
|
+
pendingLayouts.push({
|
|
24
|
+
resolve: () => resolve({ ...graph, children: graph.children.map((c, i) => ({ ...c, x: i * 300, y: 0 })) }),
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The canvas needs layout APIs jsdom lacks; what the graph hands it is what
|
|
34
|
+
// these tests check.
|
|
35
|
+
vi.mock('@xyflow/react', async importOriginal => ({
|
|
36
|
+
...(await importOriginal<typeof import('@xyflow/react')>()),
|
|
37
|
+
ReactFlow: ({ nodes, edges }: { nodes: unknown[]; edges: unknown[] }) => (
|
|
38
|
+
<div data-testid="flow" data-nodes={nodes.length} data-edges={edges.length} />
|
|
39
|
+
),
|
|
40
|
+
}))
|
|
41
|
+
|
|
42
|
+
const flow = (src: string, dst: string): AggregatedFlow => ({
|
|
43
|
+
source: { name: src, namespace: 'shop', kind: 'Deployment' },
|
|
44
|
+
destination: { name: dst, namespace: 'shop', kind: 'Deployment' },
|
|
45
|
+
protocol: 'tcp',
|
|
46
|
+
port: 80,
|
|
47
|
+
lastSeen: '',
|
|
48
|
+
flowCount: 1,
|
|
49
|
+
bytesSent: 0,
|
|
50
|
+
bytesRecv: 0,
|
|
51
|
+
connections: 1,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
let container: HTMLDivElement
|
|
55
|
+
let root: Root
|
|
56
|
+
let TrafficGraph: typeof TrafficGraphType
|
|
57
|
+
const onLayoutUnavailable = vi.fn()
|
|
58
|
+
|
|
59
|
+
const props = (flows: AggregatedFlow[]): ComponentProps<typeof TrafficGraphType> => ({
|
|
60
|
+
flows,
|
|
61
|
+
selection: null,
|
|
62
|
+
onSelectionChange: vi.fn(),
|
|
63
|
+
onFocus: vi.fn(),
|
|
64
|
+
onLayoutUnavailable,
|
|
65
|
+
windowSeconds: 300,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
async function render(flows: AggregatedFlow[]) {
|
|
69
|
+
await act(async () => root.render(<TrafficGraph {...props(flows)} />))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function settle() {
|
|
73
|
+
await act(async () => {
|
|
74
|
+
await new Promise(resolve => setTimeout(resolve, 0))
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Loading the engine is a dynamic import, which goes through the module loader
|
|
79
|
+
// and takes real time, so a fixed number of ticks is not enough on a busy
|
|
80
|
+
// machine: wait for the state the test is about instead.
|
|
81
|
+
async function until(check: () => void) {
|
|
82
|
+
await vi.waitFor(async () => {
|
|
83
|
+
await settle()
|
|
84
|
+
check()
|
|
85
|
+
}, { timeout: 5000, interval: 20 })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const canvas = () => container.querySelector<HTMLElement>('[data-testid="flow"]')
|
|
89
|
+
|
|
90
|
+
// Importing TrafficGraph is slow, and a test's own time limit should not pay
|
|
91
|
+
// for it, so each engine variant is imported once in a hook. The mocked engine
|
|
92
|
+
// writes to pendingLayouts, so tests sharing one import stay independent. A
|
|
93
|
+
// cold import transforms TrafficGraph's whole import tree, which can take
|
|
94
|
+
// longer than the default hook timeout on a busy machine or a fresh CI runner.
|
|
95
|
+
const IMPORT_TIMEOUT_MS = 60_000
|
|
96
|
+
|
|
97
|
+
async function load({ failElk = false } = {}) {
|
|
98
|
+
vi.resetModules()
|
|
99
|
+
mockElk(failElk)
|
|
100
|
+
;({ TrafficGraph } = await import('./TrafficGraph'))
|
|
101
|
+
// TrafficGraph imports the engine on its first layout; load the mock here so
|
|
102
|
+
// that import doesn't land inside the first test's time limit either.
|
|
103
|
+
if (!failElk) await import('elkjs/lib/elk.bundled.js')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
beforeEach(() => {
|
|
107
|
+
pendingLayouts = []
|
|
108
|
+
onLayoutUnavailable.mockReset()
|
|
109
|
+
container = document.createElement('div')
|
|
110
|
+
document.body.appendChild(container)
|
|
111
|
+
root = createRoot(container)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
afterEach(() => {
|
|
115
|
+
act(() => root.unmount())
|
|
116
|
+
container.remove()
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('TrafficGraph layout engine', () => {
|
|
120
|
+
beforeAll(() => load(), IMPORT_TIMEOUT_MS)
|
|
121
|
+
|
|
122
|
+
it('shows a loader until the first layout lands, then the graph', async () => {
|
|
123
|
+
await render([flow('web', 'api')])
|
|
124
|
+
await until(() => expect(pendingLayouts).toHaveLength(1))
|
|
125
|
+
|
|
126
|
+
expect(container.textContent).toContain('Laying out traffic…')
|
|
127
|
+
expect(canvas()?.dataset.nodes).toBe('0')
|
|
128
|
+
|
|
129
|
+
await act(async () => pendingLayouts[0].resolve())
|
|
130
|
+
await until(() => expect(canvas()?.dataset.nodes).toBe('2'))
|
|
131
|
+
|
|
132
|
+
expect(container.textContent).not.toContain('Laying out traffic…')
|
|
133
|
+
expect(canvas()?.dataset.nodes).toBe('2')
|
|
134
|
+
expect(canvas()?.dataset.edges).toBe('1')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('keeps the drawn graph while a later layout runs', async () => {
|
|
138
|
+
await render([flow('web', 'api')])
|
|
139
|
+
await until(() => expect(pendingLayouts).toHaveLength(1))
|
|
140
|
+
await act(async () => pendingLayouts[0].resolve())
|
|
141
|
+
await until(() => expect(canvas()?.dataset.nodes).toBe('2'))
|
|
142
|
+
|
|
143
|
+
await render([flow('web', 'api'), flow('api', 'db')])
|
|
144
|
+
await until(() => expect(pendingLayouts).toHaveLength(2))
|
|
145
|
+
|
|
146
|
+
expect(container.textContent).not.toContain('Laying out traffic…')
|
|
147
|
+
expect(canvas()?.dataset.nodes).toBe('2')
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('does not let a replaced layout overwrite a newer one', async () => {
|
|
151
|
+
await render([flow('web', 'api')])
|
|
152
|
+
await until(() => expect(pendingLayouts).toHaveLength(1))
|
|
153
|
+
await render([flow('web', 'api'), flow('api', 'db')])
|
|
154
|
+
await until(() => expect(pendingLayouts).toHaveLength(2))
|
|
155
|
+
|
|
156
|
+
await act(async () => pendingLayouts[1].resolve())
|
|
157
|
+
await until(() => expect(canvas()?.dataset.nodes).toBe('3'))
|
|
158
|
+
// The engine is loaded by now, so the stale layout settles in microtasks.
|
|
159
|
+
await act(async () => pendingLayouts[0].resolve())
|
|
160
|
+
await settle()
|
|
161
|
+
|
|
162
|
+
expect(canvas()?.dataset.nodes).toBe('3')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('reports the engine available once a layout lands', async () => {
|
|
166
|
+
await render([flow('web', 'api')])
|
|
167
|
+
await until(() => expect(pendingLayouts).toHaveLength(1))
|
|
168
|
+
await act(async () => pendingLayouts[0].resolve())
|
|
169
|
+
await until(() => expect(onLayoutUnavailable).toHaveBeenLastCalledWith(false))
|
|
170
|
+
|
|
171
|
+
expect(onLayoutUnavailable).not.toHaveBeenCalledWith(true)
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
describe('TrafficGraph layout engine that cannot load', () => {
|
|
176
|
+
beforeAll(() => load({ failElk: true }), IMPORT_TIMEOUT_MS)
|
|
177
|
+
|
|
178
|
+
it('draws nothing and reports the engine unavailable instead of drawing a partial grid when ELK cannot load', async () => {
|
|
179
|
+
const errors = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
180
|
+
await render([flow('web', 'api')])
|
|
181
|
+
await until(() => expect(onLayoutUnavailable).toHaveBeenLastCalledWith(true))
|
|
182
|
+
|
|
183
|
+
expect(canvas()).toBeNull()
|
|
184
|
+
expect(container.textContent).toBe('')
|
|
185
|
+
expect(onLayoutUnavailable).toHaveBeenLastCalledWith(true)
|
|
186
|
+
expect(errors).toHaveBeenCalledWith('ELK failed to load:', expect.any(Error))
|
|
187
|
+
errors.mockRestore()
|
|
188
|
+
|
|
189
|
+
act(() => root.unmount())
|
|
190
|
+
expect(onLayoutUnavailable).toHaveBeenLastCalledWith(false)
|
|
191
|
+
root = createRoot(container)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, useState, type ReactNode } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import type { Edge, Node } from '@xyflow/react'
|
|
6
|
+
import type { AggregatedFlow } from '../../types'
|
|
7
|
+
import { TrafficGraph } from './TrafficGraph'
|
|
8
|
+
import { endpointPair, groupAddonFlows } from './trafficFilters'
|
|
9
|
+
|
|
10
|
+
const { fitView } = vi.hoisted(() => ({ fitView: vi.fn() }))
|
|
11
|
+
vi.mock('./TrafficView', () => ({ isClusterAddon: (_name: string, namespace: string) => namespace === 'monitoring' }))
|
|
12
|
+
vi.mock('elkjs/lib/elk.bundled.js', () => ({
|
|
13
|
+
default: class {
|
|
14
|
+
async layout(graph: { children: Node[] }) {
|
|
15
|
+
return { ...graph, children: graph.children.map((node, index) => ({ ...node, x: index * 250, y: 0 })) }
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
}))
|
|
19
|
+
vi.mock('@xyflow/react', () => ({
|
|
20
|
+
ReactFlow: ({ nodes, edges, onNodeClick, onEdgeClick, children }: {
|
|
21
|
+
nodes: Node[]; edges: Edge[]; onNodeClick: (event: unknown, node: Node) => void
|
|
22
|
+
onEdgeClick: (event: unknown, edge: Edge) => void; children: ReactNode
|
|
23
|
+
}) => (
|
|
24
|
+
<div>
|
|
25
|
+
{nodes.map(node => <button key={node.id} data-node={node.id} data-connections={node.data.connections}
|
|
26
|
+
data-total-volume={node.data.totalConnections} data-ports={JSON.stringify(node.data.ports)}
|
|
27
|
+
onClick={() => onNodeClick({}, node)}>{node.data.label as string}</button>)}
|
|
28
|
+
{edges.map(edge => <button key={edge.id} data-edge={edge.id} onClick={() => onEdgeClick({}, edge)}>{edge.label as string}</button>)}
|
|
29
|
+
{children}
|
|
30
|
+
</div>
|
|
31
|
+
),
|
|
32
|
+
Background: () => null,
|
|
33
|
+
Controls: () => null,
|
|
34
|
+
Handle: () => null,
|
|
35
|
+
MarkerType: { ArrowClosed: 'arrowclosed' },
|
|
36
|
+
Position: { Left: 'left', Right: 'right' },
|
|
37
|
+
useNodesState: (initial: Node[]) => [...useState(initial), vi.fn()],
|
|
38
|
+
useEdgesState: (initial: Edge[]) => [...useState(initial), vi.fn()],
|
|
39
|
+
useReactFlow: () => ({ fitView }),
|
|
40
|
+
}))
|
|
41
|
+
|
|
42
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
43
|
+
let container: HTMLDivElement
|
|
44
|
+
let root: Root
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
container = document.createElement('div')
|
|
47
|
+
document.body.appendChild(container)
|
|
48
|
+
root = createRoot(container)
|
|
49
|
+
})
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
act(() => root.unmount())
|
|
52
|
+
container.remove()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const addon = { name: 'prometheus', namespace: 'monitoring', kind: 'Pod' }
|
|
56
|
+
const incoming: AggregatedFlow = {
|
|
57
|
+
source: { name: 'Internet', namespace: '', kind: 'Internet' }, destination: addon,
|
|
58
|
+
protocol: 'tcp', port: 443, connections: 0, bytesSent: 100, bytesRecv: 200, bytesByProtocol: { tcp: { bytesSent: 100, bytesRecv: 200 } }, flowCount: 1, lastSeen: '',
|
|
59
|
+
}
|
|
60
|
+
const outgoing: AggregatedFlow = {
|
|
61
|
+
...incoming, source: addon, destination: { name: 'kubernetes', namespace: 'default', kind: 'Service' },
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('TrafficGraph addon group edges', () => {
|
|
65
|
+
for (const source of ['istio', 'beyla']) {
|
|
66
|
+
for (const [flow, edgeId, port] of [
|
|
67
|
+
[incoming, 'addon-internet->addon-group', 443],
|
|
68
|
+
[outgoing, 'addon-group->default/kubernetes', 443],
|
|
69
|
+
] as const) {
|
|
70
|
+
it(`shows Data without a rate when selecting ${edgeId} from ${source}`, async () => {
|
|
71
|
+
const grouped = groupAddonFlows([{ ...flow, rawPairs: [endpointPair(flow)] }], (_name, ns) => ns === 'monitoring')
|
|
72
|
+
const onSelectionChange = vi.fn()
|
|
73
|
+
await act(async () => root.render(<TrafficGraph flows={grouped} trafficSource={source} addonMode="group" onSelectionChange={onSelectionChange} onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
74
|
+
const edge = container.querySelector<HTMLButtonElement>(`[data-edge="${edgeId}"]`)!
|
|
75
|
+
expect(edge).not.toBeNull()
|
|
76
|
+
// 300 bytes over the 300s window, with no request rate to show.
|
|
77
|
+
expect(edge.textContent).toBe('TCP · 1 B/s')
|
|
78
|
+
act(() => edge.click())
|
|
79
|
+
expect(container.textContent).toContain('Data300 B')
|
|
80
|
+
expect(container.textContent).not.toContain('Request Rate')
|
|
81
|
+
expect(container.textContent).not.toContain('0/s')
|
|
82
|
+
expect(onSelectionChange.mock.calls[0][0]).toMatchObject({ type: 'edge', port, directionUnknown: false })
|
|
83
|
+
await act(async () => root.render(<TrafficGraph flows={grouped} trafficSource={source} addonMode="group" selection={onSelectionChange.mock.calls[0][0]} onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
84
|
+
expect(container.textContent).toContain('Data300 B')
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (const [flow, edgeId, nodeId] of [
|
|
90
|
+
[incoming, 'addon-internet->addon-group', 'addon-internet'],
|
|
91
|
+
[outgoing, 'addon-group->default/kubernetes', 'default/kubernetes'],
|
|
92
|
+
] as const) {
|
|
93
|
+
it(`shows HTTP metadata without an invented port in ${edgeId} details`, async () => {
|
|
94
|
+
const http = { ...flow, protocol: 'http', l7Protocol: 'HTTP', bytesByProtocol: { http: { bytesSent: 100, bytesRecv: 200 } }, port: 0, connections: 2, requestRate: 1.7 }
|
|
95
|
+
const grouped = groupAddonFlows([{ ...http, rawPairs: [endpointPair(http)] }], (_name, ns) => ns === 'monitoring')
|
|
96
|
+
const onSelectionChange = vi.fn()
|
|
97
|
+
await act(async () => root.render(<TrafficGraph flows={grouped} trafficSource="istio" addonMode="group" onSelectionChange={onSelectionChange} onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
98
|
+
act(() => container.querySelector<HTMLButtonElement>(`[data-edge="${edgeId}"]`)!.click())
|
|
99
|
+
expect(container.textContent).toContain('ProtocolHTTP')
|
|
100
|
+
expect(container.textContent).not.toContain('Port')
|
|
101
|
+
expect(container.textContent).not.toContain('tcp')
|
|
102
|
+
expect(onSelectionChange.mock.calls[0][0]).toMatchObject({ type: 'edge', port: 0 })
|
|
103
|
+
act(() => container.querySelector<HTMLButtonElement>(`[data-node="${nodeId}"]`)!.click())
|
|
104
|
+
const protocols = Array.from(container.querySelectorAll('div')).find(el => el.textContent === 'Protocols')!.parentElement!
|
|
105
|
+
expect(protocols.textContent).toBe('ProtocolsHTTPHTTP1.7/s')
|
|
106
|
+
expect(container.textContent).toContain('Data transferred300 B')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it(`shows mixed metadata in ${edgeId} details`, async () => {
|
|
110
|
+
const http = { ...flow, protocol: 'http', l7Protocol: 'HTTP', bytesByProtocol: { http: { bytesSent: 100, bytesRecv: 200 } }, port: 8080 }
|
|
111
|
+
const grouped = groupAddonFlows([http, flow].map(f => ({ ...f, rawPairs: [endpointPair(f)] })), (_name, ns) => ns === 'monitoring')
|
|
112
|
+
await act(async () => root.render(<TrafficGraph flows={grouped} trafficSource="istio" addonMode="group" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
113
|
+
act(() => container.querySelector<HTMLButtonElement>(`[data-edge="${edgeId}"]`)!.click())
|
|
114
|
+
expect(container.textContent).toContain('Port443')
|
|
115
|
+
expect(container.textContent).toContain('ProtocolHTTP + TCP')
|
|
116
|
+
expect(container.textContent).toContain('Data by protocolHTTP 100 B sent · 200 B receivedTCP 100 B sent · 200 B received')
|
|
117
|
+
expect(container.textContent).not.toContain('600 B')
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
describe('TrafficGraph addon group node accounting', () => {
|
|
124
|
+
for (const source of ['istio', 'beyla', 'hubble']) {
|
|
125
|
+
for (const [flow, nodeId, direction] of [
|
|
126
|
+
[incoming, 'addon-internet', 'Outgoing'],
|
|
127
|
+
[outgoing, 'default/kubernetes', 'Incoming'],
|
|
128
|
+
] as const) {
|
|
129
|
+
it(`counts Data once when selecting ${nodeId} from ${source}`, async () => {
|
|
130
|
+
const grouped = groupAddonFlows([{ ...flow, rawPairs: [endpointPair(flow)] }], (_name, ns) => ns === 'monitoring')
|
|
131
|
+
await act(async () => root.render(<TrafficGraph flows={grouped} trafficSource={source} addonMode="group" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
132
|
+
const node = container.querySelector<HTMLButtonElement>(`[data-node="${nodeId}"]`)!
|
|
133
|
+
expect(node).not.toBeNull()
|
|
134
|
+
expect(node.dataset.connections).toBe('1')
|
|
135
|
+
act(() => node.click())
|
|
136
|
+
expect(container.textContent).toContain('Data transferred300 B')
|
|
137
|
+
expect(container.textContent).not.toContain('600 B')
|
|
138
|
+
expect(container.textContent).toContain(`${direction} (1)`)
|
|
139
|
+
|
|
140
|
+
const addonNode = container.querySelector<HTMLButtonElement>('[data-node="monitoring/prometheus"]')!
|
|
141
|
+
expect(addonNode.dataset.connections).toBe('1')
|
|
142
|
+
act(() => addonNode.click())
|
|
143
|
+
expect(container.textContent).toContain('Data transferred300 B')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it(`counts node volume and ports once at ${nodeId} from ${source}`, async () => {
|
|
147
|
+
const measured = { ...flow, connections: 2, requestRate: 1.7 }
|
|
148
|
+
const grouped = groupAddonFlows([{ ...measured, rawPairs: [endpointPair(measured)] }], (_name, ns) => ns === 'monitoring')
|
|
149
|
+
await act(async () => root.render(<TrafficGraph flows={grouped} trafficSource={source} addonMode="group" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
150
|
+
const volume = source === 'hubble' ? 2 : 1.7
|
|
151
|
+
for (const id of [nodeId, 'monitoring/prometheus']) {
|
|
152
|
+
const node = container.querySelector<HTMLButtonElement>(`[data-node="${id}"]`)!
|
|
153
|
+
expect(node.dataset.connections).toBe('1')
|
|
154
|
+
expect(Number(node.dataset.totalVolume)).toBe(volume)
|
|
155
|
+
if (id === 'default/kubernetes' || (id === 'monitoring/prometheus' && direction === 'Outgoing')) {
|
|
156
|
+
expect(JSON.parse(node.dataset.ports!)).toEqual([{ port: 443, connections: volume }])
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
describe('TrafficGraph protocol data', () => {
|
|
165
|
+
const buckets = { http: { bytesSent: 5969, bytesRecv: 260965 }, tcp: { bytesSent: 32699, bytesRecv: 391439 } }
|
|
166
|
+
const sample = { bytesSent: 38668, bytesRecv: 652404, bytesByProtocol: buckets }
|
|
167
|
+
|
|
168
|
+
for (const [flow, edgeId, endpointId, direction] of [
|
|
169
|
+
[incoming, 'addon-internet->addon-group', 'addon-internet', 'Outgoing'],
|
|
170
|
+
[outgoing, 'addon-group->default/kubernetes', 'default/kubernetes', 'Incoming'],
|
|
171
|
+
] as const) {
|
|
172
|
+
it(`keeps both protocols at the virtual edge and both ends of ${edgeId}`, async () => {
|
|
173
|
+
const grouped = groupAddonFlows([{ ...flow, ...sample, rawPairs: [endpointPair(flow)] }], (_name, ns) => ns === 'monitoring')
|
|
174
|
+
await act(async () => root.render(<TrafficGraph flows={grouped} trafficSource="istio" addonMode="group" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
175
|
+
const groupEdge = container.querySelector<HTMLButtonElement>(`[data-edge="${edgeId}"]`)!
|
|
176
|
+
expect(groupEdge.textContent).toBe('HTTP · 889.8 B/s · TCP · 1.4 KB/s')
|
|
177
|
+
act(() => groupEdge.click())
|
|
178
|
+
expect(container.textContent).toContain('ProtocolHTTP + TCP')
|
|
179
|
+
expect(container.textContent).toContain('Data by protocolHTTP 5.8 KB sent · 254.8 KB receivedTCP 31.9 KB sent · 382.3 KB received')
|
|
180
|
+
expect(container.textContent).toContain('HTTP body bytes and TCP connection bytes')
|
|
181
|
+
expect(container.textContent).not.toMatch(/674\.9 KB|691,?072/)
|
|
182
|
+
for (const id of [endpointId, 'monitoring/prometheus']) {
|
|
183
|
+
act(() => container.querySelector<HTMLButtonElement>(`[data-node="${id}"]`)!.click())
|
|
184
|
+
expect(container.textContent).toContain('Data transferredHTTP 260.7 KBTCP 414.2 KB')
|
|
185
|
+
expect(container.textContent).toContain('HTTP 260.7 KB · TCP 414.2 KB')
|
|
186
|
+
expect(container.textContent).not.toMatch(/674\.9 KB|691,?072/)
|
|
187
|
+
}
|
|
188
|
+
act(() => container.querySelector<HTMLButtonElement>(`[data-node="${endpointId}"]`)!.click())
|
|
189
|
+
expect(container.textContent).toContain(`${direction} (1)`)
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
it('folds protocols across ordinary incoming and outgoing edges without changing labels', async () => {
|
|
194
|
+
const client = { name: 'client', namespace: 'demo', kind: 'Pod' }
|
|
195
|
+
const server = { name: 'server', namespace: 'demo', kind: 'Pod' }
|
|
196
|
+
const flows = [
|
|
197
|
+
{ ...incoming, ...sample, source: client, destination: server, port: 80 },
|
|
198
|
+
{ ...incoming, ...sample, source: server, destination: addon, port: 443 },
|
|
199
|
+
]
|
|
200
|
+
await act(async () => root.render(<TrafficGraph flows={flows} trafficSource="istio" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
201
|
+
act(() => container.querySelector<HTMLButtonElement>('[data-node="demo/server"]')!.click())
|
|
202
|
+
expect(container.textContent).toContain('Data transferredHTTP 521.4 KBTCP 828.4 KB')
|
|
203
|
+
expect(container.textContent?.match(/HTTP 260\.7 KB · TCP 414\.2 KB/g)).toHaveLength(2)
|
|
204
|
+
expect(container.textContent).toContain('Incoming (1)')
|
|
205
|
+
expect(container.textContent).toContain('Outgoing (1)')
|
|
206
|
+
expect(container.textContent).not.toMatch(/674\.9 KB|691,?072|1\.3 MB/)
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
it('keeps a released HTTP/gRPC aggregate scalar unlabelled in node details', async () => {
|
|
212
|
+
const legacy = { ...incoming, bytesByProtocol: undefined, protocol: 'http', l7Protocol: 'HTTP' }
|
|
213
|
+
await act(async () => root.render(<TrafficGraph flows={[legacy]} trafficSource="istio" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
214
|
+
act(() => container.querySelector<HTMLButtonElement>('[data-node="monitoring/prometheus"]')!.click())
|
|
215
|
+
expect(container.textContent).toContain('Data transferred300 B')
|
|
216
|
+
expect(container.textContent).not.toContain('HTTP 300 B')
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
it('retains the application protocol over multiple transports in edge details', async () => {
|
|
221
|
+
const dns = { ...outgoing, port: 53, protocol: 'udp', l7Protocol: 'DNS', bytesByProtocol: { udp: { bytesSent: 100, bytesRecv: 100 }, tcp: { bytesSent: 0, bytesRecv: 100 } } }
|
|
222
|
+
await act(async () => root.render(<TrafficGraph flows={[dns]} trafficSource="hubble" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
223
|
+
act(() => container.querySelector<HTMLButtonElement>('[data-edge]')!.click())
|
|
224
|
+
expect(container.textContent).toContain('ProtocolDNS / TCP + UDP')
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
describe('TrafficGraph edge labels for traffic measured only in bytes', () => {
|
|
228
|
+
const client = { name: 'curl', namespace: 'demo', kind: 'Pod' }
|
|
229
|
+
const server = { name: 'httpbin', namespace: 'demo', kind: 'Pod' }
|
|
230
|
+
const tcpOnly: AggregatedFlow = {
|
|
231
|
+
...incoming, source: server, destination: client, port: 0, protocol: 'tcp', connections: 0,
|
|
232
|
+
bytesSent: 29999, bytesRecv: 119999, bytesByProtocol: { tcp: { bytesSent: 29999, bytesRecv: 119999 } },
|
|
233
|
+
}
|
|
234
|
+
const http: AggregatedFlow = {
|
|
235
|
+
...incoming, source: client, destination: server, port: 0, protocol: 'http', l7Protocol: 'HTTP', connections: 2, requestRate: 1.9,
|
|
236
|
+
bytesSent: 38668, bytesRecv: 652404, bytesByProtocol: { http: { bytesSent: 5969, bytesRecv: 260965 }, tcp: { bytesSent: 32699, bytesRecv: 391439 } },
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
it('labels a TCP-only edge with its throughput and leaves an edge with a request rate as it was', async () => {
|
|
240
|
+
await act(async () => root.render(<TrafficGraph flows={[tcpOnly, http]} trafficSource="istio" onLayoutUnavailable={vi.fn()} windowSeconds={60} />))
|
|
241
|
+
expect(container.querySelector('[data-edge="demo/httpbin->demo/curl:0"]')!.textContent).toBe('TCP · 2.4 KB/s')
|
|
242
|
+
const httpLabel = container.querySelector('[data-edge="demo/curl->demo/httpbin:0"]')!.textContent!
|
|
243
|
+
expect(httpLabel).toBe('HTTP · 1.9/s')
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('claims no throughput for an older Radar whose byte sum can mix TCP and UDP', async () => {
|
|
247
|
+
const legacyTcp = { ...incoming, bytesByProtocol: undefined, bytesSent: 300, bytesRecv: 0 }
|
|
248
|
+
const legacyUdp = { ...incoming, protocol: 'udp', bytesByProtocol: undefined, bytesSent: 600, bytesRecv: 0 }
|
|
249
|
+
const grouped = groupAddonFlows([legacyTcp, legacyUdp].map(f => ({ ...f, rawPairs: [endpointPair(f)] })), (_name, ns) => ns === 'monitoring')
|
|
250
|
+
await act(async () => root.render(<TrafficGraph flows={[...grouped, { ...tcpOnly, bytesByProtocol: undefined }]} trafficSource="beyla" addonMode="group" onLayoutUnavailable={vi.fn()} windowSeconds={300} />))
|
|
251
|
+
expect(container.querySelector('[data-edge="addon-internet->addon-group"]')!.textContent).toBe('')
|
|
252
|
+
expect(container.querySelector('[data-edge="demo/httpbin->demo/curl:0"]')!.textContent).toBe('')
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('lists a protocol whose bytes were not measured without printing 0 B for it', async () => {
|
|
256
|
+
const unmeasured = { ...http, bytesSent: 300, bytesRecv: 0, bytesByProtocol: { http: { bytesSent: 0, bytesRecv: 0 }, tcp: { bytesSent: 300, bytesRecv: 0 } } }
|
|
257
|
+
await act(async () => root.render(<TrafficGraph flows={[unmeasured]} trafficSource="istio" onLayoutUnavailable={vi.fn()} windowSeconds={60} />))
|
|
258
|
+
act(() => container.querySelector<HTMLButtonElement>('[data-edge]')!.click())
|
|
259
|
+
expect(container.textContent).toContain('ProtocolHTTP + TCP')
|
|
260
|
+
expect(container.textContent).toContain('Data300 B')
|
|
261
|
+
expect(container.textContent).not.toMatch(/0 B sent|HTTP 0 B|body bytes/)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it('gives each transport its own throughput rather than their sum', async () => {
|
|
265
|
+
const both = { ...tcpOnly, bytesByProtocol: { tcp: { bytesSent: 29999, bytesRecv: 119999 }, udp: { bytesSent: 30, bytesRecv: 0 } } }
|
|
266
|
+
await act(async () => root.render(<TrafficGraph flows={[both]} trafficSource="beyla" onLayoutUnavailable={vi.fn()} windowSeconds={60} />))
|
|
267
|
+
expect(container.querySelector('[data-edge]')!.textContent).toBe('TCP · 2.4 KB/s · UDP · <1 B/s')
|
|
268
|
+
})
|
|
269
|
+
})
|