@skyhook-io/radar-app 1.20.3 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -9
- package/src/App.tsx +67 -15
- package/src/api/client.audit-gating.test.tsx +105 -5
- package/src/api/client.auditBadgesSync.test.tsx +118 -0
- package/src/api/client.capabilitiesPoll.test.ts +61 -0
- package/src/api/client.ts +129 -5
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/radarFeatures.ts +11 -0
- package/src/api/substrateHealth.ts +134 -0
- package/src/api/velero.test.ts +60 -0
- package/src/api/velero.ts +377 -0
- package/src/api/vulnerabilities.ts +313 -0
- package/src/components/NamespaceSwitcher.tsx +3 -1
- package/src/components/audit/AuditView.tsx +4 -0
- package/src/components/audit/ChecksViewTabs.test.tsx +35 -5
- package/src/components/audit/ChecksViewTabs.tsx +12 -1
- package/src/components/audit/Java4ShellPanel.test.tsx +31 -0
- package/src/components/audit/Java4ShellPanel.tsx +313 -0
- package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
- package/src/components/audit/UpgradeReadinessView.tsx +60 -2
- package/src/components/audit/VulnerabilitiesView.tsx +944 -0
- package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
- package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
- package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
- package/src/components/cnpg/CNPGView.tsx +43 -117
- package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
- package/src/components/cnpg/host.tsx +2 -2
- package/src/components/cnpg/routes.ts +3 -1
- package/src/components/cnpg/shared.tsx +5 -53
- package/src/components/cnpg/useCNPGNavigate.ts +1 -21
- package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
- package/src/components/community.tsx +42 -0
- package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
- package/src/components/diagnose/investigationMetrics.test.ts +20 -0
- package/src/components/diagnose/investigationMetrics.ts +2 -1
- package/src/components/dock/BottomDock.tsx +1 -0
- package/src/components/dock/LogsTab.tsx +3 -0
- package/src/components/gitops/FluxOperatorCard.test.tsx +37 -0
- package/src/components/gitops/FluxOperatorCard.tsx +27 -0
- package/src/components/gitops/GitOpsView.rowsSummary.test.tsx +59 -0
- package/src/components/gitops/GitOpsView.tsx +8 -5
- package/src/components/gitops/gitopsRowEvents.test.ts +48 -0
- package/src/components/gitops/gitopsRowEvents.ts +31 -0
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmView.tsx +20 -16
- package/src/components/helm/OwnedResources.tsx +4 -3
- package/src/components/home/ClusterHealthCard.tsx +3 -1
- package/src/components/home/HomeAgentBlock.tsx +3 -0
- package/src/components/home/HomeView.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +19 -12
- package/src/components/home/MCPSetupDialog.tsx +4 -2
- package/src/components/home/mcpToolCatalog.ts +15 -2
- package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
- package/src/components/home/useVulnerabilitiesRow.ts +50 -0
- package/src/components/logs/LogsViewer.tsx +3 -1
- package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
- package/src/components/logs/MultiPodLogsTab.tsx +9 -5
- package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
- package/src/components/nav/PrimaryNavRail.tsx +174 -29
- package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
- package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
- package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
- package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
- package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
- package/src/components/resources/ResourcesView.tsx +12 -6
- package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
- package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
- package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
- package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +3 -2
- package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
- package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
- package/src/components/timeline/TimelineView.tsx +3 -1
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
- package/src/components/traffic/TrafficData.test.tsx +37 -0
- package/src/components/traffic/TrafficData.tsx +27 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -7
- package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
- package/src/components/traffic/TrafficGraph.test.tsx +269 -0
- package/src/components/traffic/TrafficGraph.tsx +135 -64
- package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
- package/src/components/traffic/TrafficView.tsx +46 -129
- package/src/components/traffic/trafficFilters.test.ts +172 -1
- package/src/components/traffic/trafficFilters.ts +139 -0
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +31 -2
- package/src/components/ui/UpdateNotification.tsx +34 -17
- package/src/components/ui/command-items.ts +24 -1
- package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
- package/src/components/velero/VeleroBackupNow.tsx +143 -0
- package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
- package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
- package/src/components/velero/VeleroDetailPage.tsx +158 -0
- package/src/components/velero/VeleroKindLists.test.tsx +48 -0
- package/src/components/velero/VeleroKindLists.tsx +43 -0
- package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
- package/src/components/velero/VeleroLocations.test.tsx +86 -0
- package/src/components/velero/VeleroLocations.tsx +240 -0
- package/src/components/velero/VeleroOverview.test.tsx +311 -0
- package/src/components/velero/VeleroOverview.tsx +485 -0
- package/src/components/velero/VeleroPages.test.tsx +516 -0
- package/src/components/velero/VeleroPages.tsx +1056 -0
- package/src/components/velero/VeleroRunArtifacts.test.tsx +241 -0
- package/src/components/velero/VeleroRunArtifacts.tsx +112 -0
- package/src/components/velero/VeleroRunLists.tsx +309 -0
- package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
- package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
- package/src/components/velero/VeleroRunVolumes.test.tsx +247 -0
- package/src/components/velero/VeleroRunVolumes.tsx +122 -0
- package/src/components/velero/VeleroSchedulePause.test.tsx +211 -0
- package/src/components/velero/VeleroSchedulePause.tsx +191 -0
- package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
- package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
- package/src/components/velero/VeleroSchedules.tsx +255 -0
- package/src/components/velero/VeleroView.tsx +59 -0
- package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
- package/src/components/velero/attention.test.ts +178 -0
- package/src/components/velero/attention.ts +281 -0
- package/src/components/velero/backupDelete.test.tsx +91 -0
- package/src/components/velero/backupDelete.tsx +182 -0
- package/src/components/velero/coverage.test.ts +87 -0
- package/src/components/velero/coverage.ts +150 -0
- package/src/components/velero/host.tsx +92 -0
- package/src/components/velero/routes.ts +78 -0
- package/src/components/velero/runs.tsx +121 -0
- package/src/components/velero/shared.test.ts +84 -0
- package/src/components/velero/shared.tsx +423 -0
- package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
- package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
- package/src/components/velero/velero.fixtures.ts +61 -0
- package/src/components/velero/workspaceRoute.ts +21 -0
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +179 -0
- package/src/components/vulnerabilities/parts.test.ts +72 -0
- package/src/components/vulnerabilities/parts.tsx +291 -0
- package/src/components/whats-new/WhatsNewDialog.test.tsx +6 -4
- package/src/components/whats-new/releaseNotes.ts +67 -1
- package/src/components/workload/WorkloadView.tsx +64 -27
- package/src/components/workspace/DrawerTrailBack.tsx +32 -0
- package/src/components/workspace/WorkspaceFrame.tsx +71 -0
- package/src/components/workspace/coverage.ts +61 -0
- package/src/components/workspace/layout.test.tsx +29 -1
- package/src/components/workspace/layout.tsx +15 -5
- package/src/components/workspace/sidebar.ts +9 -0
- package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
- package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
- package/src/desktop/AboutDialog.test.ts +12 -0
- package/src/desktop/AboutDialog.tsx +151 -0
- package/src/desktop/WindowsTitleBar.tsx +359 -0
- package/src/desktop/titleBar.test.ts +61 -0
- package/src/desktop/titleBar.ts +45 -0
- package/src/index.css +19 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +14 -2
- package/src/integrations/resourceHosts.tsx +22 -6
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.test.ts +11 -0
- package/src/integrations/workspaceRoutes.ts +3 -1
- package/src/integrations/workspaceScreens.tsx +2 -0
- package/src/main.tsx +8 -0
- package/src/utils/desktop-zoom.test.ts +53 -0
- package/src/utils/desktop-zoom.ts +30 -0
- package/src/utils/staleAssetPrompt.test.tsx +76 -0
- package/src/utils/staleAssetPrompt.tsx +32 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { Info, LineChart, Loader2, Lock, Wifi } from 'lucide-react'
|
|
2
|
+
import { clsx } from 'clsx'
|
|
3
|
+
import { AlertBanner, RadarUpgradeNote, Section, Tooltip, toneTextClass } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { AreaChart, SeriesLegend, formatMetricValue, formatTimestamp, type TimeSeries, type TimeSeriesPoint } from '@skyhook-io/k8s-ui/components/charts'
|
|
5
|
+
import { isForbiddenError, useAutoPromConnect, usePrometheusConnect, usePrometheusStatus } from '../../api/client'
|
|
6
|
+
import { SUBSTRATE_RANGE, useSubstrateHealth, type SubstrateChart, type SubstrateHealth, type SubstrateTarget } from '../../api/substrateHealth'
|
|
7
|
+
|
|
8
|
+
const NO_WORKERS = 'The controller reports 0 worker Pods for this pool, and Prometheus has no Agent Substrate metrics for it.'
|
|
9
|
+
|
|
10
|
+
const NOT_FOUND = {
|
|
11
|
+
workerpool: 'Prometheus has no Agent Substrate metrics for this pool. Radar reads them under the underscore names Substrate\'s exporter gives them by default (ate_workerpool_workers) or the dotted ones Google Managed Prometheus keeps (ate.workerpool.workers); native histograms are not read.',
|
|
12
|
+
node: '',
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Agent Substrate charts for one WorkerPool or Node, from the curated
|
|
17
|
+
* /prometheus/substrate endpoints. Aggregates only: Substrate keeps actor
|
|
18
|
+
* identity out of metric labels. Hidden on a Node that runs no Substrate, and
|
|
19
|
+
* when Prometheus is not connected unless standalone (the only content of its
|
|
20
|
+
* tab), which offers to connect; every other state says why there is no chart.
|
|
21
|
+
*/
|
|
22
|
+
export function SubstrateHealthCharts({ target, standalone = false, collapsible = true, workerPods }: {
|
|
23
|
+
target: SubstrateTarget
|
|
24
|
+
standalone?: boolean
|
|
25
|
+
collapsible?: boolean
|
|
26
|
+
/** A WorkerPool's status.replicas, when the caller has it: with none, the empty charts need no metric-naming hint. */
|
|
27
|
+
workerPods?: number
|
|
28
|
+
}) {
|
|
29
|
+
useAutoPromConnect()
|
|
30
|
+
const { data: status } = usePrometheusStatus()
|
|
31
|
+
const connect = usePrometheusConnect()
|
|
32
|
+
const connected = status?.connected === true
|
|
33
|
+
const { data, error, upgrade, blockedReason, support } = useSubstrateHealth(target, connected && Boolean(target.name))
|
|
34
|
+
|
|
35
|
+
if (!connected) {
|
|
36
|
+
if (!standalone || !status) return null
|
|
37
|
+
return (
|
|
38
|
+
<Frame collapsible={collapsible}>
|
|
39
|
+
<Muted>{status.discovering ? 'Discovering Prometheus…' : status.error || 'Connect Prometheus to chart this pool\'s workers, resumes and crashes.'}</Muted>
|
|
40
|
+
{!status.discovering && (
|
|
41
|
+
<button type="button" onClick={() => connect.mutate()} disabled={connect.isPending} className="btn-brand mt-3 inline-flex items-center gap-2 rounded-lg px-3 py-1.5 text-xs font-medium">
|
|
42
|
+
{connect.isPending ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Wifi className="h-3.5 w-3.5" />}
|
|
43
|
+
Discover Prometheus
|
|
44
|
+
</button>
|
|
45
|
+
)}
|
|
46
|
+
</Frame>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
if (upgrade && target.kind === 'workerpool') {
|
|
50
|
+
return <Frame collapsible={collapsible}><RadarUpgradeNote requirement={upgrade} /></Frame>
|
|
51
|
+
}
|
|
52
|
+
// Until this Radar is known to serve the charts, the query never runs.
|
|
53
|
+
if (!data && support !== 'supported' && blockedReason && target.kind === 'workerpool') {
|
|
54
|
+
return <Frame collapsible={collapsible}><Muted>{blockedReason}</Muted></Frame>
|
|
55
|
+
}
|
|
56
|
+
if (isForbiddenError(error)) {
|
|
57
|
+
return (
|
|
58
|
+
<Frame collapsible={collapsible}>
|
|
59
|
+
<AlertBanner
|
|
60
|
+
variant="info"
|
|
61
|
+
icon={Lock}
|
|
62
|
+
title="You don't have access to these metrics"
|
|
63
|
+
message={target.kind === 'workerpool'
|
|
64
|
+
? 'Agent Substrate charts are available to users who can read this WorkerPool.'
|
|
65
|
+
: 'Agent Substrate charts for a node are available to users who can read Nodes.'}
|
|
66
|
+
/>
|
|
67
|
+
</Frame>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
if (error) {
|
|
71
|
+
return <Frame collapsible={collapsible}><Muted tone="warning">Agent Substrate metrics could not be read: {error.message}</Muted></Frame>
|
|
72
|
+
}
|
|
73
|
+
if (!data) return null
|
|
74
|
+
|
|
75
|
+
switch (data.status) {
|
|
76
|
+
case 'notOnNode':
|
|
77
|
+
return null
|
|
78
|
+
case 'notFound':
|
|
79
|
+
if (target.kind !== 'workerpool') return null
|
|
80
|
+
return <Frame collapsible={collapsible}><Muted>{workerPods === 0 ? NO_WORKERS : NOT_FOUND.workerpool}</Muted></Frame>
|
|
81
|
+
case 'notAttributable':
|
|
82
|
+
case 'error':
|
|
83
|
+
return <Frame collapsible={collapsible}><Muted tone={data.status === 'error' ? 'warning' : undefined}>{data.reason}</Muted></Frame>
|
|
84
|
+
}
|
|
85
|
+
return <Frame collapsible={collapsible}><Charts health={data} /></Frame>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A section like its neighbours, not a card: the charts are the only cards.
|
|
89
|
+
// Collapsible among the drawer's sections; a plain heading on a Metrics tab,
|
|
90
|
+
// where collapsing it would only empty the tab.
|
|
91
|
+
function Frame({ children, collapsible }: { children: React.ReactNode; collapsible: boolean }) {
|
|
92
|
+
const title = `Agent Substrate · last ${SUBSTRATE_RANGE}`
|
|
93
|
+
return (
|
|
94
|
+
<section aria-label="Agent Substrate metrics">
|
|
95
|
+
{collapsible ? (
|
|
96
|
+
<Section title={title} icon={LineChart}>{children}</Section>
|
|
97
|
+
) : (
|
|
98
|
+
<>
|
|
99
|
+
<h3 className="mb-2 flex items-center gap-2 text-sm font-medium text-theme-text-secondary">
|
|
100
|
+
<LineChart className="h-4 w-4" />
|
|
101
|
+
{title}
|
|
102
|
+
</h3>
|
|
103
|
+
{children}
|
|
104
|
+
</>
|
|
105
|
+
)}
|
|
106
|
+
</section>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Averaged worker counts can be fractional; their axis stays on whole numbers.
|
|
111
|
+
function chartUnit(unit: string): string {
|
|
112
|
+
return unit === 'workers' ? 'avgCount' : unit
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function Muted({ children, tone }: { children: React.ReactNode; tone?: 'warning' }) {
|
|
116
|
+
return <p className={clsx('text-xs', tone === 'warning' ? toneTextClass('degraded') : 'text-theme-text-tertiary')}>{children}</p>
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function Charts({ health }: { health: SubstrateHealth }) {
|
|
120
|
+
const unverified = health.charts.find(c => c.state === 'ok' && c.isolation.mode === 'unverified')
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
<p className="mb-3 text-xs text-theme-text-tertiary">
|
|
124
|
+
Aggregates: Substrate keeps actor names out of its metrics.
|
|
125
|
+
</p>
|
|
126
|
+
<div className="grid grid-cols-1 gap-3">
|
|
127
|
+
{groupCharts(health.charts).map(group => group.length === 1
|
|
128
|
+
? <Chart key={group[0].id} chart={group[0]} health={health} />
|
|
129
|
+
: <SharedReason key={group[0].id} charts={group} />)}
|
|
130
|
+
</div>
|
|
131
|
+
{unverified && <p className="mt-3 text-xs text-theme-text-tertiary">{unverified.isolation.note}.</p>}
|
|
132
|
+
</>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Charts that cannot be drawn for the same reason share one note instead of
|
|
137
|
+
// repeating it card after card.
|
|
138
|
+
function groupCharts(charts: SubstrateChart[]): SubstrateChart[][] {
|
|
139
|
+
const groups: SubstrateChart[][] = []
|
|
140
|
+
const byReason = new Map<string, SubstrateChart[]>()
|
|
141
|
+
for (const chart of charts) {
|
|
142
|
+
if (chart.state === 'ok') {
|
|
143
|
+
groups.push([chart])
|
|
144
|
+
continue
|
|
145
|
+
}
|
|
146
|
+
const key = `${chart.state}\u0000${chart.reason ?? ''}`
|
|
147
|
+
const group = byReason.get(key)
|
|
148
|
+
if (group) {
|
|
149
|
+
group.push(chart)
|
|
150
|
+
} else {
|
|
151
|
+
const created = [chart]
|
|
152
|
+
byReason.set(key, created)
|
|
153
|
+
groups.push(created)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return groups
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function SharedReason({ charts }: { charts: SubstrateChart[] }) {
|
|
160
|
+
return (
|
|
161
|
+
<section className="rounded-lg border border-theme-border bg-theme-surface/30 p-3 min-w-0">
|
|
162
|
+
<h4 className="mb-1 text-xs font-medium text-theme-text-secondary">{charts.map(c => c.title).join(' · ')}</h4>
|
|
163
|
+
<Muted tone={charts[0].state === 'empty' || charts[0].state === 'noSeries' ? undefined : 'warning'}>{chartReason(charts[0])}</Muted>
|
|
164
|
+
</section>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function Chart({ chart, health }: { chart: SubstrateChart; health: SubstrateHealth }) {
|
|
169
|
+
const series = chart.series
|
|
170
|
+
const seriesLabels = series.map(s => s.labels.series || chart.title)
|
|
171
|
+
// Only a sample from the last two steps is "now"; an older one ended earlier in the range.
|
|
172
|
+
const since = health.end - 2 * health.stepSeconds
|
|
173
|
+
const unit = chartUnit(chart.unit)
|
|
174
|
+
const latest = chart.state === 'ok' && series.length === 1 ? lastValue(series[0].dataPoints, since) : undefined
|
|
175
|
+
// Each line's latest value sits in its legend entry: lines that share a
|
|
176
|
+
// value hide one another on the plot.
|
|
177
|
+
const legendValues = series.map(s => {
|
|
178
|
+
const v = lastValue(s.dataPoints, since)
|
|
179
|
+
return v === undefined ? undefined : formatMetricValue(v, unit)
|
|
180
|
+
})
|
|
181
|
+
const lateStart = chart.state === 'ok' ? lateFirstSample(series, health) : undefined
|
|
182
|
+
return (
|
|
183
|
+
<section className="rounded-lg border border-theme-border bg-theme-surface/30 p-3 flex flex-col min-w-0">
|
|
184
|
+
<header className="flex items-baseline justify-between gap-2 mb-1">
|
|
185
|
+
<h4 className="flex items-center gap-1 text-xs font-medium text-theme-text-secondary">
|
|
186
|
+
{chart.title}
|
|
187
|
+
<Tooltip content={`${chart.population} Source: ${chart.source}.`}>
|
|
188
|
+
<Info className="w-3 h-3 text-theme-text-tertiary" aria-label={`About ${chart.title}`} />
|
|
189
|
+
</Tooltip>
|
|
190
|
+
</h4>
|
|
191
|
+
{latest !== undefined && (
|
|
192
|
+
<span className="text-sm font-semibold tabular-nums text-theme-text-primary">{formatMetricValue(latest, unit)}</span>
|
|
193
|
+
)}
|
|
194
|
+
</header>
|
|
195
|
+
{chart.state === 'ok' ? (
|
|
196
|
+
<>
|
|
197
|
+
<AreaChart
|
|
198
|
+
series={series}
|
|
199
|
+
unit={unit}
|
|
200
|
+
color="var(--accent)"
|
|
201
|
+
fillColor="var(--accent-muted)"
|
|
202
|
+
layout="dashboard"
|
|
203
|
+
height={140}
|
|
204
|
+
seriesLabels={seriesLabels}
|
|
205
|
+
domain={{ start: health.start, end: health.end }}
|
|
206
|
+
stepSeconds={health.stepSeconds}
|
|
207
|
+
/>
|
|
208
|
+
{series.length > 1 && <SeriesLegend series={series} color="var(--accent)" seriesLabels={seriesLabels} values={legendValues} />}
|
|
209
|
+
{lateStart !== undefined && <Muted>No samples before {formatTimestamp(lateStart)}.</Muted>}
|
|
210
|
+
{chart.omitted ? <Muted>{chart.omitted} more series not shown.</Muted> : null}
|
|
211
|
+
{chart.reason ? <Muted>{capitalize(chart.reason)}.</Muted> : null}
|
|
212
|
+
</>
|
|
213
|
+
) : (
|
|
214
|
+
<Muted tone={chart.state === 'empty' || chart.state === 'noSeries' ? undefined : 'warning'}>{chartReason(chart)}</Muted>
|
|
215
|
+
)}
|
|
216
|
+
</section>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function capitalize(text: string): string {
|
|
221
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function chartReason(chart: SubstrateChart): string {
|
|
225
|
+
const reason = chart.reason ?? ''
|
|
226
|
+
switch (chart.state) {
|
|
227
|
+
case 'empty':
|
|
228
|
+
return `No data: ${reason}.`
|
|
229
|
+
case 'noSeries':
|
|
230
|
+
return `Not reported: ${reason}.`
|
|
231
|
+
default:
|
|
232
|
+
return `Not shown: ${reason}.`
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// The first sample, when it comes well after the range starts: a mostly empty
|
|
237
|
+
// plot otherwise reads as a broken chart. It says when samples begin, not why.
|
|
238
|
+
function lateFirstSample(series: TimeSeries[], health: SubstrateHealth): number | undefined {
|
|
239
|
+
let first: number | undefined
|
|
240
|
+
for (const s of series) {
|
|
241
|
+
const p = s.dataPoints.find(d => d.value != null && Number.isFinite(d.value))
|
|
242
|
+
if (p && (first === undefined || p.timestamp < first)) first = p.timestamp
|
|
243
|
+
}
|
|
244
|
+
const gap = Math.max(2 * health.stepSeconds, (health.end - health.start) / 10)
|
|
245
|
+
return first !== undefined && first - health.start > gap ? first : undefined
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function lastValue(points: TimeSeriesPoint[], since: number): number | undefined {
|
|
249
|
+
for (let i = points.length - 1; i >= 0 && points[i].timestamp >= since; i--) {
|
|
250
|
+
const v = points[i].value
|
|
251
|
+
if (v != null && Number.isFinite(v)) return v
|
|
252
|
+
}
|
|
253
|
+
return undefined
|
|
254
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import type { SubstrateFact, SubstrateHealth, SubstrateVerdict } from '../../api/substrateHealth'
|
|
4
|
+
|
|
5
|
+
let health: { data?: SubstrateHealth; error?: Error } = {}
|
|
6
|
+
let connected = true
|
|
7
|
+
|
|
8
|
+
// Tooltips render their content on hover; the mock puts it in the markup.
|
|
9
|
+
vi.mock('@skyhook-io/k8s-ui', async (orig) => ({
|
|
10
|
+
...(await orig<typeof import('@skyhook-io/k8s-ui')>()),
|
|
11
|
+
Tooltip: ({ content, children }: { content: string; children: React.ReactNode }) => <span data-tooltip={content}>{children}</span>,
|
|
12
|
+
}))
|
|
13
|
+
vi.mock('../../api/client', async (orig) => ({
|
|
14
|
+
...(await orig<typeof import('../../api/client')>()),
|
|
15
|
+
usePrometheusStatus: () => ({ data: { connected } }),
|
|
16
|
+
}))
|
|
17
|
+
vi.mock('../../api/substrateHealth', async (orig) => ({
|
|
18
|
+
...(await orig<typeof import('../../api/substrateHealth')>()),
|
|
19
|
+
useSubstrateHealth: () => health,
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
const { SubstrateVerdictLine } = await import('./SubstrateVerdictLine')
|
|
23
|
+
|
|
24
|
+
const pool = { kind: 'workerpool' as const, namespace: 'agents', name: 'pool' }
|
|
25
|
+
const node = { kind: 'node' as const, name: 'worker-1' }
|
|
26
|
+
const base = { range: '1h', start: 1000, end: 4600, stepSeconds: 60, charts: [] }
|
|
27
|
+
|
|
28
|
+
function withVerdict(verdict: SubstrateVerdict, status: SubstrateHealth['status'] = 'available') {
|
|
29
|
+
health = { data: { ...base, status, verdict } }
|
|
30
|
+
}
|
|
31
|
+
const render = (target: typeof pool | typeof node) => renderToStaticMarkup(<SubstrateVerdictLine target={target} onOpenMetrics={() => {}} />)
|
|
32
|
+
const ok = (id: string, label: string, unit: SubstrateFact['unit'], value: number, extra: Partial<SubstrateFact> = {}): SubstrateFact => ({ id, label, unit, state: 'ok', value, ...extra })
|
|
33
|
+
|
|
34
|
+
describe('SubstrateVerdictLine', () => {
|
|
35
|
+
it('flags a pool short of workers in amber and keeps its facts uncolored', () => {
|
|
36
|
+
withVerdict({ state: 'workerShortfall', facts: [ok('schedulableWorkers', 'Schedulable workers', 'workers', 4, { of: 6 }), ok('workersWithFreeActorSlots', 'Workers with free slots', 'workers', 0, { of: 3 })] })
|
|
37
|
+
const html = render(pool)
|
|
38
|
+
// Titled for a reader who has never heard of Substrate, with what the state means.
|
|
39
|
+
expect(html).toContain('Agent Substrate capacity')
|
|
40
|
+
expect(html).toContain('Short of workers')
|
|
41
|
+
expect(html).toContain('stayed that way for five minutes')
|
|
42
|
+
expect(html).toMatch(/bg-amber-100/)
|
|
43
|
+
expect(html).toMatch(/Schedulable workers<\/span>.*?4 of 6 desired/)
|
|
44
|
+
expect(html).toContain('0 of 3')
|
|
45
|
+
expect(html).toContain('View metrics')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('reads full as neutral and free slots as plain text', () => {
|
|
49
|
+
withVerdict({ state: 'noFreeActorSlots', facts: [] })
|
|
50
|
+
expect(render(pool)).toContain('bg-theme-hover/50')
|
|
51
|
+
withVerdict({ state: 'freeActorSlots', facts: [] })
|
|
52
|
+
const html = render(pool)
|
|
53
|
+
expect(html).toContain('Free slots')
|
|
54
|
+
expect(html).not.toMatch(/bg-amber|bg-red|bg-emerald/)
|
|
55
|
+
expect(html).not.toContain('aria-label="Qualified"')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('says an unjudged shortfall in the section and marks an unconfirmed cluster', () => {
|
|
59
|
+
withVerdict({ state: 'freeActorSlots', reason: "Radar cannot tell whether the pool is short of workers: Substrate's controller reported no desired worker count", facts: [] })
|
|
60
|
+
// Every pool on Substrate's default install: said in plain view, not only on hover.
|
|
61
|
+
expect(render(pool)).toContain('Radar cannot tell whether the pool is short of workers')
|
|
62
|
+
expect(render(pool)).not.toContain('aria-label="Qualified"')
|
|
63
|
+
const unverified = { isolation: { mode: 'unverified' as const, note: "Radar couldn't confirm these Substrate series belong to this exact cluster" } }
|
|
64
|
+
health = { data: { ...base, status: 'available', verdict: { state: 'noFreeActorSlots', facts: [] }, charts: [{ id: 'workers', title: '', unit: 'workers', population: '', source: '', state: 'ok', series: [], ...unverified }] } }
|
|
65
|
+
expect(render(pool)).toContain('aria-label="Qualified"')
|
|
66
|
+
// An unconfirmed cluster alone says nothing about the shortfall.
|
|
67
|
+
expect(render(pool)).not.toContain('cannot tell whether the pool is short')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('shows fractional replica averages as approximate, never rounded', () => {
|
|
71
|
+
withVerdict({ state: 'freeActorSlots', facts: [ok('workersWithFreeActorSlots', 'Workers with free slots', 'workers', 1.5, { of: 4 }), ok('crashes', 'Crashes', 'count', 2.4)] })
|
|
72
|
+
const html = render(pool)
|
|
73
|
+
expect(html).toContain('≈1.5 of 4')
|
|
74
|
+
expect(html).toContain('Crashes (1h)')
|
|
75
|
+
expect(html).toContain('≈2.4')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('says an hourly fact covers only the data Prometheus collected', () => {
|
|
79
|
+
withVerdict({ state: 'freeActorSlots', facts: [ok('crashes', 'Crashes', 'count', 0), ok('workersWithFreeActorSlots', 'Workers with free slots', 'workers', 2, { of: 4 })] })
|
|
80
|
+
const html = render(pool)
|
|
81
|
+
expect(html).toMatch(/data-tooltip="Computed from the data Prometheus holds for the last hour[^"]*"><span>Crashes \(1h\)/)
|
|
82
|
+
expect(html).not.toMatch(/data-tooltip="[^"]*last hour[^"]*"><span>Workers with free slots/)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('says Unavailable, never 0, for a fact Radar could not read, and None for one with nothing recorded', () => {
|
|
86
|
+
withVerdict({ state: 'unknown', reason: 'reported through more than one scrape job', facts: [
|
|
87
|
+
{ id: 'workersWithFreeActorSlots', label: 'Workers with free slots', unit: 'workers', state: 'unavailable', reason: 'reported through more than one scrape job' },
|
|
88
|
+
{ id: 'resumeP95', label: 'Resume p95', unit: 'seconds', state: 'empty', reason: 'no actor resumed on this pool in this range' },
|
|
89
|
+
] })
|
|
90
|
+
const html = render(pool)
|
|
91
|
+
expect(html).toContain('Unknown')
|
|
92
|
+
expect(html).toContain('Unavailable')
|
|
93
|
+
expect(html).toContain('None')
|
|
94
|
+
expect(html.replace(/<[^>]+>/g, ' ')).toMatch(/Workers with free slots\s+Unavailable/)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('names overdue bands on a node, worst first', () => {
|
|
98
|
+
withVerdict({ state: 'uploadsOverdue', facts: [ok('overdueUploads', 'Overdue uploads', 'count', 3, { parts: [{ label: 'over_15m', value: 1 }, { label: '1m_to_5m', value: 2 }] })] })
|
|
99
|
+
const html = render(node)
|
|
100
|
+
expect(html).toContain('Agent Substrate snapshots')
|
|
101
|
+
expect(html).toContain('Uploads overdue')
|
|
102
|
+
expect(html).toContain('overdue for upload to object storage')
|
|
103
|
+
expect(html).toContain('3 (over 15m: 1, 1–5m: 2)')
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('does not keep asserting a cached verdict after a failed refresh or a disconnect', () => {
|
|
107
|
+
withVerdict({ state: 'freeActorSlots', facts: [] })
|
|
108
|
+
health = { ...health, error: new Error('timeout') }
|
|
109
|
+
const html = render(pool)
|
|
110
|
+
expect(html).toContain('Unknown')
|
|
111
|
+
expect(html).not.toContain('Free slots')
|
|
112
|
+
health = { data: health.data }
|
|
113
|
+
connected = false
|
|
114
|
+
expect(render(pool)).toBe('')
|
|
115
|
+
connected = true
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('claims no more than the overdue count proves on a node', () => {
|
|
119
|
+
withVerdict({ state: 'noUploadsOverdue', facts: [] })
|
|
120
|
+
const html = render(node)
|
|
121
|
+
expect(html).toContain('No overdue uploads')
|
|
122
|
+
expect(html).not.toContain('Up to date')
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('renders nothing without a verdict', () => {
|
|
126
|
+
health = { data: { ...base, status: 'notFound' } }
|
|
127
|
+
expect(render(pool)).toBe('')
|
|
128
|
+
health = {}
|
|
129
|
+
expect(render(pool)).toBe('')
|
|
130
|
+
})
|
|
131
|
+
})
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { CloudUpload, Gauge, Info } from 'lucide-react'
|
|
2
|
+
import { Badge, Property, PropertyList, Section, Tooltip } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { formatMetricValue } from '@skyhook-io/k8s-ui/components/charts'
|
|
4
|
+
import { isForbiddenError, usePrometheusStatus } from '../../api/client'
|
|
5
|
+
import { useSubstrateHealth, type SubstrateFact, type SubstrateTarget, type SubstrateVerdict } from '../../api/substrateHealth'
|
|
6
|
+
|
|
7
|
+
const OVERDUE_BANDS: Record<string, string> = {
|
|
8
|
+
under_1m: 'under 1m',
|
|
9
|
+
'1m_to_5m': '1–5m',
|
|
10
|
+
'5m_to_15m': '5–15m',
|
|
11
|
+
over_15m: 'over 15m',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A section at the top of the Overview tab that judges a WorkerPool's
|
|
16
|
+
* capacity, or a Node's snapshot uploads, from the same response as the
|
|
17
|
+
* Metrics tab's charts. A Node is a generic page whose readers may never have
|
|
18
|
+
* heard of Agent Substrate, so the title names it and a sentence says what the
|
|
19
|
+
* state means. Shown only when there is a verdict to read; the charts explain
|
|
20
|
+
* every other state. onOpenMetrics switches to a Metrics tab; without one (the
|
|
21
|
+
* drawer, which shows the charts below), the link scrolls to them.
|
|
22
|
+
*/
|
|
23
|
+
export function SubstrateVerdictLine({ target, onOpenMetrics }: { target: SubstrateTarget; onOpenMetrics?: () => void }) {
|
|
24
|
+
const { data: status } = usePrometheusStatus()
|
|
25
|
+
const connected = status?.connected === true
|
|
26
|
+
const { data, error } = useSubstrateHealth(target, connected && Boolean(target.name))
|
|
27
|
+
// A failed refresh leaves the last answer cached; it must not keep asserting it.
|
|
28
|
+
const verdict: SubstrateVerdict | undefined = !connected || isForbiddenError(error)
|
|
29
|
+
? undefined
|
|
30
|
+
: error
|
|
31
|
+
? { state: 'unknown', reason: `Radar could not read Prometheus: ${error.message}`, facts: [] }
|
|
32
|
+
: data?.status === 'available' ? data.verdict : undefined
|
|
33
|
+
if (!verdict) return null
|
|
34
|
+
const pool = target.kind === 'workerpool'
|
|
35
|
+
const title = pool ? 'Agent Substrate capacity' : 'Agent Substrate snapshots'
|
|
36
|
+
// A pool's only qualifier is a shortfall that could not be judged. On
|
|
37
|
+
// Substrate's default install that is every pool, so it is said in the
|
|
38
|
+
// section, not only in a tooltip.
|
|
39
|
+
const qualifier = verdict.state !== 'unknown' ? verdict.reason : undefined
|
|
40
|
+
// Series Radar could not tie to this cluster.
|
|
41
|
+
const unverified = error ? undefined : data?.charts.find(c => c.state === 'ok' && c.isolation.mode === 'unverified')?.isolation.note
|
|
42
|
+
return (
|
|
43
|
+
<section aria-label={title}>
|
|
44
|
+
<Section title={title} icon={pool ? Gauge : CloudUpload}>
|
|
45
|
+
<div className="space-y-3 text-sm">
|
|
46
|
+
<div className="flex items-start gap-2">
|
|
47
|
+
<span className="shrink-0 pt-px"><VerdictState verdict={verdict} /></span>
|
|
48
|
+
<div className="min-w-0 space-y-1">
|
|
49
|
+
<p className="text-theme-text-secondary">
|
|
50
|
+
{meaning(verdict, pool)}
|
|
51
|
+
{unverified && (
|
|
52
|
+
<Tooltip content={sentence(unverified)}>
|
|
53
|
+
<Info aria-label="Qualified" className="ml-1 inline h-3.5 w-3.5 align-[-2px] text-theme-text-tertiary" />
|
|
54
|
+
</Tooltip>
|
|
55
|
+
)}
|
|
56
|
+
</p>
|
|
57
|
+
{qualifier && <p className="text-xs text-theme-text-tertiary">{sentence(qualifier)}</p>}
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
{verdict.facts.length > 0 && (
|
|
61
|
+
<PropertyList>
|
|
62
|
+
{verdict.facts.map(f => <Fact key={f.id} fact={f} />)}
|
|
63
|
+
</PropertyList>
|
|
64
|
+
)}
|
|
65
|
+
<button type="button" onClick={e => (onOpenMetrics ? onOpenMetrics() : scrollToCharts(e.currentTarget))} className="text-xs text-theme-text-tertiary underline-offset-2 hover:text-theme-text-primary hover:underline">
|
|
66
|
+
View metrics
|
|
67
|
+
</button>
|
|
68
|
+
</div>
|
|
69
|
+
</Section>
|
|
70
|
+
</section>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const sentence = (s: string) => (s.endsWith('.') ? s : `${s}.`)
|
|
75
|
+
|
|
76
|
+
// What the state means, in the reader's terms. Claims only what the count
|
|
77
|
+
// proves: a free slot is not proof the next actor fits, and zero overdue
|
|
78
|
+
// uploads is not proof every snapshot is saved.
|
|
79
|
+
function meaning(verdict: SubstrateVerdict, pool: boolean): string {
|
|
80
|
+
switch (verdict.state) {
|
|
81
|
+
case 'workerShortfall':
|
|
82
|
+
return 'Fewer workers can take actors than the pool wants, and it has stayed that way for five minutes. New and resuming actors may wait or fail to start.'
|
|
83
|
+
case 'noFreeActorSlots':
|
|
84
|
+
return 'No worker in this pool has a free actor slot. Actor starts and resumes may wait or fail until there is capacity.'
|
|
85
|
+
case 'noSchedulableWorkers':
|
|
86
|
+
return 'No worker can take an actor right now.'
|
|
87
|
+
case 'freeActorSlots':
|
|
88
|
+
return 'Some worker has a free actor slot, though an actor that needs more CPU or memory than that worker has left can still fail to start.'
|
|
89
|
+
case 'uploadsOverdue':
|
|
90
|
+
return 'Some actor snapshots on this node are overdue for upload to object storage. Until Substrate confirms them stored, losing this node could lose that snapshot state.'
|
|
91
|
+
case 'noUploadsOverdue':
|
|
92
|
+
return 'No snapshot upload is overdue on this node. Snapshots with no storage destination are not counted.'
|
|
93
|
+
}
|
|
94
|
+
return verdict.reason
|
|
95
|
+
? sentence(verdict.reason)
|
|
96
|
+
: `Radar could not read this ${pool ? "pool's capacity" : "node's snapshot uploads"} from Prometheus.`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function VerdictState({ verdict }: { verdict: SubstrateVerdict }) {
|
|
100
|
+
switch (verdict.state) {
|
|
101
|
+
case 'workerShortfall':
|
|
102
|
+
return <Badge severity="warning" size="sm">Short of workers</Badge>
|
|
103
|
+
case 'uploadsOverdue':
|
|
104
|
+
return <Badge severity="warning" size="sm">Uploads overdue</Badge>
|
|
105
|
+
case 'noFreeActorSlots':
|
|
106
|
+
return <Badge severity="neutral" size="sm">Full</Badge>
|
|
107
|
+
case 'noSchedulableWorkers':
|
|
108
|
+
return <Badge severity="neutral" size="sm">No schedulable workers</Badge>
|
|
109
|
+
case 'freeActorSlots':
|
|
110
|
+
return <Badge severity="neutral" size="sm">Free slots</Badge>
|
|
111
|
+
case 'noUploadsOverdue':
|
|
112
|
+
return <Badge severity="neutral" size="sm">No overdue uploads</Badge>
|
|
113
|
+
}
|
|
114
|
+
return <Badge severity="neutral" size="sm">Unknown</Badge>
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Facts read over the hour the charts cover; the others are now.
|
|
118
|
+
const HOURLY_FACTS = new Set(['resumeP95', 'resumeFailures', 'crashes'])
|
|
119
|
+
|
|
120
|
+
// Resumes carry a pool only once a worker is assigned.
|
|
121
|
+
const POOL_PLACED = 'Resumes of actors placed on this pool. A resume that failed before it got a worker names no pool and is not counted.'
|
|
122
|
+
|
|
123
|
+
// A range summary covers only the time Prometheus collected: a rate stays
|
|
124
|
+
// representative, but a count misses whatever happened during a gap.
|
|
125
|
+
const HOURLY = 'Computed from the data Prometheus holds for the last hour. If collection had a gap, the crash count covers less than the hour.'
|
|
126
|
+
|
|
127
|
+
function Fact({ fact }: { fact: SubstrateFact }) {
|
|
128
|
+
const placed = fact.id === 'resumeP95' || fact.id === 'resumeFailures'
|
|
129
|
+
const hourly = HOURLY_FACTS.has(fact.id)
|
|
130
|
+
const title = [placed && POOL_PLACED, hourly && HOURLY].filter(Boolean).join(' ') || undefined
|
|
131
|
+
return (
|
|
132
|
+
<Property
|
|
133
|
+
label={title ? <Tooltip content={title}><span>{fact.label}{hourly ? ' (1h)' : ''}</span></Tooltip> : <span>{fact.label}</span>}
|
|
134
|
+
value={<span className="tabular-nums"><FactValue fact={fact} /></span>}
|
|
135
|
+
/>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function FactValue({ fact }: { fact: SubstrateFact }) {
|
|
140
|
+
if (fact.state === 'unavailable') {
|
|
141
|
+
return (
|
|
142
|
+
<Tooltip content={fact.reason || 'Radar could not read this from Prometheus'}>
|
|
143
|
+
<span className="text-theme-text-tertiary">Unavailable</span>
|
|
144
|
+
</Tooltip>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
if (fact.state === 'empty') {
|
|
148
|
+
return fact.reason ? <Tooltip content={fact.reason}><span>None</span></Tooltip> : <span>None</span>
|
|
149
|
+
}
|
|
150
|
+
const value = fact.value!
|
|
151
|
+
switch (fact.id) {
|
|
152
|
+
case 'workersWithFreeActorSlots':
|
|
153
|
+
return <span>{count(value)}{fact.of !== undefined ? ` of ${count(fact.of)}` : ''}</span>
|
|
154
|
+
case 'schedulableWorkers':
|
|
155
|
+
return <span>{count(value)}{fact.of !== undefined ? ` of ${count(fact.of)} desired` : ''}</span>
|
|
156
|
+
case 'crashes':
|
|
157
|
+
return <span>{count(value)}</span>
|
|
158
|
+
case 'overdueUploads': {
|
|
159
|
+
const parts = fact.parts?.map(p => `${OVERDUE_BANDS[p.label] ?? p.label}: ${count(p.value)}`)
|
|
160
|
+
return <span>{count(value)}{parts?.length ? ` (${parts.join(', ')})` : ''}</span>
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return <span>{formatMetricValue(value, fact.unit)}</span>
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const CHARTS = 'section[aria-label="Agent Substrate metrics"]'
|
|
167
|
+
|
|
168
|
+
// The nearest charts below this line, not another mounted view's.
|
|
169
|
+
function scrollToCharts(from: HTMLElement) {
|
|
170
|
+
let el: HTMLElement | null = from.parentElement
|
|
171
|
+
while (el && !el.querySelector(CHARTS)) el = el.parentElement
|
|
172
|
+
el?.querySelector(CHARTS)?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Replica averages and extrapolated increases can be fractional; they are
|
|
176
|
+
// shown as approximate, never rounded to a whole count.
|
|
177
|
+
function count(value: number): string {
|
|
178
|
+
if (Number.isInteger(value)) return String(value)
|
|
179
|
+
return `≈${Math.abs(value) < 10 ? value.toFixed(1) : Math.round(value)}`
|
|
180
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState, useMemo, useCallback } from 'react'
|
|
2
2
|
import { useLocation, useNavigate } from 'react-router-dom'
|
|
3
3
|
import { useQuery } from '@tanstack/react-query'
|
|
4
|
-
import { fetchJSON, isForbiddenError, isKindSyncFailed, isStillLoadingError, useCapabilities, useNamespaceCapabilities, useResources, useSecretCertExpiry, useTopPodMetrics, useTopNodeMetrics, useBulkDeleteResources, useBulkRestartWorkloads, useBulkScaleWorkloads,
|
|
4
|
+
import { fetchJSON, isForbiddenError, isKindSyncFailed, isStillLoadingError, useCapabilities, useNamespaceCapabilities, useResources, useSecretCertExpiry, useTopPodMetrics, useTopNodeMetrics, useBulkDeleteResources, useBulkRestartWorkloads, useBulkScaleWorkloads, useAuditBadges, useIssues, fetchResourceList, isListTooLargeError, isUnretryableReadError } from '../../api/client'
|
|
5
5
|
import { isBadgeWorthy } from '../../utils/auditBadges'
|
|
6
6
|
import { ISSUE_SEVERITY_RANK } from '@skyhook-io/k8s-ui'
|
|
7
7
|
import type { Issue, AuditBadgeMessage } from '@skyhook-io/k8s-ui'
|
|
@@ -13,6 +13,9 @@ import { getSecretStoreProviderType } from '@skyhook-io/k8s-ui'
|
|
|
13
13
|
import { usePinnedKinds } from '../../hooks/useFavorites'
|
|
14
14
|
import { useResourceCounts } from '../../hooks/useResourceCounts'
|
|
15
15
|
import { useCNPGSidebarWorkspace } from '../cnpg/useCNPGSidebarWorkspace'
|
|
16
|
+
import { useVeleroSidebarWorkspace } from '../velero/useVeleroSidebarWorkspace'
|
|
17
|
+
import { isVeleroBackupKind } from '../velero/routes'
|
|
18
|
+
import { useMergedSidebarWorkspaces } from '../workspace/sidebar'
|
|
16
19
|
import { renderResourceKindList, resourceKindListMode, useResourceHostFeatures } from '../../integrations/resourceHosts'
|
|
17
20
|
import { useOpenLogs, useOpenWorkloadLogs } from '../dock'
|
|
18
21
|
import {
|
|
@@ -124,6 +127,8 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
|
|
|
124
127
|
return result
|
|
125
128
|
}, [issuesData])
|
|
126
129
|
const cnpgSidebarWorkspace = useCNPGSidebarWorkspace({ apiResources, namespaces, withMetrics: selectedKind?.group === 'postgresql.cnpg.io' })
|
|
130
|
+
const veleroSidebarWorkspace = useVeleroSidebarWorkspace({ apiResources })
|
|
131
|
+
const sidebarCategoryWorkspaces = useMergedSidebarWorkspaces(cnpgSidebarWorkspace, veleroSidebarWorkspace)
|
|
127
132
|
const workloadWrites = namespaces.length === 0
|
|
128
133
|
? capabilities?.workloadWrites
|
|
129
134
|
: namespaces.length === 1
|
|
@@ -161,7 +166,7 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
|
|
|
161
166
|
// kind shared across groups doesn't bleed findings across the two lists. Only
|
|
162
167
|
// "badge-worthy" findings count (reference-integrity / lifecycle) — posture
|
|
163
168
|
// and best-practice nags fire near-universally and would just be noise.
|
|
164
|
-
const audit =
|
|
169
|
+
const audit = useAuditBadges(namespaces)
|
|
165
170
|
const auditBadges = useMemo(() => {
|
|
166
171
|
if (!selectedKind || !audit.data?.findings) return undefined
|
|
167
172
|
const wantGroup = selectedKind.group
|
|
@@ -345,9 +350,9 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
|
|
|
345
350
|
const [createDialogYaml, setCreateDialogYaml] = useState('')
|
|
346
351
|
const [createDialogTitle, setCreateDialogTitle] = useState<string | undefined>()
|
|
347
352
|
|
|
348
|
-
const handleCreateResource = useCallback((kind:
|
|
353
|
+
const handleCreateResource = useCallback((kind: SelectedKindInfo, initialYaml?: string) => {
|
|
349
354
|
if (kind?.kind) {
|
|
350
|
-
setCreateDialogYaml(getSkeletonYaml(kind.kind, kind.group))
|
|
355
|
+
setCreateDialogYaml(initialYaml ?? getSkeletonYaml(kind.kind, kind.group))
|
|
351
356
|
setCreateDialogTitle(`Create ${kind.kind}`)
|
|
352
357
|
} else {
|
|
353
358
|
setCreateDialogYaml('')
|
|
@@ -395,7 +400,7 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
|
|
|
395
400
|
? { kind: selectedKind.name, reason: 'too-many', count: typeof selectedKindQuery.error.data?.count === 'number' ? selectedKindQuery.error.data.count : undefined, limit: selectedKindRowLimit, namespaces }
|
|
396
401
|
: largeListGuard}
|
|
397
402
|
onSelectedKindChange={setSelectedKind}
|
|
398
|
-
sidebarCategoryWorkspaces={
|
|
403
|
+
sidebarCategoryWorkspaces={sidebarCategoryWorkspaces}
|
|
399
404
|
topPodMetrics={topPodMetrics}
|
|
400
405
|
topNodeMetrics={topNodeMetrics}
|
|
401
406
|
certExpiry={certExpiry}
|
|
@@ -426,7 +431,8 @@ export function ResourcesView({ namespaces, selectedResource, onResourceClick, o
|
|
|
426
431
|
onCreateResource={handleCreateResource}
|
|
427
432
|
renderKindView={renderKindView}
|
|
428
433
|
// Bulk operations
|
|
429
|
-
|
|
434
|
+
// A Velero backup is deleted one at a time, through Velero (Delete backup in its drawer).
|
|
435
|
+
onBulkDelete={isVeleroBackupKind(selectedKind?.name, selectedKind?.group) ? undefined : (items, options) => bulkDeleteMutation.mutate({ items, force: options?.force }, { onSuccess: results => { if (!results.some(({ result }) => result.outcomeUnknown)) options?.onSuccess?.() } })}
|
|
430
436
|
isBulkDeleting={bulkDeleteMutation.isPending}
|
|
431
437
|
onBulkRestart={canBulkRestartSelectedKind ? (items, options) => bulkRestartMutation.mutate({ items }, { onSuccess: options?.onSuccess }) : undefined}
|
|
432
438
|
isBulkRestarting={canBulkRestartSelectedKind && bulkRestartMutation.isPending}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { toPlanNodes } from './UpgradePlanRenderer'
|
|
3
|
+
|
|
4
|
+
const node = { metadata: { name: 'n1', labels: { role: 'cp' } } }
|
|
5
|
+
|
|
6
|
+
describe('toPlanNodes', () => {
|
|
7
|
+
it('passes Nodes as name and labels', () => {
|
|
8
|
+
expect(toPlanNodes({ data: [node], coverage: { status: 'complete' } as any, error: null, isLoading: false })).toEqual({ nodes: [{ name: 'n1', labels: { role: 'cp' } }], loading: false })
|
|
9
|
+
})
|
|
10
|
+
it('treats a denied or partial Node read as unreadable', () => {
|
|
11
|
+
expect(toPlanNodes({ data: undefined, error: new Error('403'), isLoading: false }).nodes).toBeNull()
|
|
12
|
+
expect(toPlanNodes({ data: [node], coverage: { status: 'partial' } as any, error: null, isLoading: false }).nodes).toBeNull()
|
|
13
|
+
})
|
|
14
|
+
it('accepts a list from an older Radar that reports no coverage', () => {
|
|
15
|
+
expect(toPlanNodes({ data: [node], coverage: { status: 'unknown' } as any, error: null, isLoading: false }).nodes).toHaveLength(1)
|
|
16
|
+
})
|
|
17
|
+
it('waits while Nodes load', () => {
|
|
18
|
+
expect(toPlanNodes({ data: undefined, error: null, isLoading: true })).toEqual({ nodes: undefined, loading: true })
|
|
19
|
+
})
|
|
20
|
+
})
|