@skyhook-io/radar-app 1.21.1 → 1.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +11 -0
  2. package/package.json +2 -2
  3. package/src/App.tsx +50 -28
  4. package/src/api/actions.test.ts +11 -0
  5. package/src/api/actions.ts +5 -0
  6. package/src/api/apiResources.navigation.test.tsx +58 -0
  7. package/src/api/apiResources.ts +22 -16
  8. package/src/api/client.diagnostics.test.ts +52 -0
  9. package/src/api/client.triggerCronJob.test.tsx +49 -0
  10. package/src/api/client.ts +140 -120
  11. package/src/api/connectionBinding.test.tsx +82 -0
  12. package/src/api/connectionBinding.ts +52 -0
  13. package/src/api/contextSwitch.test.ts +11 -0
  14. package/src/api/contextSwitch.ts +58 -0
  15. package/src/api/radarFeatures.ts +7 -0
  16. package/src/api/sealedSecrets.test.ts +22 -0
  17. package/src/api/sealedSecrets.ts +37 -0
  18. package/src/api/vulnerabilities.ts +80 -7
  19. package/src/components/ConnectionErrorView.tsx +13 -0
  20. package/src/components/ContextSwitchActions.tsx +43 -0
  21. package/src/components/ContextSwitcher.tsx +13 -6
  22. package/src/components/SwitchAwareConnectionError.tsx +2 -2
  23. package/src/components/audit/Java4ShellPanel.test.tsx +104 -7
  24. package/src/components/audit/Java4ShellPanel.tsx +169 -72
  25. package/src/components/cost/ApplicationCostTab.test.ts +16 -0
  26. package/src/components/cost/ApplicationCostTab.tsx +41 -9
  27. package/src/components/cost/CostTrendChart.tsx +25 -2
  28. package/src/components/cost/CostTrendWithheld.render.test.tsx +105 -0
  29. package/src/components/cost/CostView.tsx +10 -2
  30. package/src/components/cost/CostViewTabs.test.tsx +18 -0
  31. package/src/components/cost/CostViewTabs.tsx +14 -22
  32. package/src/components/cost/WorkloadCostTab.test.ts +15 -0
  33. package/src/components/cost/WorkloadCostTab.tsx +42 -8
  34. package/src/components/cost/source.test.ts +16 -1
  35. package/src/components/cost/source.ts +34 -0
  36. package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +35 -0
  37. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +16 -1
  38. package/src/components/dock/NodeTerminalTab.test.tsx +4 -2
  39. package/src/components/dock/NodeTerminalTab.tsx +8 -8
  40. package/src/components/dock/TerminalTab.test.tsx +12 -1
  41. package/src/components/dock/TerminalTab.tsx +6 -3
  42. package/src/components/home/CostCard.test.tsx +49 -0
  43. package/src/components/home/CostCard.tsx +98 -63
  44. package/src/components/home/mcpToolCatalog.ts +1 -0
  45. package/src/components/resource/DatadogRightsizingPanel.test.tsx +118 -0
  46. package/src/components/resource/DatadogRightsizingPanel.tsx +68 -0
  47. package/src/components/resource/DatadogWorkloadCharts.tsx +149 -0
  48. package/src/components/resource/HPACharts.render.test.tsx +42 -0
  49. package/src/components/resource/HPACharts.tsx +34 -1
  50. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +126 -3
  51. package/src/components/resource/PrometheusChartsGrid.tsx +58 -25
  52. package/src/components/resource/RestartChart.render.test.tsx +72 -0
  53. package/src/components/resource/RestartChart.tsx +31 -3
  54. package/src/components/resource/RightsizingPanel.access.test.tsx +24 -0
  55. package/src/components/resource/RightsizingStrip.render.test.tsx +44 -0
  56. package/src/components/resource/RightsizingStrip.test.ts +1 -188
  57. package/src/components/resource/RightsizingStrip.tsx +27 -300
  58. package/src/components/resource/WorkloadMetricsSection.render.test.tsx +22 -0
  59. package/src/components/resource/WorkloadMetricsSection.tsx +14 -4
  60. package/src/components/resource/nameMatchedScope.ts +39 -0
  61. package/src/components/resources/pod-file-upload.ts +3 -0
  62. package/src/components/resources/renderers/CAPIClusterRenderer.tsx +5 -2
  63. package/src/components/resources/renderers/LonghornVolumeRenderer.test.tsx +104 -0
  64. package/src/components/resources/renderers/LonghornVolumeRenderer.tsx +31 -0
  65. package/src/components/resources/renderers/SealedSecretRenderer.test.tsx +41 -0
  66. package/src/components/resources/renderers/SealedSecretRenderer.tsx +14 -0
  67. package/src/components/rightsizing/RightsizingScanLink.tsx +22 -0
  68. package/src/components/rightsizing/RightsizingScanView.tsx +65 -528
  69. package/src/components/rightsizing/model.test.ts +20 -9
  70. package/src/components/rightsizing/model.ts +17 -176
  71. package/src/components/rightsizing/notices.test.tsx +30 -29
  72. package/src/components/traffic/TrafficFlowList.tsx +8 -4
  73. package/src/components/traffic/TrafficGraph.test.tsx +31 -1
  74. package/src/components/traffic/TrafficGraph.tsx +11 -6
  75. package/src/components/traffic/trafficFilters.ts +4 -4
  76. package/src/components/ui/DiagnosticsOverlay.test.ts +3 -2
  77. package/src/components/ui/DiagnosticsOverlay.tsx +23 -13
  78. package/src/components/ui/command-items.ts +3 -4
  79. package/src/components/useContextSwitchFlow.test.tsx +9 -0
  80. package/src/components/useContextSwitchFlow.tsx +43 -5
  81. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.test.tsx +54 -0
  82. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +50 -109
  83. package/src/components/whats-new/releaseNotes.ts +1 -1
  84. package/src/components/workload/WorkloadRightsizingSource.test.tsx +83 -0
  85. package/src/components/workload/WorkloadView.test.ts +22 -1
  86. package/src/components/workload/WorkloadView.tsx +57 -16
  87. package/src/context/ConnectionContext.test.ts +1 -0
  88. package/src/context/ConnectionContext.tsx +58 -15
  89. package/src/context/ConnectionProvider.connectionId.test.tsx +92 -0
  90. package/src/context/ConnectionProvider.retry.test.tsx +174 -1
  91. package/src/context/ContextSwitchContext.tsx +15 -1
  92. package/src/context/NavCustomization.tsx +6 -3
  93. package/src/hooks/useEventSource.test.tsx +85 -0
  94. package/src/hooks/useEventSource.ts +43 -16
  95. package/src/hooks/useResetViewsOnContextChange.test.tsx +34 -0
  96. package/src/hooks/useResetViewsOnContextChange.ts +27 -0
  97. package/src/index.ts +3 -0
  98. package/src/integrations/resourceHosts.test.tsx +2 -2
  99. package/src/integrations/resourceHosts.tsx +4 -0
  100. package/src/utils/navigation.ts +1 -15
  101. package/src/utils/page-links.ts +6 -0
  102. package/src/components/rightsizing/presentation.test.ts +0 -150
  103. package/src/components/rightsizing/presentation.ts +0 -109
@@ -1,7 +1,9 @@
1
- import { useState, type ReactNode } from 'react'
1
+ import { useLayoutEffect, useState, type ReactNode } from 'react'
2
2
  import { AlertTriangle } from 'lucide-react'
3
3
  import { pluralize } from '@skyhook-io/k8s-ui'
4
4
  import { useSwitchContext, fetchSessionCounts, SwitchContextError, type SessionCounts } from '../api/client'
5
+ import { finishSwitch, followSwitch, followingSwitch, switchInProgress, useTrackedContextSwitch } from '../api/contextSwitch'
6
+ import { useConnection } from '../context/ConnectionContext'
5
7
  import { useContextSwitch } from '../context/ContextSwitchContext'
6
8
  import { useToast } from './ui/Toast'
7
9
  import { Tooltip } from './ui/Tooltip'
@@ -30,8 +32,9 @@ interface PendingSwitch {
30
32
  // toast when the switch fails. `openAfter` is opened once the new context is
31
33
  // live. Callers render `confirmDialog`.
32
34
  export function useContextSwitchFlow() {
35
+ const { connection } = useConnection()
33
36
  const switchContext = useSwitchContext()
34
- const { startSwitch, endSwitch, setOpenAfterSwitch, setFailedSwitch } = useContextSwitch()
37
+ const { isSwitching, startSwitch, endSwitch, setOpenAfterSwitch, setFailedSwitch } = useContextSwitch()
35
38
  const { showError } = useToast()
36
39
  const { tabs } = useDock()
37
40
  const [pending, setPending] = useState<PendingSwitch | null>(null)
@@ -65,9 +68,9 @@ export function useContextSwitchFlow() {
65
68
  }
66
69
 
67
70
  const requestSwitch = async (context: ContextInfo, openAfter?: SelectedResource) => {
68
- if (switchContext.isPending) return
71
+ if (isSwitching || switchContext.isPending) return
69
72
  // Picking the cluster you're still on dismisses a refused switch's screen.
70
- if (context.isCurrent) {
73
+ if (context.isCurrent && connection.errorType !== 'switch-stopped') {
71
74
  setFailedSwitch(null)
72
75
  return
73
76
  }
@@ -157,7 +160,7 @@ export function useContextSwitchFlow() {
157
160
 
158
161
  return {
159
162
  requestSwitch,
160
- isPending: switchContext.isPending,
163
+ isPending: !!isSwitching || switchContext.isPending,
161
164
  error: switchContext.isError ? switchContext.error : null,
162
165
  // The picker's inline line is for failures that don't get the full screen.
163
166
  errorText: switchContext.isError && switchContext.error && !refusedBeforeLeaving(switchContext.error)
@@ -170,3 +173,38 @@ export function useContextSwitchFlow() {
170
173
  function shortNameHides(context: ContextInfo) {
171
174
  return parseContextForSwitcher(context).clusterName !== context.name
172
175
  }
176
+
177
+ export function useContextSwitchOutcome(applyContextChange: (context: string, id: string) => void) {
178
+ const { contextSwitch: polledSwitch, connection } = useConnection()
179
+ const contextSwitch = useTrackedContextSwitch(polledSwitch)
180
+ const { endSwitch, setOpenAfterSwitch, setFailedSwitch } = useContextSwitch()
181
+ const { showError } = useToast()
182
+
183
+ useLayoutEffect(() => {
184
+ if (!contextSwitch) return
185
+ if (switchInProgress(contextSwitch)) {
186
+ if (followingSwitch() !== contextSwitch.id) followSwitch(contextSwitch.id)
187
+ // The accepted POST can arrive before the first connection poll. Keep
188
+ // local progress until an observed operation takes over the overlay.
189
+ endSwitch()
190
+ return
191
+ }
192
+ if (followingSwitch() !== contextSwitch.id) return
193
+ if (contextSwitch.phase === 'failed' && connection.state === 'connecting') return
194
+ finishSwitch(contextSwitch.id)
195
+ endSwitch()
196
+ if (contextSwitch.phase === 'succeeded' && connection.context === contextSwitch.target) {
197
+ applyContextChange(contextSwitch.target, contextSwitch.id)
198
+ } else {
199
+ setOpenAfterSwitch(null)
200
+ if (contextSwitch.phase === 'failed' && (connection.state === 'connected' || connection.context !== contextSwitch.target)) {
201
+ const reason = contextSwitch.error || 'Cluster switch failed'
202
+ if (contextSwitch.errorType) {
203
+ setFailedSwitch({ context: contextSwitch.target, error: reason, errorType: contextSwitch.errorType })
204
+ } else {
205
+ showError('Failed to switch context', reason)
206
+ }
207
+ }
208
+ }
209
+ }, [contextSwitch, connection.state, connection.context, applyContextChange, endSwitch, setOpenAfterSwitch, setFailedSwitch, showError])
210
+ }
@@ -0,0 +1,54 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { MemoryRouter } from 'react-router-dom'
3
+ import { expect, it, vi } from 'vitest'
4
+ import { useAPIResources } from '../../api/apiResources'
5
+ import { useVulnerabilities, type VulnerableImage } from '../../api/vulnerabilities'
6
+ import { WorkloadVulnerabilitiesSection } from './WorkloadVulnerabilitiesSection'
7
+
8
+ vi.mock('../../api/apiResources', () => ({ useAPIResources: vi.fn() }))
9
+ vi.mock('../../api/client', () => ({ useRadarFeature: () => ({ support: 'supported' }) }))
10
+ vi.mock('../../api/vulnerabilities', async (importOriginal) => ({
11
+ ...await importOriginal<typeof import('../../api/vulnerabilities')>(),
12
+ useVulnerabilities: vi.fn(),
13
+ }))
14
+
15
+ const workload = { kind: 'Deployment', group: 'apps', namespace: 'team', name: 'api', container: 'server' }
16
+ const zero = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0 }
17
+ const image: VulnerableImage = {
18
+ id: 'api', image: 'example.com/team/api:1', scannedAt: '2026-11-20T12:00:00Z',
19
+ counts: { ...zero, critical: 1 }, fixable: { ...zero, critical: 1 }, matching: 1,
20
+ workloads: [workload], workloadsTotal: 1, findings: [], findingsTotal: 1,
21
+ report: { kind: 'VulnerabilityReport', namespace: 'team', name: 'deployment-api' },
22
+ }
23
+
24
+ function renderDrawer(available: boolean, reports: { images: VulnerableImage[]; clean?: VulnerableImage[]; unscanned?: { image: string }[] }) {
25
+ vi.mocked(useAPIResources).mockReturnValue({
26
+ data: available ? [{ group: 'aquasecurity.github.io', name: 'vulnerabilityreports' }] : [],
27
+ } as ReturnType<typeof useAPIResources>)
28
+ vi.mocked(useVulnerabilities).mockImplementation(({ view }) => ({
29
+ data: view === 'image' ? reports : { fixes: [] },
30
+ } as ReturnType<typeof useVulnerabilities>))
31
+ return renderToStaticMarkup(
32
+ <MemoryRouter>
33
+ <WorkloadVulnerabilitiesSection kind={workload.kind} namespace={workload.namespace} name={workload.name} />
34
+ </MemoryRouter>,
35
+ )
36
+ }
37
+
38
+ it('omits the section when Trivy is unavailable or has no findings for the workload', () => {
39
+ expect(renderDrawer(false, { images: [] })).toBe('')
40
+ expect(renderDrawer(true, { images: [], clean: [{ ...image, counts: zero, findingsTotal: 0 }] })).toBe('')
41
+ })
42
+
43
+ it('shows reported findings without an advisory scan action', () => {
44
+ const html = renderDrawer(true, { images: [image] })
45
+ expect(html).toContain('Vulnerabilities · 1 critical')
46
+ expect(html).toContain('1 with a fix')
47
+ expect(html).not.toContain('Java4Shell')
48
+ })
49
+
50
+ it('discloses missing scans alongside reported findings', () => {
51
+ const html = renderDrawer(true, { images: [image], unscanned: [{ image: 'example.com/sidecar' }] })
52
+ expect(html).toContain('View unscanned images in this workload')
53
+ expect(html).not.toContain('Java4Shell')
54
+ })
@@ -6,11 +6,8 @@ import { Section } from '@skyhook-io/k8s-ui/components/ui/drawer-components'
6
6
  import { formatRelativeAgeTime } from '@skyhook-io/k8s-ui/utils/format'
7
7
  import { useAPIResources } from '../../api/apiResources'
8
8
  import { useRadarFeature } from '../../api/client'
9
- import { isRadarFeatureUnsupported } from '../../api/radarFeatures'
10
- import { hasVulnerabilityReports, isKindUnknown, useVulnerabilities, workloadParam } from '../../api/vulnerabilities'
11
- import { useConnection } from '../../context/ConnectionContext'
12
- import { Java4ShellPanel } from '../audit/Java4ShellPanel'
13
- import { ClearedCount, FixVersion, ImageName, SeverityCounts, gapSentence } from './parts'
9
+ import { hasVulnerabilityReports, useVulnerabilities, workloadParam } from '../../api/vulnerabilities'
10
+ import { ClearedCount, FixVersion, ImageName, SeverityCounts } from './parts'
14
11
 
15
12
  interface Props {
16
13
  kind: string
@@ -18,53 +15,20 @@ interface Props {
18
15
  name: string
19
16
  }
20
17
 
21
- /**
22
- * The drawer combines any available scanner reports with the on-demand advisory.
23
- */
24
18
  export function WorkloadVulnerabilitiesSection({ kind, namespace, name }: Props) {
25
19
  const navigate = useNavigate()
26
20
  const [params] = useSearchParams()
27
21
  const { data: resources } = useAPIResources()
28
22
  const { support } = useRadarFeature('vulnerabilities')
29
- const { support: advisorySupport } = useRadarFeature('runtimeAdvisoryChecks')
30
- const { connection } = useConnection()
31
23
  const available = hasVulnerabilityReports(resources) && support !== 'unsupported'
32
24
  const workload = { kind, namespace, name }
33
- const { data, isLoading, error } = useVulnerabilities({ view: 'image', workload }, available && !!namespace && !!name)
34
- // The upgrades it needs, as By fix works them out, once it has findings.
35
- const { data: fixData } = useVulnerabilities({ view: 'fix', workload }, available && !!namespace && !!name && (data?.images ?? []).length > 0)
36
- const advisory = advisorySupport === 'supported' && !!namespace && !!name && (
37
- <Java4ShellPanel
38
- context={connection.context}
39
- connected={connection.state === 'connected'}
40
- workload={{ ...workload, group: 'apps' }}
41
- />
42
- )
43
- if (!available || (error && (isRadarFeatureUnsupported(error) || isKindUnknown(error)))) {
44
- return advisory ? <Section title="Vulnerabilities" icon={Shield}>{advisory}</Section> : null
45
- }
46
- if (error) {
47
- return (
48
- <Section title="Vulnerabilities" icon={Shield}>
49
- <div className="flex flex-col gap-3">
50
- <p className="text-xs text-warning-text">Couldn't read vulnerability reports: {error instanceof Error ? error.message : 'request failed'}.</p>
51
- {advisory}
52
- </div>
53
- </Section>
54
- )
55
- }
56
-
25
+ const { data } = useVulnerabilities({ view: 'image', workload }, available && !!namespace && !!name)
57
26
  const images = data?.images ?? []
58
- // The tab folds clean images away; a workload's drawer shows every container.
59
- const clean = data?.clean ?? []
60
- const unscanned = data?.unscanned ?? []
27
+ const { data: fixData } = useVulnerabilities({ view: 'fix', workload }, available && !!namespace && !!name && images.length > 0)
28
+ if (!available || images.length === 0) return null
29
+
61
30
  const critical = images.reduce((n, img) => n + (img.findingsUnread ? 0 : img.counts.critical), 0)
62
31
  const upgrades = fixData?.fixes ?? []
63
- // The read spans the caller's scope; a gap names this namespace, or might.
64
- const relevantGaps = (data?.coverage.gaps ?? []).filter((g) => {
65
- const ns = g.namespaces
66
- return !ns || ns.extent !== undefined || (ns.names ?? []).length < ns.count || (ns.names ?? []).includes(namespace)
67
- })
68
32
  const isThis = (w: { kind: string; namespace: string; name: string }) => w.kind === kind && w.namespace === namespace && w.name === name
69
33
  // The link keeps the page's namespace view, as every page link does: the
70
34
  // picker follows the URL, so a narrower one would change it.
@@ -91,73 +55,50 @@ export function WorkloadVulnerabilitiesSection({ kind, namespace, name }: Props)
91
55
 
92
56
  return (
93
57
  <Section title={critical > 0 ? `Vulnerabilities · ${critical} critical` : 'Vulnerabilities'} icon={Shield}>
94
- {isLoading ? (
95
- <p className="text-sm text-theme-text-tertiary">Reading vulnerability reports…</p>
96
- ) : (
97
- <div className="flex flex-col gap-3 text-sm">
98
- {images.map((img) => card(img.id, (
99
- <>
100
- <span className="flex flex-wrap items-baseline gap-x-2">
101
- {containerName(img.workloads)}
102
- <ImageName image={img.image} className="text-xs text-theme-text-tertiary" />
103
- </span>
104
- <span className="flex flex-wrap items-center gap-x-3">
105
- {img.findingsUnread ? <span className="text-xs text-warning-text">Findings not read</span> : <SeverityCounts counts={img.counts} />}
106
- <span className="text-xs text-theme-text-secondary">{img.findingsUnread ? '' : `${img.fixable.critical + img.fixable.high + img.fixable.medium + img.fixable.low + img.fixable.unknown} with a fix · `}scanned {formatRelativeAgeTime(img.scannedAt)}</span>
107
- </span>
108
- <SharedWith others={[...new Set(img.workloads.filter((w) => !isThis(w)).map((w) => `${w.namespace}/${w.name}`))]} partial={img.workloads.length < img.workloadsTotal} />
109
- </>
110
- )))}
111
- {unscanned.map((u) => card(u.image, (
112
- <>
113
- <span className="flex flex-wrap items-baseline gap-x-2">
114
- {containerName(u.workloads)}
115
- <ImageName image={u.image} className="text-xs text-theme-text-tertiary" />
116
- </span>
117
- <span className="text-xs text-warning-text">Not scanned</span>
118
- </>
119
- )))}
120
- {clean.map((img) => card(img.id, (
121
- <>
122
- <span className="flex flex-wrap items-baseline gap-x-2">
123
- {containerName(img.workloads)}
124
- <ImageName image={img.image} className="text-xs text-theme-text-tertiary" />
125
- </span>
126
- <span className="text-xs text-theme-text-secondary">No CVEs reported · scanned {formatRelativeAgeTime(img.scannedAt)}</span>
127
- </>
128
- )))}
129
- {images.length === 0 && clean.length === 0 && unscanned.length === 0 && (
130
- <p className="text-xs text-theme-text-tertiary">
131
- {gapSentence(relevantGaps, { counts: false }) ?? 'No running containers in this workload.'}
132
- </p>
133
- )}
134
- {upgrades.length > 0 && (
135
- // One grid so packages, targets and counts line up; Critical and
136
- // High are what decide which upgrade comes first.
137
- <div className="grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)_2rem_2.5rem] items-baseline gap-x-3 gap-y-1 text-xs">
138
- <span className="col-span-2 font-medium text-theme-text-secondary">Upgrade first</span>
139
- <span className="text-right text-theme-text-tertiary">C</span>
140
- <span className="text-right text-theme-text-tertiary">H</span>
141
- {upgrades.slice(0, UPGRADES_SHOWN).map((f) => (
142
- <Fragment key={`${f.packageType ?? ''}/${f.package}/${f.to ?? (f.fixedVersions ?? []).join('|')}`}>
143
- <span className="truncate font-mono text-theme-text-primary">{f.package}</span>
144
- {f.to
145
- ? <span className="flex min-w-0 items-baseline gap-1 font-mono"><span className="text-theme-text-tertiary">→</span><FixVersion installed={f.from.join(', ')} target={f.to} showInstalled={false} /></span>
146
- : <span className="truncate font-mono text-theme-text-tertiary">fixed in {(f.fixedVersions ?? []).join(', ')}</span>}
147
- <ClearedCount count={f.counts.critical} severity="critical" />
148
- <ClearedCount count={f.counts.high} severity="high" />
149
- </Fragment>
150
- ))}
151
- {upgrades.length > UPGRADES_SHOWN && (
152
- <button type="button" onClick={() => open({ by: 'fix' })} className="col-span-4 justify-self-start text-accent-text hover:underline">
153
- {upgrades.length - UPGRADES_SHOWN} more {upgrades.length - UPGRADES_SHOWN === 1 ? 'upgrade' : 'upgrades'} →
154
- </button>
155
- )}
156
- </div>
157
- )}
158
- </div>
159
- )}
160
- {advisory && <div className="mt-3">{advisory}</div>}
58
+ <div className="flex flex-col gap-3 text-sm">
59
+ {images.map((img) => card(img.id, (
60
+ <>
61
+ <span className="flex flex-wrap items-baseline gap-x-2">
62
+ {containerName(img.workloads)}
63
+ <ImageName image={img.image} className="text-xs text-theme-text-tertiary" />
64
+ </span>
65
+ <span className="flex flex-wrap items-center gap-x-3">
66
+ {img.findingsUnread ? <span className="text-xs text-warning-text">Findings not read</span> : <SeverityCounts counts={img.counts} />}
67
+ <span className="text-xs text-theme-text-secondary">{img.findingsUnread ? '' : `${img.fixable.critical + img.fixable.high + img.fixable.medium + img.fixable.low + img.fixable.unknown} with a fix · `}scanned {formatRelativeAgeTime(img.scannedAt)}</span>
68
+ </span>
69
+ <SharedWith others={[...new Set(img.workloads.filter((w) => !isThis(w)).map((w) => `${w.namespace}/${w.name}`))]} partial={img.workloads.length < img.workloadsTotal} />
70
+ </>
71
+ )))}
72
+ {Boolean(data?.unscanned?.length) && (
73
+ <button type="button" onClick={() => open()} className="self-start text-xs text-accent-text hover:underline">
74
+ View unscanned images in this workload →
75
+ </button>
76
+ )}
77
+ {upgrades.length > 0 && (
78
+ // One grid so packages, targets and counts line up; Critical and
79
+ // High are what decide which upgrade comes first.
80
+ <div className="grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)_2rem_2.5rem] items-baseline gap-x-3 gap-y-1 text-xs">
81
+ <span className="col-span-2 font-medium text-theme-text-secondary">Upgrade first</span>
82
+ <span className="text-right text-theme-text-tertiary">C</span>
83
+ <span className="text-right text-theme-text-tertiary">H</span>
84
+ {upgrades.slice(0, UPGRADES_SHOWN).map((f) => (
85
+ <Fragment key={`${f.packageType ?? ''}/${f.package}/${f.to ?? (f.fixedVersions ?? []).join('|')}`}>
86
+ <span className="truncate font-mono text-theme-text-primary">{f.package}</span>
87
+ {f.to
88
+ ? <span className="flex min-w-0 items-baseline gap-1 font-mono"><span className="text-theme-text-tertiary">→</span><FixVersion installed={f.from.join(', ')} target={f.to} showInstalled={false} /></span>
89
+ : <span className="truncate font-mono text-theme-text-tertiary">fixed in {(f.fixedVersions ?? []).join(', ')}</span>}
90
+ <ClearedCount count={f.counts.critical} severity="critical" />
91
+ <ClearedCount count={f.counts.high} severity="high" />
92
+ </Fragment>
93
+ ))}
94
+ {upgrades.length > UPGRADES_SHOWN && (
95
+ <button type="button" onClick={() => open({ by: 'fix' })} className="col-span-4 justify-self-start text-accent-text hover:underline">
96
+ {upgrades.length - UPGRADES_SHOWN} more {upgrades.length - UPGRADES_SHOWN === 1 ? 'upgrade' : 'upgrades'} →
97
+ </button>
98
+ )}
99
+ </div>
100
+ )}
101
+ </div>
161
102
  </Section>
162
103
  )
163
104
  }
@@ -88,7 +88,7 @@ export const RELEASE_NOTES: ReleaseNotes[] = [
88
88
  id: 'java4shell-check',
89
89
  icon: ScanSearch,
90
90
  title: 'Check for Java4Shell',
91
- description: 'Check declared Java versions in workload drawers or with radar check java4shell. Node CPU features help prioritize fixes. Works without Trivy.',
91
+ description: 'Find affected Java versions in Checks or with radar check java4shell. Node CPU features help prioritize fixes. Works without Trivy.',
92
92
  importance: 7,
93
93
  path: '/checks/vulnerabilities',
94
94
  cta: 'Open Java4Shell check',
@@ -0,0 +1,83 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
3
+ import { MemoryRouter } from 'react-router-dom'
4
+ import { expect, it, vi } from 'vitest'
5
+ import { ApiError } from '../../api/client'
6
+ import { getApiBase } from '../../api/config'
7
+ import { NavCustomizationProvider } from '../../context/NavCustomization'
8
+ import { WorkloadCostRightsizing } from '../resource/DatadogWorkloadCharts'
9
+ import { MetricsTabContent } from './WorkloadView'
10
+
11
+ vi.mock('../resource/PrometheusChartsGrid', () => ({
12
+ PrometheusChartsGrid: ({ showRightsizing = true, workloadTotals }: { showRightsizing?: boolean; workloadTotals?: React.ReactNode }) =>
13
+ <div>Prom charts{workloadTotals}{showRightsizing && <p>Prom recommendation</p>}</div>,
14
+ }))
15
+ vi.mock('../resource/RightsizingStrip', () => ({
16
+ RightsizingPanel: () => <p>Prom recommendation</p>,
17
+ RightsizingStrip: () => <p>Prom recommendation</p>,
18
+ }))
19
+ vi.mock('../resource/DatadogRightsizingPanel', () => ({
20
+ DatadogRightsizingPanel: () => <p>DD recommendation</p>,
21
+ }))
22
+ vi.mock('../resource/RestartChart', () => ({ RestartEventLane: () => null }))
23
+
24
+ function render(status: object | Error, required = true) {
25
+ const client = new QueryClient({ defaultOptions: { queries: { retryOnMount: false } } })
26
+ const queryKey = ['datadog-metrics-status', getApiBase()]
27
+ if (status instanceof Error) {
28
+ const query = client.getQueryCache().build(client, { queryKey })
29
+ query.setState({ status: 'error', error: status })
30
+ } else {
31
+ client.setQueryData(queryKey, status)
32
+ }
33
+ const workload = { kind: 'Deployment', namespace: 'shop', name: 'api' }
34
+ function view(children: React.ReactNode) {
35
+ return renderToStaticMarkup(
36
+ <MemoryRouter><NavCustomizationProvider value={{ embedded: true, rightsizingProviderStatus: required }}>
37
+ <QueryClientProvider client={client}>{children}</QueryClientProvider>
38
+ </NavCustomizationProvider></MemoryRouter>,
39
+ )
40
+ }
41
+ const metrics = view(<MetricsTabContent {...workload} resource={{}} expanded />)
42
+ const drawer = view(<MetricsTabContent {...workload} resource={{}} expanded={false} />)
43
+ const cost = view(<WorkloadCostRightsizing {...workload} />)
44
+ client.clear()
45
+ return { cost, metrics, drawer }
46
+ }
47
+
48
+ it.each([
49
+ [{ configured: false, rightsizingProvider: 'datadog' }, 'no usable rightsizing connection'],
50
+ [{ configured: false }, 'could not determine the rightsizing source'],
51
+ [new ApiError('Cluster missing', 404), 'could not determine the rightsizing source'],
52
+ [new ApiError('Gateway down', 503), 'could not determine the rightsizing source'],
53
+ ])('keeps Prom charts available and withholds sizing when its selection is unresolved', (status, reason) => {
54
+ const { cost, metrics, drawer } = render(status)
55
+ expect(metrics).toContain('Prom charts')
56
+ for (const panel of [metrics, drawer, cost]) {
57
+ expect(panel).toContain(reason)
58
+ expect(panel).not.toContain('Prom recommendation')
59
+ expect(panel).not.toContain('DD recommendation')
60
+ }
61
+ })
62
+
63
+ it.each([
64
+ [{ configured: false, rightsizingProvider: 'prometheus' }, 'Prom charts', 'Prom recommendation'],
65
+ [{ configured: true, rightsizingProvider: 'prometheus' }, 'Datadog', 'Prom recommendation'],
66
+ [{ configured: false, rightsizingProvider: 'datadog', rightsizing: true }, 'Prom charts', 'DD recommendation'],
67
+ [{ configured: true, rightsizingProvider: 'datadog', rightsizing: true }, 'Datadog', 'DD recommendation'],
68
+ ])('resolves charts independently of the single selected sizing provider', (status, charts, expected) => {
69
+ const { cost, metrics, drawer } = render(status)
70
+ expect(metrics).toContain(charts)
71
+ for (const panel of [metrics, drawer, cost]) {
72
+ expect(panel.match(/(?:DD|Prom) recommendation/g)).toEqual([expected])
73
+ }
74
+ })
75
+
76
+ it('keeps Prometheus sizing for chart-only Hubs and recognizes a missing status route', () => {
77
+ const absentRoute = new ApiError('Not found', 404, {}, { unknownRoute: true })
78
+ expect(render(absentRoute, false).cost).toContain('Prom recommendation')
79
+ expect(render(absentRoute).cost).not.toContain('Prom recommendation')
80
+ expect(render(new ApiError('Cluster unavailable', 404), false).cost).not.toContain('Prom recommendation')
81
+ expect(render({ configured: true }, false).cost).toContain('Prom recommendation')
82
+ expect(render({ configured: false }, false).cost).toContain('Prom recommendation')
83
+ })
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
2
2
 
3
3
  import { gitOpsOwnerFromRelationships } from '@skyhook-io/k8s-ui'
4
4
  import type { Relationships } from '../../types'
5
- import { collectServingRefs, memberOverviewParams, supportsBatchExecution } from './WorkloadView'
5
+ import { collectServingRefs, isPrometheusMetricsAvailable, memberOverviewParams, supportsBatchExecution } from './WorkloadView'
6
6
  import { findInheritedGitOpsLookupRef } from '../../hooks/useResolvedGitOpsOwner'
7
7
 
8
8
  describe('findInheritedGitOpsLookupRef', () => {
@@ -93,3 +93,24 @@ describe('memberOverviewParams', () => {
93
93
  expect(next.get('apiGroup')).toBe('jobset.x-k8s.io')
94
94
  })
95
95
  })
96
+
97
+ describe('isPrometheusMetricsAvailable', () => {
98
+ it('offers metrics for a core Node', () => {
99
+ expect(isPrometheusMetricsAvailable('Node', { apiVersion: 'v1', kind: 'Node' }, true)).toBe(true)
100
+ expect(isPrometheusMetricsAvailable('Node', undefined, true)).toBe(true)
101
+ })
102
+
103
+ it('offers no metrics for a Longhorn Node', () => {
104
+ const longhornNode = { apiVersion: 'longhorn.io/v1beta2', kind: 'Node' }
105
+ expect(isPrometheusMetricsAvailable('Node', longhornNode, false)).toBe(false)
106
+ expect(isPrometheusMetricsAvailable('Node', longhornNode, true)).toBe(false)
107
+ expect(isPrometheusMetricsAvailable('Node', undefined, false)).toBe(false)
108
+ })
109
+
110
+ it('keeps the workload rules', () => {
111
+ expect(isPrometheusMetricsAvailable('Deployment', {}, false)).toBe(true)
112
+ expect(isPrometheusMetricsAvailable('Pod', { status: { phase: 'Pending' } }, false)).toBe(false)
113
+ expect(isPrometheusMetricsAvailable('Pod', { status: { phase: 'Running' } }, false)).toBe(true)
114
+ expect(isPrometheusMetricsAvailable('ConfigMap', {}, false)).toBe(false)
115
+ })
116
+ })
@@ -37,6 +37,7 @@ import {
37
37
  } from '@skyhook-io/k8s-ui'
38
38
  import type { ServicePortRenderProps } from '@skyhook-io/k8s-ui/components/resources/renderers/ServiceRenderer'
39
39
  import { isJobSetV1Alpha2 } from '@skyhook-io/k8s-ui/components/resources/resource-utils-jobset-lws'
40
+ import { isCoreNode as isCoreNodeObject } from '@skyhook-io/k8s-ui/components/resources/resource-utils'
40
41
  import { SUBSTRATE_GROUP } from '@skyhook-io/k8s-ui/components/resources/resource-utils-agent-runtimes'
41
42
  import type { SelectedResource, ResourceRef, Relationships, ResourceWithRelationships } from '../../types'
42
43
  import { CronJobSchedulingContext, CronJobSchedulingDetails } from './CronJobSchedulingEvidence'
@@ -99,10 +100,12 @@ import {
99
100
  fetchJSON,
100
101
  fetchYamlSchemas,
101
102
  } from '../../api/client'
102
- import { PrometheusCharts, isPrometheusSupported } from '../resource/PrometheusCharts'
103
+ import { TIME_RANGES, PrometheusCharts, isPrometheusSupported } from '../resource/PrometheusCharts'
104
+ import { RightsizingStrip } from '../resource/RightsizingStrip'
103
105
  import { PrometheusChartsGrid } from '../resource/PrometheusChartsGrid'
106
+ import { DatadogSetupHint, DatadogWorkloadCharts, useDatadogWorkloadCharts, WorkloadCostRightsizing } from '../resource/DatadogWorkloadCharts'
107
+ import { useNavCustomization } from '../../context/NavCustomization'
104
108
  import { RestartEventLane } from '../resource/RestartChart'
105
- import { RightsizingPanel } from '../resource/RightsizingStrip'
106
109
  import { WorkloadCostTab } from '../cost/WorkloadCostTab'
107
110
  import { isOpenCostWorkloadKind } from '../cost/kinds'
108
111
  import { isRadarFeatureUnsupported } from '../../api/radarFeatures'
@@ -178,6 +181,14 @@ export function supportsBatchExecution(kind: string, apiKind: string, group?: st
178
181
  return true
179
182
  }
180
183
 
184
+ // Longhorn serves a `nodes` plural whose objects are also Kind Node; node metrics
185
+ // only exist for the core Node.
186
+ export function isPrometheusMetricsAvailable(kind: string, resource: any, coreNodeRoute: boolean): boolean {
187
+ if (!isPrometheusSupported(kind)) return false
188
+ if (kind === 'Node') return coreNodeRoute && isCoreNodeObject(resource)
189
+ return !(kind === 'Pod' && resource?.status?.phase === 'Pending')
190
+ }
191
+
181
192
  // ============================================================================
182
193
  // ROUTE WRAPPER — parses kind/ns/name from URL
183
194
  // ============================================================================
@@ -390,6 +401,7 @@ function useActionsBarProps(
390
401
  const argoResumeMutation = useArgoResume()
391
402
  const { upgrade: argoResumeUpgrade, blockedReason: argoResumeBlockedReason } = useRadarFeature('argoAutoSyncEnable')
392
403
  const { support: argoInheritanceSupport } = useRadarFeature('argoSyncInheritance')
404
+ const { support: cronJobJobNameSupport } = useRadarFeature('cronJobTriggerJobName')
393
405
 
394
406
  const {
395
407
  data: cascadePreview,
@@ -487,9 +499,11 @@ function useActionsBarProps(
487
499
  ? (params: { namespace: string; name: string }) =>
488
500
  rolloutDialogPromote.mutateAsync({ action: 'promote-full', ...params })
489
501
  : undefined,
502
+ // mutateAsync, not mutate: the Job name dialog stays open when this rejects.
490
503
  onTriggerCronJob: (params: Parameters<typeof triggerCronJobMutation.mutate>[0]) =>
491
- triggerCronJobMutation.mutate(params),
504
+ triggerCronJobMutation.mutateAsync(params),
492
505
  isTriggeringCronJob: triggerCronJobMutation.isPending,
506
+ cronJobTriggerDialog: cronJobJobNameSupport === 'supported',
493
507
  onSuspendCronJob: (params: Parameters<typeof suspendCronJobMutation.mutate>[0]) =>
494
508
  suspendCronJobMutation.mutate(params),
495
509
  isSuspendingCronJob: suspendCronJobMutation.isPending,
@@ -1351,7 +1365,7 @@ export function WorkloadView({
1351
1365
  )}
1352
1366
  renderCostTab={({ kind, namespace: ns, name: n }) => (
1353
1367
  <div className="space-y-4">
1354
- <RightsizingPanel kind={kind} namespace={ns} name={n} />
1368
+ <WorkloadCostRightsizing kind={kind} namespace={ns} name={n} />
1355
1369
  <WorkloadCostTab kind={kind} namespace={ns} name={n} />
1356
1370
  </div>
1357
1371
  )}
@@ -1377,7 +1391,7 @@ export function WorkloadView({
1377
1391
  />
1378
1392
  )}
1379
1393
  isMetricsAvailable={(kind, res) =>
1380
- isSubstrateWorkerPool || (isPrometheusSupported(kind) && !(kind === 'Pod' && res?.status?.phase === 'Pending'))
1394
+ isSubstrateWorkerPool || isPrometheusMetricsAvailable(kind, res, isNode)
1381
1395
  }
1382
1396
  isCostAvailable={(kind) => isOpenCostWorkloadKind(kind)}
1383
1397
  onDuplicate={handleDuplicate}
@@ -2255,7 +2269,7 @@ function DiagnoseInlineSection({ kind, namespace, name, group, onOpenReachabilit
2255
2269
  // Drawer mode: single chart + category tabs (compact for ~500px width).
2256
2270
  // Full-screen mode: multi-chart grid so CPU + Memory + Network can be
2257
2271
  // compared side-by-side without tab switching.
2258
- function MetricsTabContent({
2272
+ export function MetricsTabContent({
2259
2273
  kind,
2260
2274
  namespace,
2261
2275
  name,
@@ -2271,20 +2285,47 @@ function MetricsTabContent({
2271
2285
  /** False when content follows, so the tab scrolls everything as one. */
2272
2286
  fill?: boolean
2273
2287
  }) {
2274
- if (expanded) {
2275
- if (!fill) return <PrometheusChartsGrid kind={kind} namespace={namespace} name={name} resource={resource} fill={false} />
2276
- return (
2277
- <div className="flex flex-col h-full">
2278
- <div className="flex-1 min-h-0">
2279
- <PrometheusChartsGrid kind={kind} namespace={namespace} name={name} resource={resource} />
2280
- </div>
2288
+ const [params] = useSearchParams()
2289
+ const range = TIME_RANGES.find((option) => option.value === params.get('metricsRange'))?.value ?? '1h'
2290
+ const workload = { kind, namespace, name }
2291
+ const { embedded = false } = useNavCustomization()
2292
+ const { charts, rightsizing, checking, configured, setup } = useDatadogWorkloadCharts(workload, range, embedded)
2293
+ if (configured) {
2294
+ const workloadTotals = (
2295
+ <DatadogWorkloadCharts charts={charts.data?.configured ? charts.data.charts : undefined}
2296
+ loading={charts.isLoading} error={charts.error} onRetry={() => void charts.refetch()} />
2297
+ )
2298
+ if (rightsizing) return (
2299
+ <div className={fill ? 'h-full overflow-auto' : undefined}>
2300
+ <PrometheusChartsGrid {...workload} resource={resource} workloadTotals={workloadTotals} fill={false} showRightsizing={false} />
2301
+ <div className="px-4 pb-4">{rightsizing}</div>
2281
2302
  </div>
2282
2303
  )
2304
+ return <PrometheusChartsGrid {...workload} resource={resource} workloadTotals={workloadTotals} fill={fill} />
2283
2305
  }
2306
+ if (checking) return <p role="status" className="p-4 text-sm text-theme-text-secondary">Loading workload metrics…</p>
2284
2307
 
2285
- // Drawer fallback: single chart with tabs + restart lane below. The chart's
2286
- // time-range selector is mirrored to the restart lane so they stay aligned.
2287
- return <DrawerMetricsContent kind={kind} namespace={namespace} name={name} resource={resource} />
2308
+ const setupHint = setup && <DatadogSetupHint owner={setup === 'owner'} />
2309
+ if (rightsizing || !expanded) {
2310
+ return (
2311
+ <div className={fill ? 'h-full overflow-auto' : undefined}>
2312
+ {setupHint}
2313
+ {expanded
2314
+ ? <PrometheusChartsGrid {...workload} resource={resource} fill={false} showRightsizing={false} />
2315
+ : <DrawerMetricsContent {...workload} resource={resource} />}
2316
+ <div className="px-4 pb-4">{rightsizing ?? <RightsizingStrip {...workload} />}</div>
2317
+ </div>
2318
+ )
2319
+ }
2320
+ if (!fill) return <PrometheusChartsGrid {...workload} resource={resource} fill={false} />
2321
+ return (
2322
+ <div className="flex flex-col h-full">
2323
+ {setupHint}
2324
+ <div className="flex-1 min-h-0">
2325
+ <PrometheusChartsGrid {...workload} resource={resource} />
2326
+ </div>
2327
+ </div>
2328
+ )
2288
2329
  }
2289
2330
 
2290
2331
  function DrawerMetricsContent({
@@ -44,6 +44,7 @@ describe('shouldAutoRetryConnection', () => {
44
44
  expect(shouldAutoRetryConnection('config')).toBe(false)
45
45
  expect(shouldAutoRetryConnection('rbac')).toBe(false)
46
46
  expect(shouldAutoRetryConnection('settings')).toBe(false)
47
+ expect(shouldAutoRetryConnection('switch-stopped')).toBe(false)
47
48
  })
48
49
  })
49
50