@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,485 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { useLocation, useSearchParams } from 'react-router-dom'
|
|
3
|
+
import { clsx } from 'clsx'
|
|
4
|
+
import { Unlink } from 'lucide-react'
|
|
5
|
+
import { Badge, CertaintyGlyph, DimensionValue, FactGrid, FactRow, FactSource, FactValue, Tooltip, WorkspaceCard, WorkspaceProblemCallout, formatDuration, toneFillClass, toneTextClass, type NavigateToResource, type StatusTone } from '@skyhook-io/k8s-ui'
|
|
6
|
+
import { getWorkerPoolStatus } from '@skyhook-io/k8s-ui/components/resources/resource-utils-agent-runtimes'
|
|
7
|
+
import { substrateErrorCode, useSubstratePool, type SubstratePool, type SubstrateRef, type SubstrateWorkerRow } from '../../api/substrateWorkspace'
|
|
8
|
+
import { useConnection } from '../../context/ConnectionContext'
|
|
9
|
+
import { isForbiddenError, usePrometheusStatus } from '../../api/client'
|
|
10
|
+
import { useSubstrateHealth } from '../../api/substrateHealth'
|
|
11
|
+
import { formatMetricValue } from '@skyhook-io/k8s-ui/components/charts'
|
|
12
|
+
import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
|
|
13
|
+
import { WorkspaceConditions } from '../workspace/WorkspaceConditions'
|
|
14
|
+
import { coverageLabel } from '../workspace/coverage'
|
|
15
|
+
import { RefreshFailedNotice } from '../workspace/layout'
|
|
16
|
+
import { ACTOR_STATE_LABEL, compactActorLabel, definitiveFailure, attentionTone, placementTone, poolReadFailure, poolReading, splitReading, bytesText, coverageInPart, coverageReason, coverageUnread, cpuText, tierReading } from './readings'
|
|
17
|
+
import { ACTOR_DRAWER_PARAM, SUBSTRATE_GROUP, SUBSTRATE_PATH, SUBSTRATE_SCREENS, encodeActorParam, substrateActorPath, substrateActorsPath, substratePoolPath, substrateTemplatePath } from './routes'
|
|
18
|
+
import { IMPACT_LABEL, Name, Term, Unread, WorkerStateChip } from './shared'
|
|
19
|
+
import { SlotsCell, slotsOffActive } from './SubstrateOverview'
|
|
20
|
+
import { RESERVED_MEANING, lostText } from './SubstrateWorkers'
|
|
21
|
+
|
|
22
|
+
/** Past this many workers the grid becomes one row per worker with a slot bar. */
|
|
23
|
+
export const PLACEMENT_CARD_LIMIT = 12
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
type WorkerActor = NonNullable<SubstrateWorkerRow['actors']>[number]
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Opens an actor from a pool's page or drawer: its drawer inside the
|
|
31
|
+
* workspace, its page from anywhere else (the Resources list's drawer).
|
|
32
|
+
*/
|
|
33
|
+
export function useOpenActor() {
|
|
34
|
+
const { pathname } = useLocation()
|
|
35
|
+
const [params, setParams] = useSearchParams()
|
|
36
|
+
const navigate = useWorkspaceNavigate()
|
|
37
|
+
const { connection } = useConnection()
|
|
38
|
+
return (ref: SubstrateRef) => {
|
|
39
|
+
if (pathname === SUBSTRATE_PATH || pathname.startsWith(`${SUBSTRATE_PATH}/`)) {
|
|
40
|
+
const p = new URLSearchParams(params)
|
|
41
|
+
p.set(ACTOR_DRAWER_PARAM, encodeActorParam(ref))
|
|
42
|
+
p.delete('drawer')
|
|
43
|
+
setParams(p, { replace: true })
|
|
44
|
+
} else {
|
|
45
|
+
navigate(substrateActorPath(ref, connection.context || undefined))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** What one worker's slots hold: an actor per filled slot, then the free ones. */
|
|
51
|
+
export function workerSlots(w: Pick<SubstrateWorkerRow, 'capacity' | 'allocated' | 'actors'>): { actors: WorkerActor[]; free: number; total: number | undefined } {
|
|
52
|
+
const actors = w.actors ?? []
|
|
53
|
+
const total = w.capacity?.actors
|
|
54
|
+
const filled = Math.max(actors.length, w.allocated?.actors ?? 0)
|
|
55
|
+
return { actors, free: total !== undefined ? Math.max(0, total - filled) : 0, total }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The mark of an actor whose sandbox is gone: an icon, not a strike, which would read as deleted. The legend names it; a cell keeps the room for the actor's name. */
|
|
59
|
+
function LostMarker() {
|
|
60
|
+
return <Unlink aria-hidden className={clsx('ml-auto h-3 w-3 shrink-0', toneTextClass('unhealthy'))} />
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ActorCell({ actor, onOpen }: { actor: WorkerActor; onOpen: (ref: SubstrateRef) => void }) {
|
|
64
|
+
// Running on a worker Substrate no longer trusts is not healthy running: its own colour, as in the legend.
|
|
65
|
+
const tone = placementTone(actor.state, actor.workerImpact?.kind)
|
|
66
|
+
// A lost sandbox is told apart by more than hue: a "lost" marker, so a 4px bar isn't the only cue.
|
|
67
|
+
const lost = actor.workerImpact?.kind === 'restarted'
|
|
68
|
+
const state = actor.workerImpact ? `${ACTOR_STATE_LABEL[actor.state]} · ${IMPACT_LABEL[actor.workerImpact.kind]}` : ACTOR_STATE_LABEL[actor.state]
|
|
69
|
+
const label = compactActorLabel(actor)
|
|
70
|
+
const agent = actor.kagent?.kind === 'agentSession' ? ` · kagent Agent ${actor.kagent.agent.name}` : ''
|
|
71
|
+
return (
|
|
72
|
+
<Tooltip content={`${actor.atespace} / ${actor.name}${agent} · ${state} · template ${actor.template.name}${actor.workerImpact ? `. ${actor.workerImpact.reading}` : ''}`}>
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
onClick={() => onOpen(actor)}
|
|
76
|
+
className="flex w-full min-w-0 items-center gap-1.5 rounded-md border border-theme-border bg-theme-base px-1.5 py-1 text-left font-mono text-[11px] text-theme-text-primary hover:bg-theme-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
|
|
77
|
+
>
|
|
78
|
+
<span aria-hidden className={clsx('h-3 w-1 shrink-0 rounded-sm', toneFillClass(tone))} />
|
|
79
|
+
<span className={clsx('min-w-0 truncate', lost && toneTextClass('unhealthy'))}>{label.name}</span>
|
|
80
|
+
{label.agent && <span className="min-w-0 truncate font-sans text-theme-text-tertiary">{label.agent}</span>}
|
|
81
|
+
{lost && <LostMarker />}
|
|
82
|
+
<span className="sr-only">, {state}</span>
|
|
83
|
+
</button>
|
|
84
|
+
</Tooltip>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The node's risk, as two actor lists: what its loss stops, and what state it alone holds. */
|
|
89
|
+
export function NodeRiskLinks({ node }: { node: string }) {
|
|
90
|
+
const navigate = useWorkspaceNavigate()
|
|
91
|
+
return (
|
|
92
|
+
<div className="mt-1 flex flex-wrap gap-x-3 text-xs">
|
|
93
|
+
<button type="button" onClick={() => navigate(substrateActorsPath({ node, nodeHas: 'running' }))} className="text-accent-text hover:underline">Actors running on this node →</button>
|
|
94
|
+
<Tooltip content="Actors whose newest snapshot is stored only on this node: losing the node, not just this worker Pod, loses that state.">
|
|
95
|
+
<button type="button" onClick={() => navigate(substrateActorsPath({ node, nodeHas: 'localSnapshot' }))} className="text-accent-text hover:underline">Snapshots only on this node →</button>
|
|
96
|
+
</Tooltip>
|
|
97
|
+
</div>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A worker's actor slots in words. Free slots are a count, not positions:
|
|
103
|
+
* "18 of 24 actor slots used · 6 free". A worker that takes no new actors has
|
|
104
|
+
* unused slots, not free ones. Unknown capacity stays unknown.
|
|
105
|
+
*/
|
|
106
|
+
export function slotsText(w: Pick<SubstrateWorkerRow, 'state' | 'capacity' | 'allocated' | 'actors'>): string {
|
|
107
|
+
const { actors, free, total } = workerSlots(w)
|
|
108
|
+
const used = Math.max(actors.length, w.allocated?.actors ?? 0)
|
|
109
|
+
if (total === undefined) return `${used} ${used === 1 ? 'actor' : 'actors'} · slot capacity unknown`
|
|
110
|
+
const rest = w.state === 'active' ? `${free} free` : `${free} unused · takes no new actors`
|
|
111
|
+
return `${used} of ${total} actor slots used · ${rest}`
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resourcesReserved(w: SubstrateWorkerRow): ReactNode {
|
|
115
|
+
if (!w.capacity || !w.allocated) return undefined
|
|
116
|
+
return (
|
|
117
|
+
<>
|
|
118
|
+
{cpuText(w.allocated.cpuMillicores)} of {cpuText(w.capacity.cpuMillicores)} CPU · {bytesText(w.allocated.memoryBytes)} of {bytesText(w.capacity.memoryBytes)}{' '}
|
|
119
|
+
<Tooltip content={RESERVED_MEANING}><span tabIndex={0} className="cursor-help underline decoration-dotted underline-offset-2">reserved</span></Tooltip>
|
|
120
|
+
</>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function WorkerStateBadge({ w }: { w: SubstrateWorkerRow }) {
|
|
125
|
+
const lost = lostText(w)
|
|
126
|
+
return (
|
|
127
|
+
<span className="inline-flex flex-wrap items-center gap-1.5">
|
|
128
|
+
<WorkerStateChip w={w} />
|
|
129
|
+
{w.state !== 'active' && w.heldForSeconds !== undefined && <span className="whitespace-nowrap text-xs text-theme-text-tertiary">for at least {formatDuration(w.heldForSeconds * 1000)}</span>}
|
|
130
|
+
{lost && <span className="whitespace-nowrap text-xs text-theme-text-secondary">{lost}</span>}
|
|
131
|
+
</span>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function WorkerCard({ w, onOpenActor, onOpenPod, onOpenNode }: { w: SubstrateWorkerRow; onOpenActor: (ref: SubstrateRef) => void; onOpenPod: (w: SubstrateWorkerRow) => void; onOpenNode?: (node: string) => void }) {
|
|
136
|
+
const { actors, free } = workerSlots(w)
|
|
137
|
+
const podMismatch = w.podReady === true && w.state === 'unavailable'
|
|
138
|
+
const resources = resourcesReserved(w)
|
|
139
|
+
return (
|
|
140
|
+
<div className="min-w-0 rounded-lg border border-theme-border bg-theme-surface p-3">
|
|
141
|
+
<div className="flex flex-wrap items-center justify-between gap-x-2 gap-y-1">
|
|
142
|
+
<button type="button" onClick={() => onOpenPod(w)} className="min-w-0 text-left text-accent-text hover:underline">
|
|
143
|
+
<Name name={w.pod} />
|
|
144
|
+
</button>
|
|
145
|
+
<WorkerStateBadge w={w} />
|
|
146
|
+
</div>
|
|
147
|
+
{w.actors === undefined ? (
|
|
148
|
+
<p className="mt-2 text-xs text-theme-text-tertiary">Actors were not read, so which actor holds each slot is unknown.</p>
|
|
149
|
+
) : actors.length + free === 0 && w.capacity?.actors === 0 ? (
|
|
150
|
+
<p className="mt-2 text-xs text-theme-text-tertiary">0 slots: the worker reports no actor capacity, so Substrate places nothing here.</p>
|
|
151
|
+
) : (
|
|
152
|
+
<>
|
|
153
|
+
{actors.length > 0 && (
|
|
154
|
+
<div className="mt-2 grid grid-cols-[repeat(auto-fill,minmax(8.75rem,1fr))] gap-1">
|
|
155
|
+
{actors.map((a) => <ActorCell key={`${a.atespace}/${a.name}`} actor={a} onOpen={onOpenActor} />)}
|
|
156
|
+
</div>
|
|
157
|
+
)}
|
|
158
|
+
<div className="mt-2 text-xs text-theme-text-secondary">{slotsText(w)}</div>
|
|
159
|
+
</>
|
|
160
|
+
)}
|
|
161
|
+
<div className="mt-0.5 text-xs text-theme-text-tertiary">
|
|
162
|
+
{w.node && onOpenNode
|
|
163
|
+
? <button type="button" onClick={() => onOpenNode(w.node)} className="break-all font-mono text-accent-text hover:underline">{w.node}</button>
|
|
164
|
+
: <span className="break-all font-mono">{w.node || 'node unknown'}</span>}
|
|
165
|
+
{resources && <> · {resources}</>}
|
|
166
|
+
</div>
|
|
167
|
+
{podMismatch && <div className="mt-1 text-xs text-theme-text-secondary">Its Pod is Ready, so the worker, not Kubernetes, is refusing work.</div>}
|
|
168
|
+
{w.podTerminating && <div className="mt-1 text-xs text-theme-text-secondary">Its Pod is terminating, so Kubernetes doesn’t count it as ready.</div>}
|
|
169
|
+
</div>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** A filled-slot bar for a worker row, one segment per state. */
|
|
174
|
+
function SlotBar({ w }: { w: SubstrateWorkerRow }) {
|
|
175
|
+
const { actors, free, total } = workerSlots(w)
|
|
176
|
+
const size = Math.max(total ?? 0, actors.length) || 1
|
|
177
|
+
// One segment per grid colour, so the bar and the cards read the same.
|
|
178
|
+
const byTone = new Map<StatusTone, number>()
|
|
179
|
+
for (const a of actors) {
|
|
180
|
+
const tone = placementTone(a.state, a.workerImpact?.kind)
|
|
181
|
+
byTone.set(tone, (byTone.get(tone) ?? 0) + 1)
|
|
182
|
+
}
|
|
183
|
+
return (
|
|
184
|
+
<div role="img" aria-label={`${actors.length} of ${total ?? 'unknown'} slots used`} className="flex h-2 w-full overflow-hidden rounded bg-theme-elevated">
|
|
185
|
+
{[...byTone].map(([tone, n]) => (
|
|
186
|
+
<span key={tone} style={{ flexGrow: n / size, flexBasis: 0 }} className={toneFillClass(tone)} />
|
|
187
|
+
))}
|
|
188
|
+
<span style={{ flexGrow: free / size, flexBasis: 0 }} />
|
|
189
|
+
</div>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function WorkerRows({ workers, onOpenPod }: { workers: SubstrateWorkerRow[]; onOpenPod: (w: SubstrateWorkerRow) => void }) {
|
|
194
|
+
const navigate = useWorkspaceNavigate()
|
|
195
|
+
return (
|
|
196
|
+
<ul className="divide-y divide-theme-border rounded-lg border border-theme-border bg-theme-surface">
|
|
197
|
+
{workers.map((w) => (
|
|
198
|
+
<li key={w.name} className="grid grid-cols-[minmax(12rem,1.4fr)_minmax(8rem,auto)_minmax(8rem,1fr)_auto] items-center gap-3 px-3 py-2 text-sm">
|
|
199
|
+
<button type="button" onClick={() => onOpenPod(w)} className="min-w-0 text-left text-accent-text hover:underline"><Name name={w.pod} /></button>
|
|
200
|
+
<WorkerStateBadge w={w} />
|
|
201
|
+
<SlotBar w={w} />
|
|
202
|
+
<button type="button" onClick={() => navigate(substrateActorsPath({ worker: w.pod, pool: `${w.namespace}/${w.pool}` }))} className="whitespace-nowrap text-xs text-accent-text hover:underline">
|
|
203
|
+
{slotsText(w)}
|
|
204
|
+
</button>
|
|
205
|
+
</li>
|
|
206
|
+
))}
|
|
207
|
+
</ul>
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The capacity verdict from Prometheus. Where it has none to give, a line
|
|
213
|
+
* says why, so the section's absence is not read as "no problem".
|
|
214
|
+
*/
|
|
215
|
+
function CapacityVerdict({ namespace, name, onOpenMetrics }: { namespace: string; name: string; onOpenMetrics?: () => void }) {
|
|
216
|
+
const target = { kind: 'workerpool' as const, namespace, name }
|
|
217
|
+
const { data: prometheus, isError } = usePrometheusStatus()
|
|
218
|
+
const connected = prometheus?.connected === true
|
|
219
|
+
const health = useSubstrateHealth(target, connected)
|
|
220
|
+
const delivery = !health.error && health.data?.status === 'available'
|
|
221
|
+
? health.data.verdict?.facts
|
|
222
|
+
.filter((f) => f.id === 'resumeP95' || f.id === 'resumeFailures' || f.id === 'crashes')
|
|
223
|
+
.map((f) => `${f.label} ${f.state === 'ok' && f.value !== undefined ? formatMetricValue(f.value, f.unit) : f.state === 'empty' ? 'none recorded' : 'unavailable'}`)
|
|
224
|
+
: undefined
|
|
225
|
+
const reason = isForbiddenError(health.error) ? `Requires get on workerpools.ate.dev in ${namespace}`
|
|
226
|
+
: isError ? 'Prometheus connection status could not be read'
|
|
227
|
+
: !prometheus ? 'Checking Prometheus…'
|
|
228
|
+
: !connected ? 'Prometheus is not connected'
|
|
229
|
+
: health.error ? health.error.message
|
|
230
|
+
: health.data?.status === 'notFound' ? 'No Substrate series for this pool'
|
|
231
|
+
: health.data?.status === 'available' ? (delivery?.length ? delivery.join(' · ') : 'Resume and crash readings unavailable')
|
|
232
|
+
: health.data?.reason || health.blockedReason || (health.upgrade ? 'This Radar needs an upgrade' : 'Reading Prometheus…')
|
|
233
|
+
return <DimensionValue tone={delivery?.length ? 'neutral' : 'unknown'} source="Substrate Prometheus series · last hour" linkLabel="Metrics" onOpen={onOpenMetrics}>{reason}</DimensionValue>
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function Legend() {
|
|
237
|
+
const items: { label: string; tone: Parameters<typeof toneFillClass>[0] }[] = [
|
|
238
|
+
{ label: 'running', tone: placementTone('running', undefined) },
|
|
239
|
+
{ label: 'its worker is unavailable', tone: placementTone('running', 'unavailable') },
|
|
240
|
+
{ label: 'its worker is draining', tone: placementTone('running', 'draining') },
|
|
241
|
+
{ label: 'resuming, suspending or reverting', tone: placementTone('resuming', undefined) },
|
|
242
|
+
{ label: 'crashed, still assigned', tone: placementTone('crashed', undefined) },
|
|
243
|
+
]
|
|
244
|
+
return (
|
|
245
|
+
<ul className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-theme-text-tertiary" aria-label="Legend">
|
|
246
|
+
{items.map((i) => (
|
|
247
|
+
<li key={i.label} className="flex items-center gap-1.5"><span aria-hidden className={clsx('h-3 w-1 rounded-sm', toneFillClass(i.tone))} />{i.label}</li>
|
|
248
|
+
))}
|
|
249
|
+
<li className="flex items-center gap-1.5">
|
|
250
|
+
<span aria-hidden className={clsx('h-3 w-1 rounded-sm', toneFillClass('unhealthy'))} />
|
|
251
|
+
<LostMarker />
|
|
252
|
+
sandbox lost: its worker restarted under it
|
|
253
|
+
</li>
|
|
254
|
+
</ul>
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function Placement({
|
|
259
|
+
data, onOpenActor, onOpenPod, onOpenNode, drawer,
|
|
260
|
+
}: {
|
|
261
|
+
data: SubstratePool
|
|
262
|
+
onOpenActor: (ref: SubstrateRef) => void
|
|
263
|
+
onOpenPod: (w: SubstrateWorkerRow) => void
|
|
264
|
+
onOpenNode?: (node: string) => void
|
|
265
|
+
drawer?: boolean
|
|
266
|
+
}) {
|
|
267
|
+
const workers = [...data.workers].sort((a, b) => a.pod.localeCompare(b.pod))
|
|
268
|
+
if (workers.length === 0 || coverageUnread(data.coverage.workers)) return null
|
|
269
|
+
const partial = coverageInPart(data.coverage.workers)
|
|
270
|
+
const nodes = [...new Set(workers.map((w) => w.node).filter(Boolean))]
|
|
271
|
+
const content = <>
|
|
272
|
+
{partial && <p className="mb-2 text-xs text-theme-text-secondary">Observed workers only · {coverageReason(data.coverage.workers, 'workers')}.</p>}
|
|
273
|
+
{workers.length > PLACEMENT_CARD_LIMIT ? (
|
|
274
|
+
<WorkerRows workers={workers} onOpenPod={onOpenPod} />
|
|
275
|
+
) : (
|
|
276
|
+
<div className={clsx('grid items-start gap-3', drawer ? 'grid-cols-1' : 'grid-cols-1 lg:grid-cols-2')}>
|
|
277
|
+
{workers.map((w) => <WorkerCard key={w.name} w={w} onOpenActor={onOpenActor} onOpenPod={onOpenPod} onOpenNode={onOpenNode} />)}
|
|
278
|
+
</div>
|
|
279
|
+
)}
|
|
280
|
+
<div className="mt-3"><Legend /></div>
|
|
281
|
+
<p className="mt-2 text-xs text-theme-text-tertiary">
|
|
282
|
+
A <Term term="slot">slot</Term> holds one actor. Placement also uses CPU and memory.
|
|
283
|
+
</p>
|
|
284
|
+
{nodes.length > 0 && <div className="mt-2 flex flex-wrap gap-3 border-t-subtle pt-2">
|
|
285
|
+
{nodes.map((node) => <div key={node} className="min-w-0 text-xs text-theme-text-secondary">
|
|
286
|
+
<span className="break-all font-mono">{node}</span><NodeRiskLinks node={node} />
|
|
287
|
+
</div>)}
|
|
288
|
+
</div>}
|
|
289
|
+
</>
|
|
290
|
+
return <WorkspaceCard title="Placement" framed={!drawer}>{content}</WorkspaceCard>
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
interface PoolResource {
|
|
294
|
+
metadata?: { namespace?: string; name?: string; generation?: number }
|
|
295
|
+
spec?: { replicas?: number; sandboxClasses?: { name?: string; configRef?: { name?: string } }[] }
|
|
296
|
+
status?: {
|
|
297
|
+
replicas?: number
|
|
298
|
+
readyReplicas?: number
|
|
299
|
+
selector?: string
|
|
300
|
+
sandboxClasses?: { name?: string; configRef?: { name?: string }; pendingConfigRef?: { name?: string }; conditions?: { type: string; status: string; reason?: string; message?: string; lastTransitionTime?: string }[] }[]
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function poolConditions(resource: PoolResource) {
|
|
305
|
+
return (resource.status?.sandboxClasses ?? []).flatMap((c) =>
|
|
306
|
+
(c.conditions ?? []).map((condition) => ({ ...condition, type: c.name ? `${c.name} · ${condition.type}` : condition.type })),
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function PoolAbout({ resource, onNavigate, specOnly }: { resource: PoolResource; onNavigate?: NavigateToResource; specOnly?: boolean }) {
|
|
311
|
+
const classes = resource.spec?.sandboxClasses ?? []
|
|
312
|
+
const link = (name: string) => onNavigate
|
|
313
|
+
? <button type="button" onClick={() => onNavigate({ kind: 'SandboxConfig', group: SUBSTRATE_GROUP, namespace: '', name })} className="font-mono text-accent-text hover:underline">{name}</button>
|
|
314
|
+
: <span className="font-mono">{name}</span>
|
|
315
|
+
return (
|
|
316
|
+
<>
|
|
317
|
+
<FactRow label="Sandbox classes">{classes.length > 0 ? classes.map((c) => c.name).filter(Boolean).join(' · ') : <Unread>None declared</Unread>}</FactRow>
|
|
318
|
+
<FactRow label="SandboxConfig">
|
|
319
|
+
{classes.length === 0 ? <Unread>Unreported</Unread> : classes.map((c, i) => {
|
|
320
|
+
const status = specOnly ? undefined : resource.status?.sandboxClasses?.find((sc) => sc.name === c.name)
|
|
321
|
+
const current = status?.configRef?.name
|
|
322
|
+
const pending = status?.pendingConfigRef?.name
|
|
323
|
+
const requested = c.configRef?.name
|
|
324
|
+
return <div key={c.name ?? i}>
|
|
325
|
+
{classes.length > 1 && c.name && <>{c.name} · </>}
|
|
326
|
+
{current || pending
|
|
327
|
+
? <>{current && link(current)}{pending && pending !== current && <>{current ? ' → ' : 'Pending: '}{link(pending)}</>}</>
|
|
328
|
+
: requested ? <>{!specOnly && 'Requested: '}{link(requested)}{!specOnly && ' (unresolved)'}</> : <Unread>Unreported</Unread>}
|
|
329
|
+
</div>
|
|
330
|
+
})}
|
|
331
|
+
</FactRow>
|
|
332
|
+
</>
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function PoolSpecStatus({ resource, onNavigate }: { resource: PoolResource; onNavigate?: NavigateToResource }) {
|
|
337
|
+
const count = (n: number | undefined, source: string) => {
|
|
338
|
+
const fact = { text: n === undefined ? 'Unreported' : String(n), tone: n === undefined ? 'unknown' as const : 'neutral' as const, source }
|
|
339
|
+
return <><FactValue fact={fact} /><FactSource fact={fact} /></>
|
|
340
|
+
}
|
|
341
|
+
return (
|
|
342
|
+
<div className="space-y-4 p-4">
|
|
343
|
+
<WorkspaceCard title="Desired by spec">
|
|
344
|
+
<FactGrid>
|
|
345
|
+
<FactRow label="Workers">{count(resource.spec?.replicas, 'spec.replicas')}</FactRow>
|
|
346
|
+
<PoolAbout resource={resource} onNavigate={onNavigate} specOnly />
|
|
347
|
+
</FactGrid>
|
|
348
|
+
</WorkspaceCard>
|
|
349
|
+
<WorkspaceCard title="Reported by controller">
|
|
350
|
+
<FactGrid>
|
|
351
|
+
<FactRow label="Worker replicas">{count(resource.status?.replicas, 'status.replicas')}</FactRow>
|
|
352
|
+
<FactRow label="Ready replicas">{count(resource.status?.readyReplicas, 'status.readyReplicas')}</FactRow>
|
|
353
|
+
<FactRow label="Worker selector">{resource.status?.selector || <Unread>Unreported</Unread>}</FactRow>
|
|
354
|
+
</FactGrid>
|
|
355
|
+
</WorkspaceCard>
|
|
356
|
+
<WorkspaceConditions conditions={poolConditions(resource)} title="Sandbox class conditions" sourcePath="status.sandboxClasses[].conditions" />
|
|
357
|
+
</div>
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export function SubstratePoolSummary({
|
|
362
|
+
namespace, name, resource, context, onNavigate,
|
|
363
|
+
}: {
|
|
364
|
+
namespace: string
|
|
365
|
+
name: string
|
|
366
|
+
resource: PoolResource
|
|
367
|
+
context: 'drawer' | 'expanded'
|
|
368
|
+
onNavigate?: NavigateToResource
|
|
369
|
+
}) {
|
|
370
|
+
const query = useSubstratePool({ namespace, name })
|
|
371
|
+
const [params, setParams] = useSearchParams()
|
|
372
|
+
const navigate = useWorkspaceNavigate()
|
|
373
|
+
const { connection } = useConnection()
|
|
374
|
+
const openActor = useOpenActor()
|
|
375
|
+
const code = substrateErrorCode(query.error)
|
|
376
|
+
const data = definitiveFailure(code) || code === 'incomplete' ? undefined : query.data
|
|
377
|
+
const k = data?.pool.kubernetes
|
|
378
|
+
const workerRead = data?.coverage.workers
|
|
379
|
+
const finding = data?.attention
|
|
380
|
+
const placement = data?.pool.placement
|
|
381
|
+
const partial = coverageInPart(workerRead)
|
|
382
|
+
const workers = placement?.workers
|
|
383
|
+
const actorsPartial = coverageInPart(data?.coverage.actors)
|
|
384
|
+
const offActive = data ? slotsOffActive(data.pool, actorsPartial) : 0
|
|
385
|
+
const openTab = (tab: string) => {
|
|
386
|
+
const p = new URLSearchParams(params)
|
|
387
|
+
if (tab === 'overview') p.delete('tab')
|
|
388
|
+
else p.set('tab', tab)
|
|
389
|
+
setParams(p, { replace: true })
|
|
390
|
+
}
|
|
391
|
+
const drawer = context === 'drawer'
|
|
392
|
+
const desired = resource.spec?.replicas
|
|
393
|
+
const replicas = resource.status?.readyReplicas
|
|
394
|
+
const observed = k?.pods
|
|
395
|
+
const poolVerdict = data && poolReading(data.pool, finding)
|
|
396
|
+
const controllerFinding = poolVerdict?.controllerFinding
|
|
397
|
+
const [lead, rawDetail] = finding ? splitReading(finding.reading) : []
|
|
398
|
+
const shortfallDetails = poolVerdict?.label.startsWith('Short of workers · ') ? rawDetail : undefined
|
|
399
|
+
const readState = query.isLoading ? 'Reading Substrate…'
|
|
400
|
+
: !data ? poolReadFailure(query.error, namespace)
|
|
401
|
+
: data.apiTier.state !== 'connected' ? tierReading(data.apiTier).detail
|
|
402
|
+
: coverageReason(workerRead, 'workers')
|
|
403
|
+
return (
|
|
404
|
+
<div className="space-y-4 p-4">
|
|
405
|
+
{data && <RefreshFailedNotice queries={[query]} />}
|
|
406
|
+
{finding && <WorkspaceProblemCallout rootKind="WorkerPool" subjectIsSelf problem={{
|
|
407
|
+
id: finding.id, category: finding.rule, source: 'reading', tone: attentionTone(finding),
|
|
408
|
+
subject: { kind: 'WorkerPool', group: SUBSTRATE_GROUP, namespace, name },
|
|
409
|
+
title: poolVerdict!.label,
|
|
410
|
+
detail: shortfallDetails ?? lead, nextStep: controllerFinding || finding.rule !== 'poolShort' ? finding.nextStep : 'Compare controller readiness with Substrate registrations below.',
|
|
411
|
+
rawDetail: shortfallDetails ? undefined : rawDetail, rawDetailLabel: 'Details',
|
|
412
|
+
origin: { label: controllerFinding ? 'WorkerPool controller status' : 'Kubernetes and Substrate' },
|
|
413
|
+
}} />}
|
|
414
|
+
{drawer && <div className="flex flex-wrap gap-2">
|
|
415
|
+
<button type="button" className="btn-brand px-3 py-1 text-sm" onClick={() => navigate(substratePoolPath({ namespace, name }, connection.context || undefined))}>Open pool</button>
|
|
416
|
+
<button type="button" className="btn-secondary px-3 py-1 text-sm" onClick={() => navigate(substratePoolPath({ namespace, name }, connection.context || undefined, 'workers'))}>Workers</button>
|
|
417
|
+
</div>}
|
|
418
|
+
<WorkspaceCard framed={!drawer} title="At a glance">
|
|
419
|
+
<FactGrid>
|
|
420
|
+
<FactRow label="Provisioning">
|
|
421
|
+
<DimensionValue tone={k?.health === 'unhealthy' ? 'unhealthy' : k?.health === 'healthy' && (!observed || observed.ready === replicas) ? 'healthy' : (k?.health === 'degraded' || (observed && replicas !== undefined && observed.ready < replicas)) ? 'degraded' : 'unknown'}
|
|
422
|
+
source={<>{observed ? `Pods observed by Radar: ${observed.created} present, ${observed.ready} ready${observed.terminating ? `, ${observed.terminating} terminating` : ''}` : query.isLoading ? 'Reading Pod counts…' : !data ? readState
|
|
423
|
+
: data.podRead === 'denied' ? `Requires list on pods in ${namespace}` : data.podRead === 'uncollected' ? 'Worker Pods are not collected' : 'WorkerPool not read'}
|
|
424
|
+
{observed && replicas !== undefined && observed.ready !== replicas && ' · Counts differ from the controller’s status'}</>}>
|
|
425
|
+
{desired === undefined ? 'Desired workers unreported' : `${desired} desired by spec`}
|
|
426
|
+
{' · '}{replicas === undefined ? 'Controller readiness unreported' : `${replicas} ready reported by controller`}
|
|
427
|
+
</DimensionValue>
|
|
428
|
+
</FactRow>
|
|
429
|
+
<FactRow label="Registration">
|
|
430
|
+
<DimensionValue tone={!workers || partial ? 'unknown' : finding ? attentionTone(finding) : workers.active > 0 ? 'healthy' : 'neutral'}
|
|
431
|
+
source={workers ? partial ? coverageReason(workerRead, 'workers') : 'Worker registrations from Substrate' : readState}
|
|
432
|
+
linkLabel="Workers" onOpen={drawer ? undefined : () => openTab('workers')}>
|
|
433
|
+
{workers && (!partial || workers.total > 0)
|
|
434
|
+
? <>{partial ? '≥' : ''}{workers.total} registered · {partial && workers.active === 0 ? 'accepting actors unknown' : `${partial ? '≥' : ''}${workers.active} accepting actors`}</>
|
|
435
|
+
: 'Unknown'}
|
|
436
|
+
</DimensionValue>
|
|
437
|
+
</FactRow>
|
|
438
|
+
<FactRow label="Placement capacity">
|
|
439
|
+
<DimensionValue tone={!placement || partial ? 'unknown' : finding ? attentionTone(finding) : data?.pool.capacity === 'free' ? 'healthy' : 'unknown'}
|
|
440
|
+
source={!placement ? readState : <>{partial ? coverageReason(workerRead, 'workers') : 'Slots on active workers · actor CPU and memory can limit placement'}{offActive > 0 && ` · +${offActive} on non-active workers`}</>} linkLabel="Workers" onOpen={drawer ? undefined : () => openTab('workers')}>
|
|
441
|
+
{data ? <SlotsCell p={data.pool} connected={data.apiTier.state === 'connected'} actorsPartial={actorsPartial} inline /> : <Unread>Unknown</Unread>}
|
|
442
|
+
</DimensionValue>
|
|
443
|
+
</FactRow>
|
|
444
|
+
<FactRow label="Template matches">
|
|
445
|
+
<DimensionValue tone={data?.templates && !coverageInPart(data.coverage.templates) ? 'neutral' : 'unknown'}
|
|
446
|
+
source={data?.templates ? coverageInPart(data.coverage.templates) ? coverageReason(data.coverage.templates, 'templates') : 'Template selectors matched against this pool’s labels' : data ? coverageReason(data.coverage.templates, 'templates') : readState}
|
|
447
|
+
linkLabel="All templates" onOpen={() => navigate(SUBSTRATE_SCREENS.templates.path)}>
|
|
448
|
+
{data?.templates && (!coverageInPart(data.coverage.templates) || data.templates.length > 0)
|
|
449
|
+
? <>{coverageInPart(data.coverage.templates) && <CertaintyGlyph certainty="lower_bound" title="Some templates could not be read" />} {data.templates.length} label-matched</>
|
|
450
|
+
: 'Unknown'}
|
|
451
|
+
</DimensionValue>
|
|
452
|
+
{!!data?.templates?.length && <div className="mt-1 flex flex-wrap gap-1.5">
|
|
453
|
+
{data.templates.map((t) => <button type="button" key={`${t.atespace}/${t.name}`} onClick={() => navigate(substrateTemplatePath(t, connection.context || undefined))} className="btn-secondary px-2 py-0.5 font-mono text-xs">{t.atespace}/{t.name}</button>)}
|
|
454
|
+
</div>}
|
|
455
|
+
</FactRow>
|
|
456
|
+
<FactRow label="Delivery metrics"><CapacityVerdict namespace={namespace} name={name} onOpenMetrics={drawer ? undefined : () => openTab('metrics')} /></FactRow>
|
|
457
|
+
</FactGrid>
|
|
458
|
+
{data && data.coverage.pools.state !== 'full' && <p className="mt-2 text-xs text-theme-text-tertiary">{coverageLabel(data.coverage.pools)}</p>}
|
|
459
|
+
</WorkspaceCard>
|
|
460
|
+
{data && <Placement data={data} drawer={drawer} onOpenActor={openActor} onOpenPod={(w) => onNavigate?.({ kind: 'Pod', namespace: w.namespace, name: w.pod })}
|
|
461
|
+
onOpenNode={onNavigate ? (node) => onNavigate({ kind: 'Node', namespace: '', name: node }) : undefined} />}
|
|
462
|
+
<WorkspaceCard framed={!drawer} title="About"><FactGrid><PoolAbout resource={resource} onNavigate={onNavigate} /></FactGrid></WorkspaceCard>
|
|
463
|
+
<WorkspaceConditions conditions={poolConditions(resource)} title="Sandbox class conditions" sourcePath="status.sandboxClasses[].conditions" framed={!drawer} />
|
|
464
|
+
</div>
|
|
465
|
+
)
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export function PoolHeaderBadge({ resource }: { resource: any }) {
|
|
469
|
+
const namespace: string = resource?.metadata?.namespace ?? ''
|
|
470
|
+
const name: string = resource?.metadata?.name ?? ''
|
|
471
|
+
const query = useSubstratePool(namespace && name ? { namespace, name } : null)
|
|
472
|
+
const code = substrateErrorCode(query.error)
|
|
473
|
+
const data = definitiveFailure(code) || code === 'incomplete' ? undefined : query.data
|
|
474
|
+
if (!data) {
|
|
475
|
+
const k = getWorkerPoolStatus(resource)
|
|
476
|
+
return <span className={clsx('badge whitespace-nowrap', k.color)}>{k.text}</span>
|
|
477
|
+
}
|
|
478
|
+
const r = poolReading(data.pool, data.attention)
|
|
479
|
+
// Kubernetes' phase rides in the tooltip: beside the name it would crowd the title out.
|
|
480
|
+
return (
|
|
481
|
+
<Tooltip content={[r.meaning, r.kubernetes && `Kubernetes: ${r.kubernetes}.`].filter(Boolean).join(' ')}>
|
|
482
|
+
<span><Badge severity={r.severity} size="sm" className="whitespace-nowrap">{r.label}</Badge></span>
|
|
483
|
+
</Tooltip>
|
|
484
|
+
)
|
|
485
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { MemoryRouter } from 'react-router-dom'
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import type { SidebarCategoryWorkspace } from '@skyhook-io/k8s-ui'
|
|
5
|
+
import type { SubstrateWorkspace } from '../../api/substrateWorkspace'
|
|
6
|
+
import type { APIResource } from '../../types'
|
|
7
|
+
import { RadarFeatureUnsupportedError, type RadarFeatureSupport } from '../../api/radarFeatures'
|
|
8
|
+
import { SubstrateScreenGate } from './shared'
|
|
9
|
+
import { AGENTS_SIDEBAR_CATEGORY } from '../workspace/sidebar'
|
|
10
|
+
import { useSubstrateSidebarWorkspace } from './useSubstrateSidebarWorkspace'
|
|
11
|
+
import { notConnectedWorkspace, workspace } from './substrate.fixtures'
|
|
12
|
+
|
|
13
|
+
const state = vi.hoisted(() => ({ support: 'supported' as RadarFeatureSupport, data: undefined as SubstrateWorkspace | undefined }))
|
|
14
|
+
|
|
15
|
+
vi.mock('../../api/client', async (importOriginal) => ({
|
|
16
|
+
...(await importOriginal<typeof import('../../api/client')>()),
|
|
17
|
+
useRadarFeature: () => ({ support: state.support }),
|
|
18
|
+
}))
|
|
19
|
+
vi.mock('../../api/substrateWorkspace', async (importOriginal) => ({
|
|
20
|
+
...(await importOriginal<typeof import('../../api/substrateWorkspace')>()),
|
|
21
|
+
useSubstrateWorkspace: () => ({ data: state.data }),
|
|
22
|
+
}))
|
|
23
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { context: 'kind-demo' } }) }))
|
|
24
|
+
|
|
25
|
+
const substrate: APIResource[] = [{ group: 'ate.dev', version: 'v1alpha1', kind: 'WorkerPool', name: 'workerpools', namespaced: true, isCrd: true, verbs: ['list'] } as unknown as APIResource]
|
|
26
|
+
|
|
27
|
+
function sidebar(apiResources: APIResource[] | undefined = substrate): SidebarCategoryWorkspace | undefined {
|
|
28
|
+
let out: Record<string, SidebarCategoryWorkspace> | undefined
|
|
29
|
+
function Probe() {
|
|
30
|
+
out = useSubstrateSidebarWorkspace({ apiResources, active: 'actors' })
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
renderToStaticMarkup(<MemoryRouter><Probe /></MemoryRouter>)
|
|
34
|
+
return out?.[AGENTS_SIDEBAR_CATEGORY]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('Agent Substrate in the sidebar', () => {
|
|
38
|
+
it('is its part of the Agents row, the tool beneath, opening to its screens and Radar’s pool table', () => {
|
|
39
|
+
state.data = workspace()
|
|
40
|
+
const w = sidebar()!
|
|
41
|
+
// The row is named by the category, "Agents"; the tool sits beneath it.
|
|
42
|
+
expect(w.label).toBeUndefined()
|
|
43
|
+
expect(w.tools).toBe('Agent Substrate')
|
|
44
|
+
expect(w.count).toBe(3)
|
|
45
|
+
expect(w.countTitle).toContain("3 findings need attention in Overview")
|
|
46
|
+
expect(w.destinations.map((d) => d.label)).toEqual(['Overview', 'Actors', 'Templates', 'Workers', 'Pools'])
|
|
47
|
+
expect(new Set(w.destinations.map((d) => d.section))).toEqual(new Set(['Substrate']))
|
|
48
|
+
// The badge counts actors needing attention, as the Actors screen shows them: the fixture's 14 crashed.
|
|
49
|
+
expect(w.destinations.find((d) => d.id === 'actors')).toMatchObject({ active: true, count: 14 })
|
|
50
|
+
// The Pools row is the WorkerPool kind's list, so the kind is not listed again under Other kinds.
|
|
51
|
+
expect(w.destinations.find((d) => d.id === 'pools')?.kind).toEqual({ name: 'workerpools', kind: 'WorkerPool', group: 'ate.dev' })
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('reads unknown counts, not zero, while Substrate’s API is not connected', () => {
|
|
55
|
+
state.data = notConnectedWorkspace()
|
|
56
|
+
const w = sidebar()!
|
|
57
|
+
expect(w.count).toBeNull()
|
|
58
|
+
expect(w.destinations.find((d) => d.id === 'actors')?.count).toBeNull()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('is absent where Substrate is not installed or the Radar predates the views', () => {
|
|
62
|
+
state.data = workspace()
|
|
63
|
+
expect(sidebar([])).toBeUndefined()
|
|
64
|
+
state.support = 'unsupported'
|
|
65
|
+
expect(sidebar()).toBeUndefined()
|
|
66
|
+
state.support = 'supported'
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
describe('Agent Substrate screen gate', () => {
|
|
71
|
+
const ready = { data: undefined as unknown, error: null as unknown, isLoading: false, isFetching: false, refetch: vi.fn(), isRefetchError: false, dataUpdatedAt: 0 }
|
|
72
|
+
const gate = (query: Partial<typeof ready>, discovered = true) =>
|
|
73
|
+
renderToStaticMarkup(
|
|
74
|
+
<SubstrateScreenGate query={{ ...ready, ...query } as never} discoveryPending={false} discovered={discovered}>
|
|
75
|
+
{() => <div>screen</div>}
|
|
76
|
+
</SubstrateScreenGate>,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
it('shows the upgrade note on a Radar that predates the views, a retry for a failed read, and not installed', () => {
|
|
80
|
+
expect(gate({ error: new RadarFeatureUnsupportedError('substrateWorkspace', { currentVersion: 'v1.16.0' }) })).toContain('Agent Substrate needs a newer Radar')
|
|
81
|
+
expect(gate({ error: new Error('boom') })).toContain('Retry')
|
|
82
|
+
expect(gate({}, false)).toContain('Agent Substrate is not installed')
|
|
83
|
+
expect(gate({ data: workspace() })).toContain('screen')
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
it('counts attention actors and templates from the fleet and distinct restarted workers', () => {
|
|
87
|
+
const ws = workspace()
|
|
88
|
+
ws.summary.actors!.attentionCount = 24
|
|
89
|
+
ws.summary.templates!.attentionCount = 5
|
|
90
|
+
ws.needsAttention.push(...['a', 'b'].map((pod) => ({
|
|
91
|
+
id: `workerRestarting:${pod}`, rule: 'workerRestarting' as const, severity: 'critical' as const, count: 3,
|
|
92
|
+
title: 'Restarted', reading: 'Sandboxes lost', nextStep: 'Review recovery',
|
|
93
|
+
subject: { kind: 'Actors' as const, filter: { worker: pod, pool: 'agents/pool', impact: 'restarted' } },
|
|
94
|
+
})))
|
|
95
|
+
ws.needsAttention.push({ ...ws.needsAttention.at(-1)!, id: 'workerDraining:c', rule: 'workerDraining', severity: 'info' })
|
|
96
|
+
state.data = ws
|
|
97
|
+
const destinations = sidebar()!.destinations
|
|
98
|
+
expect(destinations.find((d) => d.id === 'actors')?.count).toBe(24)
|
|
99
|
+
expect(destinations.find((d) => d.id === 'templates')?.count).toBe(5)
|
|
100
|
+
expect(destinations.find((d) => d.id === 'workers')?.count).toBe(2)
|
|
101
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { clsx } from 'clsx'
|
|
2
|
+
import type { SubstrateActorState, SubstrateStateCounts } from '../../api/substrateWorkspace'
|
|
3
|
+
import { ACTOR_STATE_LABEL, actorStateFill, stateBarSegments } from './readings'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The actors by state as one bar: a mark per actor while there are few enough
|
|
7
|
+
* to count, then segments in proportion. The bar is a picture; the legend
|
|
8
|
+
* beneath carries the numbers, and each state opens the actors in it.
|
|
9
|
+
*/
|
|
10
|
+
export function SubstrateStateBar({
|
|
11
|
+
counts,
|
|
12
|
+
onSelectState,
|
|
13
|
+
compact,
|
|
14
|
+
partial,
|
|
15
|
+
}: {
|
|
16
|
+
counts: SubstrateStateCounts
|
|
17
|
+
onSelectState?: (state: SubstrateActorState) => void
|
|
18
|
+
/** A small bar without the legend, for a table cell; its numbers go in the label. */
|
|
19
|
+
compact?: boolean
|
|
20
|
+
partial?: boolean
|
|
21
|
+
}) {
|
|
22
|
+
const { segments, countable } = stateBarSegments(counts)
|
|
23
|
+
const label = segments.map((s) => `${ACTOR_STATE_LABEL[s.state]} ${s.count.toLocaleString('en-US')}`).join(', ')
|
|
24
|
+
if (counts.total === 0) {
|
|
25
|
+
return compact ? <span className="text-theme-text-tertiary">none</span> : <p className="text-sm text-theme-text-tertiary">{partial ? 'No actors observed in the part Radar could read.' : 'No actors.'}</p>
|
|
26
|
+
}
|
|
27
|
+
const bar = (
|
|
28
|
+
<div
|
|
29
|
+
role="img"
|
|
30
|
+
aria-label={`${partial ? 'At least ' : ''}${counts.total.toLocaleString('en-US')} actors: ${label}`}
|
|
31
|
+
className={clsx('flex w-full overflow-hidden rounded', compact ? 'h-1.5 gap-px' : 'h-3', countable && !compact ? 'gap-0.5' : !compact && 'gap-px')}
|
|
32
|
+
>
|
|
33
|
+
{countable && !compact
|
|
34
|
+
? segments.flatMap((s) => Array.from({ length: s.count }, (_, i) => <span key={`${s.state}-${i}`} className={clsx('min-w-0 flex-1 rounded-[2px]', actorStateFill(s.state))} />))
|
|
35
|
+
: segments.map((s) => (
|
|
36
|
+
// A state with a handful of actors among thousands keeps a visible sliver.
|
|
37
|
+
<span key={s.state} style={{ flexGrow: s.share, flexBasis: 0, minWidth: 3 }} className={clsx('h-full', actorStateFill(s.state))} />
|
|
38
|
+
))}
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
if (compact) return bar
|
|
42
|
+
return (
|
|
43
|
+
<div className="space-y-2">
|
|
44
|
+
{bar}
|
|
45
|
+
<ul className="flex flex-wrap gap-x-5 gap-y-1 text-sm" aria-label="Actors by state">
|
|
46
|
+
{segments.map((s) => (
|
|
47
|
+
<li key={s.state} className="flex items-center gap-1.5">
|
|
48
|
+
<span aria-hidden className={clsx('inline-block h-1.5 w-1.5 rounded-full', actorStateFill(s.state))} />
|
|
49
|
+
{onSelectState ? (
|
|
50
|
+
<button type="button" onClick={() => onSelectState(s.state)} className="text-theme-text-secondary hover:text-theme-text-primary hover:underline">
|
|
51
|
+
{ACTOR_STATE_LABEL[s.state]} <span className="font-medium text-theme-text-primary">{partial && '≥'}{s.count.toLocaleString('en-US')}</span>
|
|
52
|
+
</button>
|
|
53
|
+
) : (
|
|
54
|
+
<span className="text-theme-text-secondary">
|
|
55
|
+
{ACTOR_STATE_LABEL[s.state]} <span className="font-medium text-theme-text-primary">{partial && '≥'}{s.count.toLocaleString('en-US')}</span>
|
|
56
|
+
</span>
|
|
57
|
+
)}
|
|
58
|
+
</li>
|
|
59
|
+
))}
|
|
60
|
+
</ul>
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}
|