@skyhook-io/radar-app 1.22.1 → 1.23.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.
- package/package.json +8 -8
- package/src/App.tsx +131 -38
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/RadarApp.tsx +5 -0
- package/src/api/agentSandbox.ts +259 -0
- package/src/api/client.autoPromConnect.test.tsx +43 -0
- package/src/api/client.metricsRelayCheck.test.tsx +134 -0
- package/src/api/client.ts +128 -25
- package/src/api/cloudInstallDiscover.test.tsx +76 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/kagent.test.ts +82 -0
- package/src/api/kagent.ts +230 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +13 -0
- package/src/api/substrateWorkspace.test.ts +72 -0
- package/src/api/substrateWorkspace.ts +1394 -0
- package/src/api/vulnerabilities.ts +207 -9
- package/src/api/workloadSource.test.tsx +1172 -0
- package/src/api/workloadSource.ts +408 -0
- package/src/components/APIUnreachableBanner.test.tsx +19 -0
- package/src/components/APIUnreachableBanner.tsx +20 -0
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +127 -32
- package/src/components/ConnectionErrorView.test.tsx +63 -2
- package/src/components/ConnectionErrorView.tsx +88 -68
- package/src/components/SelfManagedStart.tsx +12 -2
- package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
- package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
- package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
- package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
- package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
- package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
- package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
- package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
- package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
- package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
- package/src/components/agentsandbox/data.ts +135 -0
- package/src/components/agentsandbox/host.test.ts +27 -0
- package/src/components/agentsandbox/host.tsx +85 -0
- package/src/components/agentsandbox/labels.test.ts +42 -0
- package/src/components/agentsandbox/labels.ts +146 -0
- package/src/components/agentsandbox/listFilters.ts +85 -0
- package/src/components/agentsandbox/lists.ts +52 -0
- package/src/components/agentsandbox/routes.ts +23 -0
- package/src/components/agentsandbox/shared.tsx +321 -0
- package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
- package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
- package/src/components/agentsandbox/workspace.tsx +258 -0
- package/src/components/agentsandbox/workspaceRoute.ts +18 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
- package/src/components/applications/ApplicationsView.tsx +156 -3
- package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
- package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
- package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
- package/src/components/audit/VulnerabilitiesView.tsx +639 -199
- package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
- package/src/components/cloudHints/CloudHintLink.tsx +29 -0
- package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
- package/src/components/cloudHints/cloudHints.test.ts +126 -0
- package/src/components/cloudHints/cloudHints.ts +131 -0
- package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
- package/src/components/cloudHints/cloudLinks.test.ts +52 -0
- package/src/components/cloudHints/cloudLinks.ts +31 -0
- package/src/components/cloudHints/hintStorage.ts +28 -0
- package/src/components/cnpg/CNPGView.tsx +4 -7
- package/src/components/diagnose/ActivityTurn.tsx +6 -4
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/AssessmentCard.tsx +1 -2
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
- package/src/components/diagnose/DiagnoseContext.tsx +7 -0
- package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
- package/src/components/diagnose/Home.test.tsx +6 -0
- package/src/components/diagnose/Home.tsx +10 -3
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
- package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
- package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
- package/src/components/diagnose/InvestigationView.tsx +120 -23
- package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
- package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
- package/src/components/diagnose/investigationState.ts +9 -0
- package/src/components/diagnose/parts.test.tsx +11 -3
- package/src/components/diagnose/toolCallLabel.ts +3 -0
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/home/ActivitySummary.tsx +3 -8
- package/src/components/home/ClusterHealthCard.tsx +91 -17
- package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +9 -29
- package/src/components/home/MCPSetupDialog.test.tsx +9 -0
- package/src/components/home/MCPSetupDialog.tsx +6 -2
- package/src/components/home/McpCloudLine.test.tsx +162 -0
- package/src/components/home/McpCloudLine.tsx +95 -0
- package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
- package/src/components/home/TopologyPreview.test.tsx +31 -30
- package/src/components/home/TopologyPreview.tsx +19 -28
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +7 -7
- package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
- package/src/components/issues/IssuesPane.render.test.tsx +36 -1
- package/src/components/issues/IssuesPane.tsx +181 -23
- package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
- package/src/components/issues/SinceLastVisitRow.tsx +71 -0
- package/src/components/issues/sinceLastVisit.test.ts +266 -0
- package/src/components/issues/sinceLastVisit.ts +439 -0
- package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
- package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
- package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
- package/src/components/kagent/KagentAgentSessions.tsx +124 -0
- package/src/components/kagent/KagentDetailPage.tsx +106 -0
- package/src/components/kagent/KagentLists.tsx +412 -0
- package/src/components/kagent/KagentOverview.tsx +234 -0
- package/src/components/kagent/KagentPages.tsx +690 -0
- package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
- package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
- package/src/components/kagent/KagentSidebar.test.tsx +112 -0
- package/src/components/kagent/KagentView.tsx +109 -0
- package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
- package/src/components/kagent/host.tsx +144 -0
- package/src/components/kagent/routes.ts +31 -0
- package/src/components/kagent/shared.tsx +336 -0
- package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
- package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
- package/src/components/kagent/workspace.fixtures.ts +108 -0
- package/src/components/kagent/workspaceRoute.ts +18 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
- package/src/components/resource/MetricsNotConnected.tsx +10 -7
- package/src/components/resource/PrometheusCharts.tsx +10 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
- package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
- package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
- package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +2 -6
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
- package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
- package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
- package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
- package/src/components/settings/SettingsDialog.tsx +84 -16
- package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
- package/src/components/settings/SubstrateSettings.test.tsx +131 -0
- package/src/components/settings/SubstrateSettings.tsx +544 -0
- package/src/components/settings/settings-state.test.ts +21 -3
- package/src/components/settings/settings-state.ts +13 -3
- package/src/components/share/ShareLinkButton.test.tsx +360 -0
- package/src/components/share/ShareLinkButton.tsx +391 -0
- package/src/components/share/openShareInCloud.test.ts +29 -0
- package/src/components/share/openShareInCloud.ts +10 -0
- package/src/components/share/shareLink.test.ts +129 -0
- package/src/components/share/shareLink.ts +175 -0
- package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
- package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
- package/src/components/substrate/SubstrateActorPage.tsx +384 -0
- package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
- package/src/components/substrate/SubstrateActors.tsx +612 -0
- package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
- package/src/components/substrate/SubstrateConnect.tsx +88 -0
- package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
- package/src/components/substrate/SubstrateOverview.tsx +575 -0
- package/src/components/substrate/SubstratePages.test.tsx +478 -0
- package/src/components/substrate/SubstratePool.test.tsx +462 -0
- package/src/components/substrate/SubstratePoolPage.tsx +95 -0
- package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
- package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
- package/src/components/substrate/SubstrateStateBar.tsx +63 -0
- package/src/components/substrate/SubstrateTemplates.tsx +376 -0
- package/src/components/substrate/SubstrateView.tsx +173 -0
- package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
- package/src/components/substrate/SubstrateWorkers.tsx +389 -0
- package/src/components/substrate/attention.ts +81 -0
- package/src/components/substrate/contextPin.tsx +69 -0
- package/src/components/substrate/host.tsx +83 -0
- package/src/components/substrate/kubectlTarget.test.tsx +77 -0
- package/src/components/substrate/readings.test.ts +484 -0
- package/src/components/substrate/readings.ts +997 -0
- package/src/components/substrate/routes.ts +103 -0
- package/src/components/substrate/shared.tsx +426 -0
- package/src/components/substrate/substrate.fixtures.ts +325 -0
- package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
- package/src/components/substrate/workspaceRoute.ts +23 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
- package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
- package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -5
- package/src/components/traffic/TrafficGraph.test.tsx +26 -0
- package/src/components/traffic/TrafficGraph.tsx +17 -14
- package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
- package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
- package/src/components/traffic/TrafficView.tsx +26 -56
- package/src/components/traffic/trafficFilters.test.ts +61 -1
- package/src/components/traffic/trafficFilters.ts +68 -8
- package/src/components/velero/VeleroOverview.tsx +2 -2
- package/src/components/velero/VeleroView.tsx +3 -6
- package/src/components/vulnerabilities/columns.tsx +132 -0
- package/src/components/vulnerabilities/filters.tsx +317 -0
- package/src/components/vulnerabilities/owner.test.ts +54 -0
- package/src/components/vulnerabilities/owner.tsx +163 -0
- package/src/components/vulnerabilities/parts.test.ts +126 -12
- package/src/components/vulnerabilities/parts.tsx +612 -52
- package/src/components/vulnerabilities/traffic.test.tsx +65 -0
- package/src/components/vulnerabilities/traffic.tsx +40 -0
- package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +119 -14
- package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
- package/src/components/workspace/layout.tsx +13 -7
- package/src/components/workspace/sidebar.test.ts +48 -0
- package/src/components/workspace/sidebar.ts +73 -3
- package/src/components/workspace/table.ts +2 -1
- package/src/context/ConnectionContext.tsx +24 -5
- package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
- package/src/context/ConnectionProvider.handover.test.tsx +94 -0
- package/src/context/DiagnoseCustomization.tsx +20 -2
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/hooks/useEventSource.test.tsx +275 -4
- package/src/hooks/useEventSource.ts +278 -51
- package/src/index.ts +1 -0
- package/src/integrations/resourceHost.ts +12 -6
- package/src/integrations/resourceHosts.test.tsx +27 -1
- package/src/integrations/resourceHosts.tsx +15 -7
- package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
- package/src/integrations/sidebarWorkspaces.ts +41 -0
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.ts +7 -1
- package/src/integrations/workspaceScreens.tsx +6 -0
- package/src/utils/navigation.test.ts +1 -6
- package/src/utils/navigation.ts +9 -44
- package/src/utils/network-policy-navigation.test.ts +21 -36
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { Fragment, useMemo, useState, type ReactNode } from 'react'
|
|
2
|
+
import { useSearchParams } from 'react-router-dom'
|
|
3
|
+
import { clsx } from 'clsx'
|
|
4
|
+
import { Badge, Collapse, CollapseChevron, Input, PaneLoader, SelectMenu, Tooltip, formatDuration } from '@skyhook-io/k8s-ui'
|
|
5
|
+
import {
|
|
6
|
+
useSubstrateWorkers,
|
|
7
|
+
type SubstrateAttention,
|
|
8
|
+
type SubstrateCoverage,
|
|
9
|
+
type SubstrateResources,
|
|
10
|
+
type SubstrateStatus,
|
|
11
|
+
type SubstratePoolRow,
|
|
12
|
+
type SubstrateWorkerRow,
|
|
13
|
+
type SubstrateWorkspace,
|
|
14
|
+
} from '../../api/substrateWorkspace'
|
|
15
|
+
import { Notice, RefreshFailedNotice, ScreenBody, Segments, Sub, type TableColumn } from '../workspace/layout'
|
|
16
|
+
import { ROW_HOVER, TABLE_HEAD, TABLE_WRAP, TBODY, TD, TH } from '../workspace/table'
|
|
17
|
+
import { useConnection } from '../../context/ConnectionContext'
|
|
18
|
+
import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
|
|
19
|
+
import type { OpenSubject } from './SubstrateAttentionList'
|
|
20
|
+
import { SubstrateConnectNotice, SubstrateTierBanner } from './SubstrateConnect'
|
|
21
|
+
import { bytesText, compactActorLabel, coverageInPart, coverageReason, cpuText, poolReading, workerPodText } from './readings'
|
|
22
|
+
import { substrateActorsPath, substratePoolPath } from './routes'
|
|
23
|
+
import { ActorStateBadge, Name, SUBSTRATE_WIDE, SubstrateCoverageNotice, SubstrateHeader, SubstrateSourceLine, Term, Unread, WholeNames, WorkerStateChip } from './shared'
|
|
24
|
+
import { useMediaQuery } from '../../hooks/useMediaQuery'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
/** What a worker's CPU and memory figures are, from Substrate's own fields. */
|
|
29
|
+
export const RESERVED_MEANING = 'Reserved: what the actors on it request, with their runtime’s overhead, of the capacity the worker reports to Substrate. Not measured usage.'
|
|
30
|
+
|
|
31
|
+
/** A worker's actors lost to its restart, while Substrate has not yet reconciled it: said beside the chip, so the chip stays one line. */
|
|
32
|
+
export function lostText(w: Pick<SubstrateWorkerRow, 'workerState'>): string | undefined {
|
|
33
|
+
const lost = w.workerState?.kind === 'reconciling' ? w.workerState.lost : undefined
|
|
34
|
+
return lost ? `${lost} ${lost === 1 ? 'actor' : 'actors'} lost` : undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function Reserved({ children }: { children: ReactNode }) {
|
|
38
|
+
return (
|
|
39
|
+
<Tooltip content={RESERVED_MEANING}>
|
|
40
|
+
<span tabIndex={0} className="cursor-help underline decoration-dotted underline-offset-2">{children}</span>
|
|
41
|
+
</Tooltip>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function usage(allocated: SubstrateResources | undefined, capacity: SubstrateResources | undefined, dim: keyof SubstrateResources, fmt: (n: number) => string) {
|
|
46
|
+
if (!capacity) return <Unread>unknown</Unread>
|
|
47
|
+
const used = allocated?.[dim] ?? 0
|
|
48
|
+
if (dim === 'actors' && capacity.actors === 0) return <Tooltip content="Substrate counts an unreported actor capacity as zero: this worker takes no actors."><span className="whitespace-nowrap">{used} of 0</span></Tooltip>
|
|
49
|
+
return <span className="whitespace-nowrap">{fmt(used)} of {fmt(capacity[dim])}</span>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Wide: every column. Narrow: CPU and memory under the slots, the node under the Pod. */
|
|
53
|
+
export function workerColumns(onOpenSubject: OpenSubject, wide: boolean): TableColumn<SubstrateWorkerRow>[] {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
header: 'Worker Pod',
|
|
57
|
+
width: wide ? '20%' : '25%',
|
|
58
|
+
cell: (w) => (
|
|
59
|
+
<>
|
|
60
|
+
<Name name={w.pod} />
|
|
61
|
+
{!wide && w.node && <Sub><WholeNames text={w.node} /></Sub>}
|
|
62
|
+
<button type="button" onClick={(e) => { e.stopPropagation(); onOpenSubject({ kind: 'Pod', namespace: w.namespace, name: w.pod }) }} className="text-xs text-accent-text hover:underline">Open Pod →</button>
|
|
63
|
+
</>
|
|
64
|
+
),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
header: 'State',
|
|
68
|
+
width: wide ? '20%' : '25%',
|
|
69
|
+
cell: (w) => (
|
|
70
|
+
<>
|
|
71
|
+
<span className="inline-flex flex-wrap items-center gap-x-1.5">
|
|
72
|
+
<WorkerStateChip w={w} />
|
|
73
|
+
{w.heldForSeconds !== undefined && <span className="whitespace-nowrap text-xs text-theme-text-tertiary">for at least {formatDuration(w.heldForSeconds * 1000)}</span>}
|
|
74
|
+
</span>
|
|
75
|
+
<Sub>
|
|
76
|
+
{[lostText(w), workerPodText(w)].filter(Boolean).join(' · ')}
|
|
77
|
+
</Sub>
|
|
78
|
+
</>
|
|
79
|
+
),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
header: <Term term="slot">Actor slots</Term>,
|
|
83
|
+
width: wide ? '10%' : '28%',
|
|
84
|
+
cell: (w) => (
|
|
85
|
+
<>
|
|
86
|
+
<span className="inline-flex flex-wrap items-center gap-1.5">
|
|
87
|
+
{usage(w.allocated, w.capacity, 'actors', String)}
|
|
88
|
+
{w.state === 'active' && !w.hasFreeSlot && (
|
|
89
|
+
<Tooltip content="No actor slot left: Substrate places no new actor on this worker until one suspends. The pool’s own badge says whether any of its workers has room."><span><Badge severity="neutral" size="sm">Full</Badge></span></Tooltip>
|
|
90
|
+
)}
|
|
91
|
+
</span>
|
|
92
|
+
{!wide && <Sub>{usage(w.allocated, w.capacity, 'cpuMillicores', cpuText)} CPU · {usage(w.allocated, w.capacity, 'memoryBytes', bytesText)} <Reserved>reserved</Reserved></Sub>}
|
|
93
|
+
</>
|
|
94
|
+
),
|
|
95
|
+
},
|
|
96
|
+
...(wide
|
|
97
|
+
? [
|
|
98
|
+
{ header: <Reserved>CPU reserved</Reserved>, width: '10%', cell: (w: SubstrateWorkerRow) => usage(w.allocated, w.capacity, 'cpuMillicores', cpuText) },
|
|
99
|
+
{ header: <Reserved>Memory reserved</Reserved>, width: '12%', cell: (w: SubstrateWorkerRow) => usage(w.allocated, w.capacity, 'memoryBytes', bytesText) },
|
|
100
|
+
{
|
|
101
|
+
header: 'Node',
|
|
102
|
+
width: '17%',
|
|
103
|
+
// A hostname truncates whole, with the name on hover; it never breaks inside a label.
|
|
104
|
+
cell: (w: SubstrateWorkerRow) => (w.node ? <Tooltip content={w.node} wrapperClassName="min-w-0 max-w-full"><span className="block truncate whitespace-nowrap font-mono text-[12px]">{w.node}</span></Tooltip> : <Unread>unknown</Unread>),
|
|
105
|
+
},
|
|
106
|
+
]
|
|
107
|
+
: []),
|
|
108
|
+
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const STATE_RANK: Record<SubstrateWorkerRow['state'], number> = { unavailable: 0, draining: 1, unknown: 2, active: 3 }
|
|
113
|
+
|
|
114
|
+
// A worker whose actors lost their sandboxes ranks with the unavailable ones: its actors are as affected.
|
|
115
|
+
const lostSandboxes = (w: SubstrateWorkerRow) => (w.workerState?.lost ?? 0) > 0
|
|
116
|
+
const ATTENTION_RANK = { critical: 0, alert: 1, warning: 2, info: 3 }
|
|
117
|
+
const rank = (w: SubstrateWorkerRow) =>
|
|
118
|
+
w.attentionSeverity ? ATTENTION_RANK[w.attentionSeverity] : lostSandboxes(w) ? 0 : 4
|
|
119
|
+
|
|
120
|
+
/** Within a pool: the worst state first, then full workers, then by name. */
|
|
121
|
+
export function sortWorkers(workers: SubstrateWorkerRow[]): SubstrateWorkerRow[] {
|
|
122
|
+
return [...workers].sort(
|
|
123
|
+
(a, b) =>
|
|
124
|
+
rank(a) - rank(b) ||
|
|
125
|
+
STATE_RANK[a.state] - STATE_RANK[b.state] ||
|
|
126
|
+
Number(a.state === 'active' && a.hasFreeSlot) - Number(b.state === 'active' && b.hasFreeSlot) ||
|
|
127
|
+
a.pod.localeCompare(b.pod),
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type StateFilter = 'all' | 'attention' | SubstrateWorkerRow['state']
|
|
132
|
+
|
|
133
|
+
/** Substrate's workers by pool: state, slots, and the actors on each. */
|
|
134
|
+
export function SubstrateWorkersScreen({ workspace, status, onOpenSubject }: { workspace?: SubstrateWorkspace; status?: SubstrateStatus; onOpenSubject: OpenSubject }) {
|
|
135
|
+
const [params, setParams] = useSearchParams()
|
|
136
|
+
const navigate = useWorkspaceNavigate()
|
|
137
|
+
const { connection } = useConnection()
|
|
138
|
+
const [search, setSearch] = useState('')
|
|
139
|
+
const tier = workspace?.apiTier
|
|
140
|
+
const connected = tier?.state === 'connected'
|
|
141
|
+
const query = useSubstrateWorkers(undefined, connected)
|
|
142
|
+
const data = query.data
|
|
143
|
+
const pool = params.get('pool') ?? ''
|
|
144
|
+
const stateFilter = (params.get('state') as StateFilter | null) ?? 'all'
|
|
145
|
+
const set = (k: string, v: string) => {
|
|
146
|
+
const p = new URLSearchParams(params)
|
|
147
|
+
if (v && v !== 'all') p.set(k, v)
|
|
148
|
+
else p.delete(k)
|
|
149
|
+
setParams(p, { replace: true })
|
|
150
|
+
}
|
|
151
|
+
const registeredPools = useMemo(() => new Set((data?.workers ?? []).map((w) => `${w.namespace}/${w.pool}`)), [data])
|
|
152
|
+
const emptyPools = data?.coverage.workers.state === 'full'
|
|
153
|
+
? (workspace?.pools ?? []).filter((p) => p.kubernetes && !registeredPools.has(`${p.namespace}/${p.name}`))
|
|
154
|
+
: []
|
|
155
|
+
const pools = [...new Set([...registeredPools, ...emptyPools.map((p) => `${p.namespace}/${p.name}`)])].sort()
|
|
156
|
+
const scoped = (data?.workers ?? []).filter((w) => (!pool || `${w.namespace}/${w.pool}` === pool) && w.pod.toLowerCase().includes(search.trim().toLowerCase()))
|
|
157
|
+
const needsAttention = (w: SubstrateWorkerRow) => w.attentionSeverity !== undefined && w.attentionSeverity !== 'info'
|
|
158
|
+
const shown = scoped.filter((w) => stateFilter === 'all' || (stateFilter === 'attention' ? needsAttention(w) : w.state === stateFilter))
|
|
159
|
+
const partial = coverageInPart(data?.coverage.workers)
|
|
160
|
+
const count = (n: number) => partial ? n > 0 ? `≥${n}` : undefined : n
|
|
161
|
+
const attentionPartial = partial || coverageInPart(data?.coverage.actors)
|
|
162
|
+
const attentionCount = scoped.filter(needsAttention).length
|
|
163
|
+
const poolFindings = workspace?.needsAttention.filter((a) => a.subject.kind === 'WorkerPool')
|
|
164
|
+
return (
|
|
165
|
+
<div className="flex min-h-0 flex-1 flex-col">
|
|
166
|
+
<SubstrateHeader title="Workers" intro="Cluster-wide" />
|
|
167
|
+
<ScreenBody>
|
|
168
|
+
{!connected && tier ? (
|
|
169
|
+
<>
|
|
170
|
+
<SubstrateTierBanner tier={tier} />
|
|
171
|
+
<SubstrateConnectNotice status={status} tier={tier} />
|
|
172
|
+
</>
|
|
173
|
+
) : query.isLoading ? (
|
|
174
|
+
<PaneLoader label="Loading workers…" />
|
|
175
|
+
) : !data ? (
|
|
176
|
+
<Notice>Radar couldn’t read the workers: {query.error instanceof Error ? query.error.message : 'unknown error'}.</Notice>
|
|
177
|
+
) : (
|
|
178
|
+
<>
|
|
179
|
+
<RefreshFailedNotice queries={[query]} />
|
|
180
|
+
<SubstrateCoverageNotice coverage={data.coverage} kinds={['workers', 'actors']} />
|
|
181
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
182
|
+
<Segments
|
|
183
|
+
label="Worker filter"
|
|
184
|
+
value={stateFilter}
|
|
185
|
+
onChange={(v) => set('state', v)}
|
|
186
|
+
options={[
|
|
187
|
+
{ id: 'all', label: 'All', count: count(scoped.length) },
|
|
188
|
+
{ id: 'attention', label: 'Needs attention', count: attentionPartial ? attentionCount > 0 ? `≥${attentionCount}` : undefined : attentionCount },
|
|
189
|
+
{ id: 'active', label: 'Active', count: count(scoped.filter((w) => w.state === 'active').length) },
|
|
190
|
+
{ id: 'draining', label: 'Draining', count: count(scoped.filter((w) => w.state === 'draining').length) },
|
|
191
|
+
{ id: 'unavailable', label: 'Unavailable', count: count(scoped.filter((w) => w.state === 'unavailable').length) },
|
|
192
|
+
]}
|
|
193
|
+
/>
|
|
194
|
+
<Input aria-label="Search worker names" placeholder="Search workers…" value={search} onChange={(e) => setSearch(e.target.value)} className="h-8 max-w-52 rounded-md border border-theme-border bg-theme-elevated px-3" />
|
|
195
|
+
<SelectMenu ariaLabel="Pool" value={pool} options={[{ value: '', label: 'Every pool' }, ...pools.map((p) => ({ value: p, label: p.replace('/', ' / ') }))]} onChange={(v) => set('pool', v)} className="min-w-[12rem]" />
|
|
196
|
+
</div>
|
|
197
|
+
<WorkersTable data={{ workers: shown, coverage: data.coverage }} pools={workspace?.pools} poolFindings={poolFindings} onOpenSubject={onOpenSubject} grouped />
|
|
198
|
+
{emptyPools.length > 0 && <div className="flex flex-wrap gap-x-3 gap-y-1 text-xs text-theme-text-secondary">
|
|
199
|
+
<span>Pools with no registered workers</span>
|
|
200
|
+
{emptyPools.map((p) => <button key={`${p.namespace}/${p.name}`} type="button" onClick={() => navigate(substratePoolPath(p, connection.context || undefined))} className="font-mono text-accent-text hover:underline">{p.namespace}/{p.name} →</button>)}
|
|
201
|
+
</div>}
|
|
202
|
+
</>
|
|
203
|
+
)}
|
|
204
|
+
{tier && <SubstrateSourceLine tier={tier} status={status} />}
|
|
205
|
+
</ScreenBody>
|
|
206
|
+
</div>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The worker's actors, under its row: each opens in the actor drawer. */
|
|
211
|
+
function WorkerActors({ w, onOpenSubject, partial }: { w: SubstrateWorkerRow; onOpenSubject: OpenSubject; partial: boolean }) {
|
|
212
|
+
const navigate = useWorkspaceNavigate()
|
|
213
|
+
if (!w.actors) return <p className="text-xs text-theme-text-tertiary">Actors were not read, so which actors are on this worker is unknown.</p>
|
|
214
|
+
if (w.actors.length === 0) return <p className="text-xs text-theme-text-tertiary">{partial ? 'No assignments found in the actors Radar could read.' : 'No actor is on this worker.'}</p>
|
|
215
|
+
return (
|
|
216
|
+
<div className="space-y-1.5">
|
|
217
|
+
<ul className="grid grid-cols-[repeat(auto-fill,minmax(22rem,1fr))] gap-x-4 gap-y-1">
|
|
218
|
+
{w.actors.map((a) => (
|
|
219
|
+
<li key={`${a.atespace}/${a.name}`} className="flex min-w-0 items-center gap-2 text-xs">
|
|
220
|
+
<span className="shrink-0 whitespace-nowrap"><ActorStateBadge state={a.state} impact={a.workerImpact} updateTime={a.updateTime} /></span>
|
|
221
|
+
<Tooltip content={a.name} wrapperClassName="min-w-0"><button type="button" onClick={() => onOpenSubject({ kind: 'Actor', atespace: a.atespace, name: a.name })} className="min-w-0 max-w-full truncate font-mono text-accent-text hover:underline">{compactActorLabel(a).name}</button></Tooltip>
|
|
222
|
+
<span className="min-w-0 truncate text-theme-text-tertiary">{[a.atespace, compactActorLabel(a).agent].filter(Boolean).join(' · ')}</span>
|
|
223
|
+
</li>
|
|
224
|
+
))}
|
|
225
|
+
</ul>
|
|
226
|
+
<button type="button" onClick={() => navigate(substrateActorsPath({ worker: w.name, pool: `${w.namespace}/${w.pool}` }))} className="text-xs text-accent-text hover:underline">In the Actors list →</button>
|
|
227
|
+
</div>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function WorkerRows({ workers, columns, onOpenSubject, actorsPartial }: { workers: SubstrateWorkerRow[]; columns: TableColumn<SubstrateWorkerRow>[]; onOpenSubject: OpenSubject; actorsPartial: boolean }) {
|
|
232
|
+
const [open, setOpen] = useState<Set<string>>(() => new Set())
|
|
233
|
+
const toggle = (name: string) =>
|
|
234
|
+
setOpen((prev) => {
|
|
235
|
+
const next = new Set(prev)
|
|
236
|
+
if (next.has(name)) next.delete(name)
|
|
237
|
+
else next.add(name)
|
|
238
|
+
return next
|
|
239
|
+
})
|
|
240
|
+
return (
|
|
241
|
+
<>
|
|
242
|
+
{workers.map((w) => {
|
|
243
|
+
const isOpen = open.has(w.name)
|
|
244
|
+
const panel = `worker-actors-${w.name}`
|
|
245
|
+
const full = w.state === 'active' && !w.hasFreeSlot
|
|
246
|
+
return (
|
|
247
|
+
<Fragment key={w.name}>
|
|
248
|
+
<tr className={clsx(ROW_HOVER, 'cursor-pointer', full && 'bg-theme-elevated/40')} onClick={() => toggle(w.name)}>
|
|
249
|
+
{columns.map((c, i) => <td key={i} className={clsx(TD, c.className)}>{c.cell(w)}</td>)}
|
|
250
|
+
<td className={TD}>
|
|
251
|
+
<button
|
|
252
|
+
type="button"
|
|
253
|
+
aria-expanded={isOpen}
|
|
254
|
+
aria-controls={panel}
|
|
255
|
+
aria-label={`${isOpen ? 'Hide' : 'Show'} assigned actors for ${w.pod}`}
|
|
256
|
+
onClick={(e) => { e.stopPropagation(); toggle(w.name) }}
|
|
257
|
+
className="inline-flex items-center gap-1 text-left text-xs text-accent-text hover:underline"
|
|
258
|
+
>
|
|
259
|
+
<CollapseChevron open={isOpen} />
|
|
260
|
+
{isOpen ? 'Hide assigned actors' : w.actors && (!actorsPartial || w.actors.length > 0) ? `Show ${actorsPartial ? '≥' : ''}${w.actors.length} assigned actors` : 'View assigned actors'}
|
|
261
|
+
</button>
|
|
262
|
+
</td>
|
|
263
|
+
</tr>
|
|
264
|
+
<tr>
|
|
265
|
+
<td colSpan={columns.length + 1} className="p-0">
|
|
266
|
+
<Collapse open={isOpen} id={panel} unmountOnExit>
|
|
267
|
+
<div className="border-t-subtle bg-theme-base/40 py-2.5 pl-11 pr-4">
|
|
268
|
+
<WorkerActors w={w} onOpenSubject={onOpenSubject} partial={actorsPartial} />
|
|
269
|
+
</div>
|
|
270
|
+
</Collapse>
|
|
271
|
+
</td>
|
|
272
|
+
</tr>
|
|
273
|
+
</Fragment>
|
|
274
|
+
)
|
|
275
|
+
})}
|
|
276
|
+
</>
|
|
277
|
+
)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Workers as a table; `grouped` puts them under a header per pool with its
|
|
282
|
+
* slots used of total and its reading. Each row expands to the actors on it;
|
|
283
|
+
* full workers carry a badge and a tint.
|
|
284
|
+
*/
|
|
285
|
+
export function WorkersTable({
|
|
286
|
+
data,
|
|
287
|
+
pools,
|
|
288
|
+
poolFindings,
|
|
289
|
+
emptyMessage,
|
|
290
|
+
onOpenSubject,
|
|
291
|
+
grouped,
|
|
292
|
+
title,
|
|
293
|
+
}: {
|
|
294
|
+
data: { workers: SubstrateWorkerRow[]; coverage: { workers: SubstrateCoverage; actors?: SubstrateCoverage } }
|
|
295
|
+
pools?: SubstratePoolRow[]
|
|
296
|
+
poolFindings?: SubstrateAttention[]
|
|
297
|
+
emptyMessage?: ReactNode
|
|
298
|
+
onOpenSubject: OpenSubject
|
|
299
|
+
grouped?: boolean
|
|
300
|
+
title?: string
|
|
301
|
+
}) {
|
|
302
|
+
const navigate = useWorkspaceNavigate()
|
|
303
|
+
const { connection } = useConnection()
|
|
304
|
+
const wide = useMediaQuery(SUBSTRATE_WIDE)
|
|
305
|
+
const columns = workerColumns(onOpenSubject, wide)
|
|
306
|
+
const groups = useMemo(() => {
|
|
307
|
+
const by = new Map<string, SubstrateWorkerRow[]>()
|
|
308
|
+
for (const w of data.workers) {
|
|
309
|
+
const k = grouped ? `${w.namespace}/${w.pool}` : ''
|
|
310
|
+
by.set(k, [...(by.get(k) ?? []), w])
|
|
311
|
+
}
|
|
312
|
+
return [...by].map(([key, ws]) => ({ key, workers: sortWorkers(ws) }))
|
|
313
|
+
.sort((a, b) => rank(a.workers[0]) - rank(b.workers[0]) || a.key.localeCompare(b.key))
|
|
314
|
+
}, [data.workers, grouped])
|
|
315
|
+
const empty = coverageInPart(data.coverage.workers) ? `No workers: ${coverageReason(data.coverage.workers, 'workers')}.` : emptyMessage ?? 'No workers match.'
|
|
316
|
+
return (
|
|
317
|
+
<section>
|
|
318
|
+
{title && <h2 className="mb-2 text-sm font-semibold text-theme-text-primary">{title}</h2>}
|
|
319
|
+
<div className="overflow-hidden rounded-xl border border-theme-border bg-theme-surface shadow-theme-sm">
|
|
320
|
+
{data.workers.length === 0 ? (
|
|
321
|
+
<div className="px-4 py-5 text-sm text-theme-text-tertiary">{empty}</div>
|
|
322
|
+
) : (
|
|
323
|
+
<div className={TABLE_WRAP}>
|
|
324
|
+
<table className="w-full table-fixed" style={{ minWidth: wide ? 900 : 700 }}>
|
|
325
|
+
<colgroup>
|
|
326
|
+
{columns.map((c, i) => <col key={i} style={c.width ? { width: c.width } : undefined} />)}
|
|
327
|
+
<col style={{ width: '10rem' }} />
|
|
328
|
+
</colgroup>
|
|
329
|
+
<thead className={TABLE_HEAD}>
|
|
330
|
+
<tr>
|
|
331
|
+
{columns.map((c, i) => <th key={i} className={TH}>{c.header}</th>)}
|
|
332
|
+
<th className={TH}>Assignments</th>
|
|
333
|
+
</tr>
|
|
334
|
+
</thead>
|
|
335
|
+
{groups.map((g) => {
|
|
336
|
+
const row = pools?.find((p) => `${p.namespace}/${p.name}` === g.key)
|
|
337
|
+
const slots = row?.placement?.slots
|
|
338
|
+
const [ns, name] = g.key.split('/')
|
|
339
|
+
return (
|
|
340
|
+
<tbody key={g.key} className={TBODY}>
|
|
341
|
+
{grouped && (
|
|
342
|
+
<tr className="bg-theme-base/60">
|
|
343
|
+
<td colSpan={columns.length + 1} className="px-3 py-2 text-xs">
|
|
344
|
+
<span className="inline-flex flex-wrap items-center gap-x-2 gap-y-1">
|
|
345
|
+
{row?.kubernetes
|
|
346
|
+
? <button type="button" className="font-mono text-sm font-medium text-accent-text hover:underline" onClick={() => navigate(substratePoolPath(row, connection.context || undefined))}>{name} →</button>
|
|
347
|
+
: <span className="font-mono text-sm font-medium text-theme-text-primary">{name}</span>}
|
|
348
|
+
<span className="text-theme-text-tertiary">
|
|
349
|
+
{ns} · {poolWorkersText(row, g.workers)}
|
|
350
|
+
{slots ? ` · ${row?.placement?.complete === false ? slots.used > 0 ? `at least ${slots.used} actor slots used on active workers` : 'actor slot usage unknown' : `${slots.used} of ${slots.total} actor slots used on active workers`}` : ''}
|
|
351
|
+
</span>
|
|
352
|
+
{row && <PoolReadingBadge p={row} finding={poolFindings?.find((f) => f.subject.namespace === ns && f.subject.name === name)} />}
|
|
353
|
+
</span>
|
|
354
|
+
</td>
|
|
355
|
+
</tr>
|
|
356
|
+
)}
|
|
357
|
+
<WorkerRows workers={g.workers} columns={columns} onOpenSubject={onOpenSubject} actorsPartial={coverageInPart(data.coverage.actors)} />
|
|
358
|
+
</tbody>
|
|
359
|
+
)
|
|
360
|
+
})}
|
|
361
|
+
</table>
|
|
362
|
+
</div>
|
|
363
|
+
)}
|
|
364
|
+
</div>
|
|
365
|
+
</section>
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* A pool's workers by name: registered with Substrate, of those active, and
|
|
371
|
+
* the desired count Kubernetes holds. From the pool's own totals, not the
|
|
372
|
+
* rows a state filter left; a partial read is a lower bound.
|
|
373
|
+
*/
|
|
374
|
+
export function poolWorkersText(row: Pick<SubstratePoolRow, 'placement' | 'kubernetes'> | undefined, shown: Pick<SubstrateWorkerRow, 'state'>[]): string {
|
|
375
|
+
const counts = row?.placement?.workers
|
|
376
|
+
const registered = counts?.total ?? shown.length
|
|
377
|
+
const active = counts?.active ?? shown.filter((w) => w.state === 'active').length
|
|
378
|
+
const partial = row?.placement?.complete === false
|
|
379
|
+
const atLeast = partial ? 'at least ' : ''
|
|
380
|
+
const desired = row?.kubernetes?.desired
|
|
381
|
+
const reg = partial && registered === 0 ? 'registrations unknown'
|
|
382
|
+
: desired !== undefined ? `${atLeast}${registered} of ${desired} desired workers registered` : `${atLeast}${registered} ${registered === 1 ? 'worker' : 'workers'} registered`
|
|
383
|
+
return `${reg}, ${partial && active === 0 ? 'active worker count unknown' : `${atLeast}${active} active`}`
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function PoolReadingBadge({ p, finding }: { p: SubstratePoolRow; finding?: SubstrateAttention }) {
|
|
387
|
+
const r = poolReading(p, finding)
|
|
388
|
+
return <Tooltip content={r.meaning}><span><Badge severity={r.severity} size="sm">{r.label}</Badge></span></Tooltip>
|
|
389
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { SubstrateAttention, SubstrateWorkspace } from '../../api/substrateWorkspace'
|
|
2
|
+
import { INCOMPLETE_COVERAGE_STATES } from '../workspace/coverage'
|
|
3
|
+
import { API_AREAS, attentionArea, coverageInPart, type AttentionArea } from './readings'
|
|
4
|
+
|
|
5
|
+
export interface SubstrateAttentionCount {
|
|
6
|
+
/** `null` when nothing was found but the read was partial, so zero would claim too much. */
|
|
7
|
+
count: number | null
|
|
8
|
+
lowerBound: boolean
|
|
9
|
+
title: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const AREA_NOUN: Record<AttentionArea, string> = {
|
|
13
|
+
actors: 'actors',
|
|
14
|
+
templates: 'templates',
|
|
15
|
+
workers: 'workers',
|
|
16
|
+
pools: 'pools',
|
|
17
|
+
nodes: 'nodes',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Whether what an area's rules read was read in full. */
|
|
21
|
+
function areaRead(data: SubstrateWorkspace, area: AttentionArea): { read: boolean; why?: string } {
|
|
22
|
+
const connected = data.apiTier.state === 'connected'
|
|
23
|
+
if (area === 'pools' || area === 'nodes') {
|
|
24
|
+
// Pool rows join Kubernetes' WorkerPools with Substrate's workers.
|
|
25
|
+
if (INCOMPLETE_COVERAGE_STATES.has(data.coverage.pools.state)) return { read: false, why: 'some WorkerPools could not be read' }
|
|
26
|
+
if (!connected || coverageInPart(data.coverage?.workers)) return { read: false, why: 'Substrate’s workers were not read' }
|
|
27
|
+
return { read: true }
|
|
28
|
+
}
|
|
29
|
+
if (!connected) return { read: false, why: 'Radar is not connected to Substrate’s API' }
|
|
30
|
+
const cov = data.coverage
|
|
31
|
+
const parts = area === 'actors' ? [cov.actors, cov.workers] : area === 'templates' ? [cov.templates, cov.actors, cov.workers] : [cov.workers, cov.actors]
|
|
32
|
+
if (area === 'templates' && (INCOMPLETE_COVERAGE_STATES.has(cov.pools.state) || data.summary.templates?.noMatchingPool === undefined)) return { read: false, why: 'some WorkerPools could not be read' }
|
|
33
|
+
if (parts.some((c) => coverageInPart(c))) return { read: false, why: `some ${AREA_NOUN[area]} could not be read` }
|
|
34
|
+
return { read: true }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function countOf(count: number | undefined, read: { read: boolean; why?: string }, what: (n: number) => string): SubstrateAttentionCount {
|
|
38
|
+
if (!read.read && !count) {
|
|
39
|
+
return { count: null, lowerBound: true, title: `Unknown: ${read.why}, so nothing found does not mean nothing needs attention.` }
|
|
40
|
+
}
|
|
41
|
+
if (count === undefined) return { count: null, lowerBound: true, title: 'The attention count was not reported.' }
|
|
42
|
+
const note = read.read ? '' : ` ${read.why ? `${read.why[0].toUpperCase()}${read.why.slice(1)}` : 'Some was not read'}, so there may be more.`
|
|
43
|
+
return { count, lowerBound: !read.read, title: `${read.read ? '' : 'At least '}${what(count)}.${note}` }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Rows that need a look: an info row is expected and still within its budget. */
|
|
47
|
+
function needing(data: SubstrateWorkspace): SubstrateAttention[] {
|
|
48
|
+
return data.needsAttention.filter((a) => a.severity !== 'info')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The integration row's sidebar badge: how many attention items Needs
|
|
53
|
+
* attention lists. Rules that need Substrate's API are not evaluated while it
|
|
54
|
+
* is not read, so then the count is a lower bound and its zero unknown.
|
|
55
|
+
*/
|
|
56
|
+
export function substrateAttentionCount(data: SubstrateWorkspace): SubstrateAttentionCount {
|
|
57
|
+
const areas: AttentionArea[] = ['actors', 'templates', 'workers', 'pools']
|
|
58
|
+
const unread = areas.map((a) => areaRead(data, a)).find((r) => !r.read)
|
|
59
|
+
return countOf(needing(data).length, unread ?? { read: true }, (n) => `${n} ${n === 1 ? 'finding needs' : 'findings need'} attention in Overview`)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const subjectKey = (s: SubstrateAttention['subject']) => `${s.kind}/${s.namespace ?? s.atespace ?? ''}/${s.name ?? s.filter?.template ?? ''}`
|
|
63
|
+
|
|
64
|
+
/** Counts for the same predicates as each screen’s Needs attention filter. */
|
|
65
|
+
export function substrateScreenCounts(data: SubstrateWorkspace): Record<AttentionArea, SubstrateAttentionCount> {
|
|
66
|
+
const rows = needing(data)
|
|
67
|
+
const distinct = (area: AttentionArea) => new Set(rows.filter((a) => attentionArea(a) === area).map((a) => area === 'workers' ? a.id : subjectKey(a.subject))).size
|
|
68
|
+
const objects = (one: string, many: string) => (n: number) => `${n} ${n === 1 ? `${one} needs` : `${many} need`} attention`
|
|
69
|
+
return {
|
|
70
|
+
actors: countOf(data.summary.actors?.attentionCount, areaRead(data, 'actors'), objects('actor', 'actors')),
|
|
71
|
+
templates: countOf(data.summary.templates?.attentionCount, areaRead(data, 'templates'), objects('template', 'templates')),
|
|
72
|
+
workers: countOf(distinct('workers'), areaRead(data, 'workers'), objects('worker', 'workers')),
|
|
73
|
+
pools: countOf(distinct('pools'), areaRead(data, 'pools'), objects('pool', 'pools')),
|
|
74
|
+
nodes: countOf(distinct('nodes'), areaRead(data, 'nodes'), objects('node', 'nodes')),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Whether the Needs attention list left out rules because their inputs were not read. */
|
|
79
|
+
export function attentionInPart(data: SubstrateWorkspace): boolean {
|
|
80
|
+
return [...API_AREAS, 'pools' as const].some((a) => !areaRead(data, a).read)
|
|
81
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
import { useLocation, useSearchParams } from 'react-router-dom'
|
|
3
|
+
import { Unplug } from 'lucide-react'
|
|
4
|
+
import { useContexts } from '../../api/client'
|
|
5
|
+
import { useConnection } from '../../context/ConnectionContext'
|
|
6
|
+
import { useContextSwitchFlow } from '../useContextSwitchFlow'
|
|
7
|
+
import { ScreenEmptyState } from '../workspace/layout'
|
|
8
|
+
import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
|
|
9
|
+
import { SUBSTRATE_PATH } from './routes'
|
|
10
|
+
|
|
11
|
+
export interface ContextPin {
|
|
12
|
+
pinned: string | null
|
|
13
|
+
active: string
|
|
14
|
+
/** The page was opened for another context: render nothing of it and read nothing. */
|
|
15
|
+
mismatch: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The `ctx` pin every Substrate detail page carries: a link names the
|
|
20
|
+
* Kubernetes context it was made in, and a missing pin is set to the active
|
|
21
|
+
* one. Actors, templates and pools are named the same way in every cluster, so
|
|
22
|
+
* a page opened under another context must not show that cluster's namesake.
|
|
23
|
+
*/
|
|
24
|
+
export function useContextPin(): ContextPin {
|
|
25
|
+
const location = useLocation()
|
|
26
|
+
const [params, setParams] = useSearchParams()
|
|
27
|
+
const { connection } = useConnection()
|
|
28
|
+
const active = connection.context
|
|
29
|
+
const pinned = params.get('ctx')
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (pinned || !active) return
|
|
33
|
+
const p = new URLSearchParams(params)
|
|
34
|
+
p.set('ctx', active)
|
|
35
|
+
setParams(p, { replace: true, state: location.state })
|
|
36
|
+
}, [pinned, active]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
37
|
+
|
|
38
|
+
return { pinned, active, mismatch: !!pinned && !!active && pinned !== active }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What a detail page shows in place of itself when its pin names another context. */
|
|
42
|
+
export function NotInContext({ name, what, pinnedContext, activeContext }: { name: string; what: string; pinnedContext: string; activeContext: string }) {
|
|
43
|
+
const navigate = useWorkspaceNavigate()
|
|
44
|
+
const { data: contexts } = useContexts()
|
|
45
|
+
const { requestSwitch, confirmDialog } = useContextSwitchFlow()
|
|
46
|
+
const pinned = contexts?.find((c) => c.name === pinnedContext)
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
<ScreenEmptyState
|
|
50
|
+
icon={Unplug}
|
|
51
|
+
title={`${name} is not in ${activeContext}`}
|
|
52
|
+
detail={`This link points at ${what}, read through context ${pinnedContext}. Radar does not open a same-named one from another cluster.`}
|
|
53
|
+
action={
|
|
54
|
+
<div className="mt-4 flex flex-wrap justify-center gap-2">
|
|
55
|
+
{pinned && (
|
|
56
|
+
<button type="button" onClick={() => requestSwitch(pinned)} className="btn-brand px-3 py-1.5 text-sm font-medium">
|
|
57
|
+
Switch back to {pinnedContext}
|
|
58
|
+
</button>
|
|
59
|
+
)}
|
|
60
|
+
<button type="button" onClick={() => navigate(SUBSTRATE_PATH)} className="btn-secondary px-3 py-1.5 text-sm">
|
|
61
|
+
Go to the Agent Substrate Overview
|
|
62
|
+
</button>
|
|
63
|
+
</div>
|
|
64
|
+
}
|
|
65
|
+
/>
|
|
66
|
+
{confirmDialog}
|
|
67
|
+
</>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { DetailSlots, HostResource, KindListProps, ResourceHost } from '../../integrations/resourceHost'
|
|
2
|
+
import { PoolHeaderBadge, SubstratePoolSummary } from './SubstratePoolSummary'
|
|
3
|
+
import type { SelectedResource } from '../../types'
|
|
4
|
+
import { useSubstrateStatus, useSubstrateWorkspace } from '../../api/substrateWorkspace'
|
|
5
|
+
import { kindToPluralWithGroup } from '../../utils/navigation'
|
|
6
|
+
import { DrawerTrailBack } from '../workspace/DrawerTrailBack'
|
|
7
|
+
import { ScreenBody } from '../workspace/layout'
|
|
8
|
+
import { PoolsTable } from './SubstrateOverview'
|
|
9
|
+
import { SubstrateCoverageNotice, SubstrateHeader, SubstrateScreenGate, SubstrateSourceLine } from './shared'
|
|
10
|
+
import {
|
|
11
|
+
SUBSTRATE_GROUP,
|
|
12
|
+
SUBSTRATE_NAMESPACE_FILTER_TOOLTIP,
|
|
13
|
+
SUBSTRATE_PATH,
|
|
14
|
+
SUBSTRATE_WORKERPOOL_KIND,
|
|
15
|
+
substrateKindListMode,
|
|
16
|
+
substratePoolPath,
|
|
17
|
+
} from './routes'
|
|
18
|
+
|
|
19
|
+
const KIND_BY_PLURAL: Record<string, string> = { workerpools: 'WorkerPool', pods: 'Pod', nodes: 'Node' }
|
|
20
|
+
|
|
21
|
+
function SubstrateDrawerTrailBack({ resource }: { resource: SelectedResource }) {
|
|
22
|
+
return <DrawerTrailBack resource={resource} pathPrefix={SUBSTRATE_PATH} kindLabel={(plural) => KIND_BY_PLURAL[plural]} />
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isWorkerPool(resource: HostResource): boolean {
|
|
26
|
+
return resource.group === SUBSTRATE_GROUP && kindToPluralWithGroup(resource.kind, resource.group) === SUBSTRATE_WORKERPOOL_KIND.name
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The WorkerPool kind's list joins Kubernetes and Substrate across namespaces.
|
|
31
|
+
*/
|
|
32
|
+
function SubstratePoolsKindList({ inspected, onInspect }: KindListProps) {
|
|
33
|
+
const query = useSubstrateWorkspace()
|
|
34
|
+
const status = useSubstrateStatus()
|
|
35
|
+
return (
|
|
36
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-theme-base">
|
|
37
|
+
<SubstrateScreenGate query={query} discoveryPending={false} discovered>
|
|
38
|
+
{(data) => (
|
|
39
|
+
<div className="flex min-h-0 flex-1 flex-col">
|
|
40
|
+
<SubstrateHeader title="Pools" intro="Cluster-wide" />
|
|
41
|
+
<ScreenBody>
|
|
42
|
+
<SubstrateCoverageNotice coverage={data.coverage} kinds={['workers', 'actors']} />
|
|
43
|
+
<PoolsTable data={data} onInspect={onInspect} inspected={inspected} />
|
|
44
|
+
<SubstrateSourceLine tier={data.apiTier} status={status.data} />
|
|
45
|
+
</ScreenBody>
|
|
46
|
+
</div>
|
|
47
|
+
)}
|
|
48
|
+
</SubstrateScreenGate>
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const substrateResourceHost: ResourceHost = {
|
|
54
|
+
id: 'substrate',
|
|
55
|
+
feature: 'substrateWorkspace',
|
|
56
|
+
drawerNavigation: {
|
|
57
|
+
ownsPath: (pathname) => pathname === SUBSTRATE_PATH || pathname.startsWith(`${SUBSTRATE_PATH}/`),
|
|
58
|
+
Component: SubstrateDrawerTrailBack,
|
|
59
|
+
},
|
|
60
|
+
resources: [{ name: SUBSTRATE_WORKERPOOL_KIND.name, group: SUBSTRATE_GROUP }],
|
|
61
|
+
// A WorkerPool has a page of its own in the workspace: "Open full view" and
|
|
62
|
+
// links to the generic detail land there.
|
|
63
|
+
expandedPath: (resource, context, tab) => (isWorkerPool(resource) ? substratePoolPath({ namespace: resource.namespace, name: resource.name }, context, tab) : null),
|
|
64
|
+
detailRedirect: (resource, search) => {
|
|
65
|
+
if (!isWorkerPool(resource)) return null
|
|
66
|
+
const params = new URLSearchParams(search)
|
|
67
|
+
params.delete('apiGroup')
|
|
68
|
+
const base = substratePoolPath({ namespace: resource.namespace, name: resource.name })
|
|
69
|
+
const qs = params.toString()
|
|
70
|
+
return qs ? `${base}?${qs}` : base
|
|
71
|
+
},
|
|
72
|
+
detailOwnership: ['summary', 'destination'],
|
|
73
|
+
detailSlots: (resource): DetailSlots => (isWorkerPool(resource)
|
|
74
|
+
? {
|
|
75
|
+
renderSummary: ({ namespace, name, resource: data, context, onNavigate }) => <SubstratePoolSummary namespace={namespace} name={name} resource={data} context={context} onNavigate={onNavigate} />,
|
|
76
|
+
renderStatusBadge: (data: any) => <PoolHeaderBadge resource={data} />,
|
|
77
|
+
}
|
|
78
|
+
: {}),
|
|
79
|
+
// Radar's pool table is the kind's list, so the sidebar's Pools row stands for it.
|
|
80
|
+
kindLists: [
|
|
81
|
+
{ kind: SUBSTRATE_WORKERPOOL_KIND, title: 'Agent Substrate pools', mode: substrateKindListMode, namespaceFilterTooltip: SUBSTRATE_NAMESPACE_FILTER_TOOLTIP, Component: SubstratePoolsKindList },
|
|
82
|
+
],
|
|
83
|
+
}
|