@skyhook-io/radar-app 1.19.0 → 1.20.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.
Files changed (173) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -5
  3. package/src/App.tsx +31 -5
  4. package/src/api/application-evidence.ts +63 -0
  5. package/src/api/argoSync.test.ts +22 -0
  6. package/src/api/client.audit-gating.test.tsx +48 -0
  7. package/src/api/client.kueuePosition.test.ts +32 -0
  8. package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
  9. package/src/api/client.resource-identity.test.ts +3 -0
  10. package/src/api/client.resourceIssues.test.tsx +239 -0
  11. package/src/api/client.resourcePath.test.ts +3 -0
  12. package/src/api/client.ts +285 -55
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.ts +4 -0
  15. package/src/api/radarFeatures.render.test.tsx +33 -1
  16. package/src/api/radarFeatures.test.ts +47 -0
  17. package/src/api/radarFeatures.ts +40 -1
  18. package/src/api/rbac.settled.test.tsx +42 -0
  19. package/src/api/rbac.test.ts +18 -0
  20. package/src/api/rbac.ts +37 -7
  21. package/src/api/traffic.ts +9 -4
  22. package/src/api/usage-data.fixtures.ts +3 -1
  23. package/src/api/usage-data.test.tsx +134 -0
  24. package/src/api/usage-data.ts +35 -7
  25. package/src/api/workloadPodsPolling.test.ts +26 -0
  26. package/src/components/CloudConnectFlow.test.tsx +86 -0
  27. package/src/components/CloudConnectFlow.tsx +65 -27
  28. package/src/components/CloudFunnelButton.test.tsx +140 -5
  29. package/src/components/CloudFunnelButton.tsx +50 -9
  30. package/src/components/ConnectionErrorView.test.tsx +34 -0
  31. package/src/components/ConnectionErrorView.tsx +35 -11
  32. package/src/components/ContextSwitcher.tsx +5 -2
  33. package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
  34. package/src/components/SwitchAwareConnectionError.tsx +85 -0
  35. package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
  36. package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
  37. package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
  38. package/src/components/capacity/CapacityDemand.tsx +3 -2
  39. package/src/components/capacity/demandSummary.test.ts +38 -0
  40. package/src/components/capacity/shared.tsx +12 -1
  41. package/src/components/cost/ApplicationCostTab.tsx +4 -0
  42. package/src/components/cost/CostTrendChart.tsx +2 -0
  43. package/src/components/cost/WorkloadCostTab.tsx +4 -0
  44. package/src/components/cost/source.test.ts +5 -0
  45. package/src/components/cost/source.ts +11 -0
  46. package/src/components/diagnose/AIMarkdown.tsx +3 -0
  47. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  48. package/src/components/diagnose/AgentSetupNotice.tsx +21 -3
  49. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  50. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  51. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  52. package/src/components/diagnose/DiagnoseContext.question.test.tsx +1 -1
  53. package/src/components/diagnose/DiagnoseContext.tsx +68 -2
  54. package/src/components/diagnose/DiagnoseSurface.tsx +58 -113
  55. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  56. package/src/components/diagnose/Home.test.tsx +26 -0
  57. package/src/components/diagnose/Home.tsx +20 -1
  58. package/src/components/diagnose/InvestigationEvidenceSections.tsx +45 -22
  59. package/src/components/diagnose/InvestigationView.tsx +94 -26
  60. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  61. package/src/components/diagnose/LocalDiagnoseAction.tsx +354 -35
  62. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  63. package/src/components/diagnose/NextStepJump.tsx +75 -0
  64. package/src/components/diagnose/QuestionComposer.tsx +8 -0
  65. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  66. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  67. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  68. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  69. package/src/components/diagnose/investigationCase.test.tsx +9 -1
  70. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  71. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +50 -2
  72. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  73. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  74. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  75. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  76. package/src/components/diagnose/investigationEvidence/types.ts +5 -0
  77. package/src/components/diagnose/investigationState.ts +28 -0
  78. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  79. package/src/components/diagnose/lastInvestigation.ts +58 -0
  80. package/src/components/diagnose/launch.test.ts +125 -1
  81. package/src/components/diagnose/launch.ts +57 -10
  82. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  83. package/src/components/execution/BatchExecutionView.tsx +24 -11
  84. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  85. package/src/components/execution/JobSetAdmission.tsx +18 -3
  86. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  87. package/src/components/execution/runState.test.ts +14 -0
  88. package/src/components/execution/runState.ts +8 -0
  89. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  90. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  91. package/src/components/gitops/GitOpsView.tsx +86 -17
  92. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  93. package/src/components/gitops/destination-toast.test.ts +1 -1
  94. package/src/components/gitops/destination-toast.ts +2 -2
  95. package/src/components/home/ClusterHealthCard.tsx +1 -1
  96. package/src/components/home/HomeAgentBlock.test.tsx +31 -3
  97. package/src/components/home/HomeAgentBlock.tsx +13 -4
  98. package/src/components/home/HomeDiagramCard.tsx +47 -0
  99. package/src/components/home/HomeView.tsx +81 -41
  100. package/src/components/home/MCPSetupDialog.test.tsx +95 -5
  101. package/src/components/home/MCPSetupDialog.tsx +30 -5
  102. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  103. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  104. package/src/components/home/TopologyPreview.test.tsx +73 -0
  105. package/src/components/home/TopologyPreview.tsx +120 -233
  106. package/src/components/home/TrafficSummary.test.tsx +63 -0
  107. package/src/components/home/TrafficSummary.tsx +135 -138
  108. package/src/components/home/mcpToolCatalog.ts +23 -10
  109. package/src/components/issues/IssuesPane.test.ts +11 -0
  110. package/src/components/issues/IssuesPane.tsx +15 -5
  111. package/src/components/issues/uncheckedSources.test.ts +20 -1
  112. package/src/components/issues/uncheckedSources.ts +18 -0
  113. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  114. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  115. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  116. package/src/components/kueue/useRelatedReads.ts +205 -0
  117. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  118. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  119. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  120. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  121. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  122. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  123. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  124. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  125. package/src/components/logs/rayClusterPods.ts +32 -0
  126. package/src/components/outageSince.test.ts +21 -0
  127. package/src/components/outageSince.ts +10 -0
  128. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  129. package/src/components/resource/PrometheusCharts.tsx +3 -40
  130. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  131. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  132. package/src/components/resources/crd/host.tsx +14 -0
  133. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  134. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  135. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  136. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  137. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  138. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  139. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  140. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  141. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  142. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  143. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  144. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  145. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  146. package/src/components/traffic/TrafficView.tsx +3 -3
  147. package/src/components/ui/command-items-crd.test.tsx +23 -0
  148. package/src/components/ui/command-items.ts +2 -1
  149. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  150. package/src/components/useContextSwitchFlow.tsx +21 -4
  151. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  152. package/src/components/whats-new/WhatsNew.tsx +5 -1
  153. package/src/components/whats-new/WhatsNewDialog.test.tsx +17 -3
  154. package/src/components/whats-new/releaseNotes.ts +77 -4
  155. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  156. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  157. package/src/components/workload/WorkloadView.test.ts +10 -1
  158. package/src/components/workload/WorkloadView.tsx +85 -98
  159. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  160. package/src/components/workload/issueResourceOpener.ts +17 -0
  161. package/src/context/ConnectionContext.tsx +133 -60
  162. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  163. package/src/context/ContextSwitchContext.tsx +14 -1
  164. package/src/context/DiagnoseCustomization.tsx +3 -0
  165. package/src/context/clusterConnected.ts +10 -0
  166. package/src/contexts/CapabilitiesContext.tsx +6 -4
  167. package/src/hooks/useElementSize.ts +30 -0
  168. package/src/integrations/resourceHost.test.tsx +1 -0
  169. package/src/integrations/resourceHost.ts +5 -1
  170. package/src/integrations/resourceHosts.test.tsx +21 -4
  171. package/src/integrations/resourceHosts.tsx +12 -0
  172. package/src/main.tsx +5 -0
  173. package/src/utils/related-findings.ts +46 -0
@@ -0,0 +1,120 @@
1
+ import { useEffect } from 'react'
2
+ import { clsx } from 'clsx'
3
+ import { Terminal } from 'lucide-react'
4
+ import { Tooltip } from '@skyhook-io/k8s-ui'
5
+ import { usePodLogs, useResource } from '../../api/client'
6
+ import type { ResourceRef } from '../../types'
7
+ import { LogsViewer } from './LogsViewer'
8
+ import { PodLogsUnavailable } from './PodLogsUnavailable'
9
+
10
+ export function MultiPodLogsTab({
11
+ pods,
12
+ namespace,
13
+ selectedPod,
14
+ onSelectPod,
15
+ initialContainer,
16
+ defaultPod,
17
+ selectedPodNote,
18
+ emptyMessage = 'No pods available',
19
+ }: {
20
+ pods: ResourceRef[]
21
+ namespace: string
22
+ selectedPod: string | null
23
+ onSelectPod: (name: string | null) => void
24
+ initialContainer?: string | null
25
+ /** Opened when nothing is selected; the first Pod otherwise. */
26
+ defaultPod?: string
27
+ /** Shown instead of the viewer when the caller knows the selected Pod has no output yet. */
28
+ selectedPodNote?: string
29
+ emptyMessage?: string
30
+ }) {
31
+ useEffect(() => {
32
+ if (pods.length > 0 && !selectedPod) {
33
+ onSelectPod(pods.some((p) => p.name === defaultPod) ? defaultPod! : pods[0].name)
34
+ }
35
+ }, [pods, selectedPod, onSelectPod, defaultPod])
36
+
37
+ const podNamespace = pods.find((p) => p.name === selectedPod)?.namespace || namespace
38
+
39
+ const readable = selectedPod && !selectedPodNote ? selectedPod : ''
40
+ const { data: logsData, error: containersError } = usePodLogs(podNamespace, readable, {
41
+ tailLines: 1,
42
+ })
43
+ const containers = logsData?.containers || []
44
+
45
+ // A terminated pod (common for Job/CronJob children) has nothing to follow —
46
+ // only stream live ones. Wait for the pod to load before deciding so we don't
47
+ // briefly auto-stream a completed pod while its phase is still unknown.
48
+ const { data: selectedPodResource } = useResource<any>('Pod', podNamespace, readable)
49
+ const phase = selectedPodResource?.status?.phase
50
+ const autoStream = !!phase && phase !== 'Succeeded' && phase !== 'Failed'
51
+
52
+ // A selected Pod that left the list (deleted, replaced, or not in a newer
53
+ // list) stays selectable so its loaded lines aren't thrown away, but is
54
+ // marked, and the other Pods stay one click away.
55
+ const unlisted = selectedPod && !pods.some((p) => p.name === selectedPod) ? selectedPod : null
56
+ const chips = unlisted ? [...pods, { kind: 'Pod', namespace: podNamespace, name: unlisted }] : pods
57
+
58
+ if (chips.length === 0) {
59
+ return (
60
+ <div className="flex flex-col items-center justify-center h-full text-theme-text-tertiary">
61
+ <Terminal className="w-12 h-12 mb-4 opacity-50" />
62
+ <p>{emptyMessage}</p>
63
+ </div>
64
+ )
65
+ }
66
+
67
+ return (
68
+ <div className="h-full flex flex-col">
69
+ {(chips.length > 1 || unlisted) && (
70
+ <div className="shrink-0 border-b border-theme-border bg-theme-surface/50 px-4 py-2 flex gap-2 overflow-x-auto">
71
+ {chips.map((pod) => (
72
+ <Tooltip key={pod.name} content={pod.name} disabled={pod.name.length <= 40}>
73
+ <button
74
+ onClick={() => onSelectPod(pod.name)}
75
+ aria-pressed={selectedPod === pod.name}
76
+ aria-label={
77
+ pod.name.length > 40 ? `${pod.name}${pod.name === unlisted ? ', not in this list' : ''}` : undefined
78
+ }
79
+ className={clsx(
80
+ 'px-3 py-1.5 text-sm rounded-lg whitespace-nowrap transition-colors',
81
+ selectedPod === pod.name
82
+ ? 'selection-strong selection-text'
83
+ : 'bg-theme-elevated text-theme-text-secondary hover:bg-theme-hover',
84
+ )}
85
+ >
86
+ {pod.name.length > 40 ? '...' + pod.name.slice(-37) : pod.name}
87
+ {pod.name === unlisted && <span className="ml-1.5 text-xs opacity-75">· not in this list</span>}
88
+ </button>
89
+ </Tooltip>
90
+ ))}
91
+ </div>
92
+ )}
93
+ {selectedPod && selectedPodNote && (
94
+ <div
95
+ role="status"
96
+ className="flex flex-1 flex-col items-center justify-center gap-1 px-6 text-center text-theme-text-tertiary"
97
+ >
98
+ <Terminal className="mb-3 h-12 w-12 opacity-50" />
99
+ <p className="text-sm font-medium text-theme-text-secondary">No logs shown for {selectedPod}</p>
100
+ <p className="text-sm">{selectedPodNote}</p>
101
+ </div>
102
+ )}
103
+ {selectedPod && !selectedPodNote && containersError && !logsData && (
104
+ <PodLogsUnavailable podName={selectedPod} error={containersError} />
105
+ )}
106
+ {selectedPod && !selectedPodNote && containers.length > 0 && (
107
+ <div className="flex-1 min-h-0">
108
+ <LogsViewer
109
+ key={selectedPod}
110
+ namespace={podNamespace}
111
+ podName={selectedPod}
112
+ containers={containers}
113
+ initialContainer={initialContainer || undefined}
114
+ autoStream={autoStream}
115
+ />
116
+ </div>
117
+ )}
118
+ </div>
119
+ )
120
+ }
@@ -0,0 +1,18 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+ vi.mock('../../api/client', () => ({ isNotFoundError: (e: any) => e?.status === 404 }))
4
+ const { PodLogsUnavailable } = await import('./PodLogsUnavailable')
5
+
6
+ describe('PodLogsUnavailable', () => {
7
+ it('says a deleted Pod has no logs left instead of rendering nothing', () => {
8
+ const html = renderToStaticMarkup(<PodLogsUnavailable podName="worker-1" error={Object.assign(new Error('Pod not found'), { status: 404 })} />)
9
+ expect(html).toContain('Radar can&#x27;t find worker-1')
10
+ expect(html).toContain('Kubernetes serves no logs for a deleted Pod')
11
+ })
12
+ it('shows the server reason for any other failure', () => {
13
+ const html = renderToStaticMarkup(<PodLogsUnavailable podName="worker-1" error={Object.assign(new Error('no access to pod logs in namespace ml: requires get pods/log'), { status: 403 })} />)
14
+ expect(html).toContain('Logs for worker-1 are unavailable')
15
+ expect(html).toContain('requires get pods/log')
16
+ expect(html).not.toContain('can&#x27;t find')
17
+ })
18
+ })
@@ -0,0 +1,21 @@
1
+ import { Terminal } from 'lucide-react'
2
+ import { isNotFoundError } from '../../api/client'
3
+
4
+ // Generic Pod pickers can list Pods recalled from history that no longer
5
+ // exist, and the API server serves no logs for a deleted Pod.
6
+ export function PodLogsUnavailable({ podName, error }: { podName: string; error: unknown }) {
7
+ const gone = isNotFoundError(error)
8
+ return (
9
+ <div role="status" className="flex flex-1 flex-col items-center justify-center gap-1 px-6 text-center text-theme-text-tertiary">
10
+ <Terminal className="mb-3 h-12 w-12 opacity-50" />
11
+ <p className="text-sm font-medium text-theme-text-secondary">
12
+ {gone ? `Radar can't find ${podName}` : `Logs for ${podName} are unavailable`}
13
+ </p>
14
+ <p className="text-sm">
15
+ {gone
16
+ ? 'It may have been deleted, and Kubernetes serves no logs for a deleted Pod. Choose another Pod.'
17
+ : error instanceof Error ? error.message : 'The log request failed.'}
18
+ </p>
19
+ </div>
20
+ )
21
+ }
@@ -0,0 +1,67 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from 'react'
3
+ import { createRoot } from 'react-dom/client'
4
+ import { expect, it, vi } from 'vitest'
5
+
6
+ const state = vi.hoisted(() => ({ query: {} as any }))
7
+ vi.mock('../../api/client', async (original) => ({
8
+ ...await original<typeof import('../../api/client')>(),
9
+ useCapabilities: () => ({ data: { features: { rayClusterPods: true, podSidecarMarks: true } } }),
10
+ useRadarFeature: () => ({ support: 'supported', upgrade: null }),
11
+ useWorkloadPods: () => state.query,
12
+ }))
13
+ vi.mock('../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canViewLogs: true, logsUnknown: false }) }))
14
+ vi.mock('./MultiPodLogsTab', () => ({ MultiPodLogsTab: () => null }))
15
+ vi.mock('@skyhook-io/k8s-ui', () => ({ AlertBanner: () => null, PaneLoader: () => null, RadarUpgradeNote: () => null }))
16
+ const { RayClusterLogsTab } = await import('./RayClusterLogsTab')
17
+ ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
18
+
19
+ const history = [{ kind: 'Pod', namespace: 'ml', name: 'deleted-worker' }]
20
+ const owned = { pods: [{ name: 'failing-worker', ready: false, containers: [] }, { name: 'head', ready: true, containers: [] }], total: 2, truncated: false }
21
+
22
+ function mount(selectedPod: string, onSelectPod = vi.fn()) {
23
+ const host = document.createElement('div')
24
+ const root = createRoot(host)
25
+ const render = () => act(() => root.render(<RayClusterLogsTab namespace="ml" name="c" uid="u" suspendRequested={false} rootLoading={false} rootError={null} historyPods={history} selectedPod={selectedPod} onSelectPod={onSelectPod} />))
26
+ return { render, onSelectPod, unmount: () => act(() => root.unmount()) }
27
+ }
28
+
29
+ it('replaces a recorded Pod picked while the owned list was failing once that list arrives', () => {
30
+ state.query = { error: new Error('cache warming') }
31
+ const view = mount('deleted-worker')
32
+ view.render()
33
+ state.query = { data: owned }
34
+ view.render()
35
+ expect(view.onSelectPod).toHaveBeenCalledWith('failing-worker')
36
+ view.unmount()
37
+ })
38
+
39
+ it('leaves a selection alone when the owned list was showing all along', () => {
40
+ state.query = { data: owned }
41
+ const view = mount('gone-after-selection')
42
+ view.render()
43
+ view.render()
44
+ expect(view.onSelectPod).not.toHaveBeenCalled()
45
+ view.unmount()
46
+ })
47
+
48
+
49
+ it('keeps a recorded selection that is still in the current owned list', () => {
50
+ state.query = { error: new Error('cache warming') }
51
+ const view = mount('head')
52
+ view.render()
53
+ state.query = { data: owned }
54
+ view.render()
55
+ expect(view.onSelectPod).not.toHaveBeenCalled()
56
+ view.unmount()
57
+ })
58
+
59
+ it('keeps a pre-existing selection while the owned list is initially loading', () => {
60
+ state.query = { isLoading: true }
61
+ const view = mount('gone-after-selection')
62
+ view.render()
63
+ state.query = { data: owned }
64
+ view.render()
65
+ expect(view.onSelectPod).not.toHaveBeenCalled()
66
+ view.unmount()
67
+ })
@@ -0,0 +1,167 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+
4
+ const state = vi.hoisted(() => ({ support: 'supported' as string, query: {} as any, calls: [] as any[], tab: null as any, flag: true, canViewLogs: true, capsFailed: false, capsData: true }))
5
+ vi.mock('../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canViewLogs: state.canViewLogs, logsUnknown: false }) }))
6
+ vi.mock('../../api/client', async (original) => {
7
+ const actual = await original<typeof import('../../api/client')>()
8
+ return {
9
+ ...actual,
10
+ useCapabilities: () => ({ data: state.capsData ? { features: { rayClusterPods: true, podSidecarMarks: state.flag } } : undefined, isError: state.capsFailed }),
11
+ useRadarFeature: () => ({ support: state.support, upgrade: state.support === 'unsupported' ? { feature: 'RayCluster runtime Pods', minimumVersion: 'v1.15.0' } : null }),
12
+ useWorkloadPods: (...args: any[]) => { state.calls.push(args); return state.query },
13
+ }
14
+ })
15
+ vi.mock('./MultiPodLogsTab', () => ({ MultiPodLogsTab: (props: any) => { state.tab = props; return <div>pods:{props.pods.map((p: any) => p.name).join(',')}</div> } }))
16
+ vi.mock('@skyhook-io/k8s-ui', () => ({
17
+ AlertBanner: ({ title, message }: any) => <div>{title}: {message}</div>,
18
+ PaneLoader: ({ label }: any) => <div>{label}</div>,
19
+ RadarUpgradeNote: ({ requirement }: any) => <div>upgrade:{requirement.feature} {requirement.minimumVersion}</div>,
20
+ }))
21
+ const { ApiError } = await import('../../api/client')
22
+ const { RayClusterLogsTab } = await import('./RayClusterLogsTab')
23
+ const { isKubeRayCluster } = await import('./rayClusterPods')
24
+
25
+ const history = [{ kind: 'Pod', namespace: 'ml', name: 'deleted-worker' }, { kind: 'Pod', namespace: 'ml', name: 'cluster-head' }]
26
+ const started = (name: string, init = false, ready = true) => ({ name, init, ready, restartCount: 0 })
27
+ const owned = { pods: [
28
+ { name: 'cluster-worker-b', ready: false, phase: 'Pending', containers: ['wait-gcs-ready', 'ray-worker'], containerStatuses: [started('wait-gcs-ready', true, false), started('ray-worker', false, false)] },
29
+ { name: 'cluster-head', ready: true, containers: ['ray-head'], containerStatuses: [started('ray-head')] },
30
+ ], total: 2, truncated: false }
31
+ const render = (uid: string | undefined = 'uid-1', selectedPod: string | null = null) => renderUID(uid, selectedPod)
32
+ const renderUID = (uid: string | undefined, selectedPod: string | null = null, root: { loading?: boolean; error?: Error | null } = {}) => renderToStaticMarkup(
33
+ <RayClusterLogsTab namespace="ml" name="cluster" uid={uid} suspendRequested={false} rootLoading={root.loading ?? false} rootError={root.error ?? null} historyPods={history} selectedPod={selectedPod} onSelectPod={() => {}} />,
34
+ )
35
+
36
+ describe('RayClusterLogsTab', () => {
37
+ beforeEach(() => { state.support = 'supported'; state.query = {}; state.calls = []; state.tab = null; state.flag = true; state.canViewLogs = true; state.capsFailed = false; state.capsData = true })
38
+
39
+ it('lists the Pods the current incarnation owns, by name, not the ones history recalls', () => {
40
+ state.query = { data: owned }
41
+ const html = render()
42
+ expect(state.calls[0]).toEqual(['rayclusters', 'ml', 'cluster', { ownerUID: 'uid-1', limit: 200, refetchInterval: 5000 }])
43
+ expect(html).toContain('pods:cluster-head,cluster-worker-b')
44
+ expect(html).not.toContain('deleted-worker')
45
+ expect(state.tab.emptyMessage).toBe('This RayCluster has no Pods right now.')
46
+ expect(state.tab.defaultPod).toBe('cluster-worker-b')
47
+ })
48
+
49
+ it('opens a selected worker that waits on the head in its init container', () => {
50
+ state.query = { data: owned }
51
+ render('uid-1', 'cluster-worker-b')
52
+ expect(state.tab.initialContainer).toBe('wait-gcs-ready')
53
+ })
54
+
55
+ it('says when the list is capped and how to reach the rest', () => {
56
+ state.query = { data: { ...owned, total: 250, truncated: true } }
57
+ const html = render()
58
+ expect(html).toContain('Showing the 2 least healthy of 250 Pods')
59
+ expect(html).toContain('Runtime Pods on Overview can narrow to the head or one worker group (each view is capped at 200)')
60
+ })
61
+
62
+ it('falls back to the recorded Pods with the reason when the current list is denied', () => {
63
+ state.query = { error: new ApiError('Reading RayCluster Pods requires get rayclusters and list pods in this namespace', 403), data: owned }
64
+ const html = render()
65
+ expect(html).toContain('pods:deleted-worker,cluster-head')
66
+ expect(html).toContain('can include deleted ones')
67
+ expect(html).toContain('requires get rayclusters and list pods')
68
+ expect(state.tab.emptyMessage).toBe('Radar hasn\'t recorded any Pods for this RayCluster.')
69
+ })
70
+
71
+ it('keeps the last list through a passing refresh failure', () => {
72
+ state.query = { error: new ApiError('Cluster connection changed; retry the Pod request', 503), data: owned }
73
+ const html = render()
74
+ expect(html).toContain('pods:cluster-head,cluster-worker-b')
75
+ expect(html).not.toContain('Current Pods unavailable')
76
+ expect(html).toContain('Pod list not refreshed: Showing the last list Radar read. Cluster connection changed')
77
+ })
78
+
79
+ it('asks for a newer Radar instead of requesting a list it cannot serve', () => {
80
+ state.support = 'unsupported'
81
+ const html = render()
82
+ expect(state.calls[0][2]).toBe('')
83
+ expect(html).toContain('upgrade:RayCluster runtime Pods v1.15.0')
84
+ expect(html).toContain('Showing recorded Pods: ')
85
+ expect(html).toContain('pods:deleted-worker,cluster-head')
86
+ })
87
+
88
+ it.each([[{ isLoading: true }, 'uid-1', false], [{}, undefined, true]])('waits rather than flashing recorded Pods (%#)', (query, uid, rootLoading) => {
89
+ state.query = query
90
+ expect(renderUID(uid as string | undefined, null, { loading: rootLoading as boolean })).toContain(uid ? 'Reading runtime Pods' : 'Reading RayCluster')
91
+ expect(state.tab).toBeNull()
92
+ })
93
+
94
+ it('falls back to the recorded Pods when the RayCluster itself could not be read', () => {
95
+ const html = renderUID(undefined, null, { error: new Error('rayclusters.ray.io "cluster" not found') })
96
+ expect(html).toContain('pods:deleted-worker,cluster-head')
97
+ expect(html).toContain('not found')
98
+ expect(html).not.toContain('Reading runtime Pods')
99
+ })
100
+
101
+ it('names an unsupporting Radar rather than echoing its 400 when support is unknown', () => {
102
+ state.support = 'unknown'
103
+ state.query = { error: new ApiError('only deployments, statefulsets, daemonsets, rollouts, jobs, and workflows are supported', 400) }
104
+ const html = render()
105
+ expect(html).toContain('Radar v1.15 and later')
106
+ expect(html).not.toContain('only deployments')
107
+ })
108
+
109
+ it('passes a current Radar\'s own 400 through even when its version is unknown', () => {
110
+ state.support = 'unknown'
111
+ state.query = { error: new ApiError('Expected ray.io/v1 RayCluster', 400) }
112
+ const html = render()
113
+ expect(html).toContain('Expected ray.io/v1 RayCluster')
114
+ expect(html).not.toContain('Radar v1.15 and later')
115
+ })
116
+
117
+ it('still reports a known denial when only a capabilities refetch failed', () => {
118
+ state.canViewLogs = false
119
+ state.capsFailed = true
120
+ state.query = { data: owned }
121
+ expect(render()).toContain('which you don&#x27;t have')
122
+ })
123
+
124
+ it('does not claim a missing permission when capabilities could not be read', () => {
125
+ state.canViewLogs = false
126
+ state.capsFailed = true
127
+ state.capsData = false
128
+ state.query = { data: owned }
129
+ const html = render()
130
+ expect(html).toContain('hasn&#x27;t confirmed whether you can read Pod logs')
131
+ expect(html).not.toContain('which you don&#x27;t have')
132
+ })
133
+
134
+ it('shows why a selected Pod has no output instead of an empty viewer', () => {
135
+ state.query = { data: { pods: [{ name: 'pending-worker', ready: false, containers: ['ray-worker'] }], total: 1, truncated: false } }
136
+ render('uid-1', 'pending-worker')
137
+ expect(state.tab.selectedPodNote).toBe('Not scheduled')
138
+ })
139
+
140
+ it('says once, up front, when Pod logs are not readable here, and fetches none', () => {
141
+ state.canViewLogs = false
142
+ state.query = { data: owned }
143
+ expect(render()).toContain('needs get on pods/log')
144
+ expect(state.tab.selectedPodNote).toBe('You can\'t read Pod logs in this namespace.')
145
+ })
146
+
147
+ it('says what happened when an older Radar has no recorded Pods either', () => {
148
+ state.support = 'unsupported'
149
+ const html = renderToStaticMarkup(<RayClusterLogsTab namespace="ml" name="cluster" uid="uid-1" suspendRequested={false} rootLoading={false} rootError={null} historyPods={[]} selectedPod={null} onSelectPod={() => {}} />)
150
+ expect(state.tab.emptyMessage).toBe('Radar hasn\'t recorded any Pods for this RayCluster.')
151
+ expect(html).not.toContain('Showing recorded Pods')
152
+ })
153
+
154
+ it('names a requested suspension when the cluster has no Pods', () => {
155
+ state.query = { data: { pods: [], total: 0, truncated: false } }
156
+ renderToStaticMarkup(<RayClusterLogsTab namespace="ml" name="cluster" uid="uid-1" suspendRequested rootLoading={false} rootError={null} historyPods={history} selectedPod={null} onSelectPod={() => {}} />)
157
+ expect(state.tab.emptyMessage).toBe('This RayCluster has no Pods right now. Its suspension is requested.')
158
+ })
159
+
160
+ it('applies only to the KubeRay ray.io/v1 RayCluster', () => {
161
+ expect(isKubeRayCluster('RayCluster', 'ray.io', 'ray.io/v1')).toBe(true)
162
+ expect(isKubeRayCluster('RayCluster', 'ray.io', undefined)).toBe(true)
163
+ expect(isKubeRayCluster('RayCluster', 'ray.io', 'ray.io/v1alpha1')).toBe(false)
164
+ expect(isKubeRayCluster('RayCluster', 'example.io', 'example.io/v1')).toBe(false)
165
+ expect(isKubeRayCluster('RayJob', 'ray.io', 'ray.io/v1')).toBe(false)
166
+ })
167
+ })
@@ -0,0 +1,109 @@
1
+ import { useEffect, useRef } from 'react'
2
+ import { AlertBanner, PaneLoader, RadarUpgradeNote } from '@skyhook-io/k8s-ui'
3
+ import { logsContainer, podLogsUnavailableReason } from '@skyhook-io/k8s-ui/components/resources/resource-utils-ray'
4
+ import { isStableClientError, useRadarFeature, useWorkloadPods } from '../../api/client'
5
+ import type { ResourceRef } from '../../types'
6
+ import { MultiPodLogsTab } from './MultiPodLogsTab'
7
+ import { rayClusterPodsError, useLogsReadability, useSidecarsMarked } from './rayClusterPods'
8
+
9
+ // The generic Logs tab lists Pods recalled from history, deleted ones
10
+ // included. A RayCluster's tab lists the Pods its current incarnation owns
11
+ // instead (the same request as the renderer's Runtime Pods), and falls back to
12
+ // the history list, saying so, when that list can't be read: the route needs
13
+ // get rayclusters and list pods, which a reader of Pod logs may lack.
14
+ export function RayClusterLogsTab({
15
+ namespace,
16
+ name,
17
+ uid,
18
+ suspendRequested,
19
+ rootLoading,
20
+ rootError,
21
+ historyPods,
22
+ selectedPod,
23
+ onSelectPod,
24
+ }: {
25
+ namespace: string
26
+ name: string
27
+ uid: string | undefined
28
+ suspendRequested: boolean
29
+ rootLoading: boolean
30
+ rootError: Error | null
31
+ historyPods: ResourceRef[]
32
+ selectedPod: string | null
33
+ onSelectPod: (name: string | null) => void
34
+ }) {
35
+ const { support, upgrade } = useRadarFeature('rayClusterPods')
36
+ const sidecarsMarked = useSidecarsMarked()
37
+ const readability = useLogsReadability(namespace)
38
+ const logsDenied = readability === 'denied'
39
+ const unsupported = support === 'unsupported'
40
+ const query = useWorkloadPods('rayclusters', namespace, uid && !unsupported ? name : '', { ownerUID: uid, limit: 200, refetchInterval: 5000 })
41
+ const owned = !unsupported && uid && query.data && !isStableClientError(query.error) ? query.data : undefined
42
+ const defaultPod = owned?.pods[0]?.name
43
+ const loading = !unsupported && (uid ? query.isLoading : rootLoading)
44
+
45
+ // A pick made from the recorded Pods while the owned list was failing gives
46
+ // way to the owned list's first Pod once it arrives, unless still owned:
47
+ // the recorded Pod may well be deleted.
48
+ // Only a recorded list actually shown counts: a selection that predates
49
+ // this tab (a deep link, or a Pod that has since left the owned list) stays.
50
+ const showedRecorded = useRef(false)
51
+ useEffect(() => {
52
+ if (!owned) { if (!loading) showedRecorded.current = true; return }
53
+ if (showedRecorded.current && defaultPod && selectedPod && !owned.pods.some(pod => pod.name === selectedPod)) onSelectPod(defaultPod)
54
+ showedRecorded.current = false
55
+ }, [owned, loading, defaultPod, selectedPod, onSelectPod])
56
+
57
+ if (loading) return <PaneLoader label={uid ? 'Reading runtime Pods…' : 'Reading RayCluster…'} className="h-full" />
58
+
59
+ // Shown by name so the strip holds still while health changes; the least
60
+ // healthy Pod (the route's order) is the one opened first.
61
+ const pods: ResourceRef[] = owned
62
+ ? [...owned.pods].sort((a, b) => a.name.localeCompare(b.name)).map(pod => ({ kind: 'Pod', namespace, name: pod.name }))
63
+ : historyPods
64
+ const selected = owned?.pods.find(pod => pod.name === selectedPod)
65
+ const container = selected ? logsContainer(selected, sidecarsMarked) : undefined
66
+ const reason = unsupported ? '' : !uid ? rootError?.message ?? 'The RayCluster could not be read.' : rayClusterPodsError(query.error, support) ?? 'Its current Pods could not be read.'
67
+ const refreshError = owned && query.error ? rayClusterPodsError(query.error, support) : undefined
68
+ const sentence = (text: string) => /[.!?]$/.test(text) ? text : `${text}.`
69
+
70
+ return (
71
+ <div className="flex h-full flex-col">
72
+ {unsupported && upgrade && <div className="shrink-0 px-4 pt-3"><RadarUpgradeNote requirement={upgrade} /></div>}
73
+ {owned?.truncated && (
74
+ <div className="shrink-0 px-4 pt-3">
75
+ <AlertBanner variant="info" title="Pod list capped" message={`Showing the ${owned.pods.length} least healthy of ${owned.total} Pods. Runtime Pods on Overview can narrow to the head or one worker group (each view is capped at 200), with a Logs button on each Pod.`} />
76
+ </div>
77
+ )}
78
+ {readability !== 'allowed' && (
79
+ <div className="shrink-0 px-4 pt-3">
80
+ {logsDenied
81
+ ? <AlertBanner variant="warning" title="Pod logs not readable" message="Reading a Pod's logs in this namespace needs get on pods/log, which you don't have. The Pods are listed so you can see which exist." />
82
+ : <AlertBanner variant="info" title="Permissions not checked" message="Radar hasn't confirmed whether you can read Pod logs here; a Pod's logs say so if you can't." />}
83
+ </div>
84
+ )}
85
+ {refreshError && (
86
+ <div className="shrink-0 px-4 pt-3">
87
+ <AlertBanner variant="info" title="Pod list not refreshed" message={`Showing the last list Radar read. ${sentence(refreshError)}`} />
88
+ </div>
89
+ )}
90
+ {!owned && (historyPods.length > 0 || reason) && (
91
+ <div className="shrink-0 px-4 pt-3">
92
+ <AlertBanner variant={unsupported ? 'info' : 'warning'} title={unsupported ? 'Showing recorded Pods' : 'Current Pods unavailable'} message={`Showing Pods Radar has recorded for this RayCluster, which can include deleted ones.${reason ? ` ${sentence(reason)}` : ''}`} />
93
+ </div>
94
+ )}
95
+ <div className="min-h-0 flex-1">
96
+ <MultiPodLogsTab
97
+ pods={pods}
98
+ namespace={namespace}
99
+ selectedPod={selectedPod}
100
+ onSelectPod={onSelectPod}
101
+ defaultPod={defaultPod}
102
+ initialContainer={container}
103
+ selectedPodNote={logsDenied ? 'You can\'t read Pod logs in this namespace.' : selected ? podLogsUnavailableReason(selected) : undefined}
104
+ emptyMessage={owned ? `This RayCluster has no Pods right now.${suspendRequested ? ' Its suspension is requested.' : ''}` : 'Radar hasn\'t recorded any Pods for this RayCluster.'}
105
+ />
106
+ </div>
107
+ </div>
108
+ )
109
+ }
@@ -4,6 +4,7 @@ import { clsx } from 'clsx'
4
4
  import { useWorkloadRuns, useResource, type WorkloadRun } from '../../api/client'
5
5
  import { WorkloadLogsViewer } from './WorkloadLogsViewer'
6
6
  import { pickDefaultRun, selectedRunMissing, workloadRunKey } from '../execution/BatchExecutionView'
7
+ import { runStateLabel } from '../execution/runState'
7
8
 
8
9
  interface ScheduledWorkloadLogsViewerProps {
9
10
  kind: string
@@ -127,7 +128,7 @@ function ScheduledWorkloadLogsContent({ kind, namespace, name, selectedRunKey, o
127
128
  ))}
128
129
  </select>
129
130
  <span className={clsx('badge-sm', phaseBadgeClass(selectedRun.phase))}>
130
- {selectedRun.phase}{selectedRun.deleting ? ' · deleting' : ''}
131
+ {runStateLabel(selectedRun)}
131
132
  </span>
132
133
  <span className="text-xs text-theme-text-tertiary">
133
134
  {formatRunTime(selectedRun)}
@@ -173,7 +174,7 @@ function formatRunTime(run: WorkloadRun): string {
173
174
  }
174
175
 
175
176
  function formatRunOption(run: WorkloadRun, showNamespace: boolean, memberCollection: boolean): string {
176
- const bits = [showNamespace ? `${run.namespace}/${run.name}` : run.name, `${run.phase}${run.deleting ? ' · deleting' : ''}`]
177
+ const bits = [showNamespace ? `${run.namespace}/${run.name}` : run.name, runStateLabel(run)]
177
178
  if (memberCollection && run.jobset?.replicatedJob) {
178
179
  bits.push(`${run.jobset?.replicatedJob}${run.jobset?.jobIndex ? ` #${run.jobset?.jobIndex}` : ''}`)
179
180
  }
@@ -0,0 +1,32 @@
1
+ import { isKubeRayClusterIdentity } from '@skyhook-io/k8s-ui/components/resources/resource-utils-ray'
2
+ import { ApiError, useCapabilities } from '../../api/client'
3
+ import { useNamespacedCapabilities } from '../../contexts/CapabilitiesContext'
4
+ import type { RadarFeatureSupport } from '../../api/radarFeatures'
5
+
6
+ export function isKubeRayCluster(kind: string, group: string | undefined, apiVersion: string | undefined): boolean {
7
+ return kind === 'RayCluster' && isKubeRayClusterIdentity(group, apiVersion)
8
+ }
9
+
10
+ export function useSidecarsMarked(): boolean {
11
+ return useCapabilities().data?.features?.podSidecarMarks === true
12
+ }
13
+
14
+ // What a failed read of a RayCluster's Pods means. Radars before v1.15 reject
15
+ // the kind with "only deployments, …"; when the version can't place the Radar,
16
+ // say which Radar lists RayCluster Pods instead of echoing that. A current
17
+ // Radar's own 400s pass through.
18
+ export function rayClusterPodsError(error: unknown, support: RadarFeatureSupport): string | undefined {
19
+ if (!error) return undefined
20
+ if (error instanceof ApiError && error.status === 400 && support !== 'supported' && /^only deployments/.test(error.message)) return 'This Radar may not list a RayCluster\'s Pods; Radar v1.15 and later do.'
21
+ return error instanceof Error ? error.message : 'The Pod list could not be read.'
22
+ }
23
+
24
+ // Whether this viewer can read Pod logs in a namespace. Unknown while the
25
+ // namespace answer is pending or failed, or when no capabilities answer ever
26
+ // arrived (a failed refetch keeps the last answer).
27
+ export function useLogsReadability(namespace: string): 'allowed' | 'denied' | 'unknown' {
28
+ const { canViewLogs, logsUnknown } = useNamespacedCapabilities(namespace)
29
+ const capabilities = useCapabilities()
30
+ if (canViewLogs) return 'allowed'
31
+ return logsUnknown || (capabilities.isError && !capabilities.data) ? 'unknown' : 'denied'
32
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { outageSinceLabel } from './outageSince'
3
+
4
+ describe('outageSinceLabel', () => {
5
+ it('shows only the time for an outage that started today', () => {
6
+ const now = new Date(2026, 9, 30, 16, 0)
7
+ const started = new Date(2026, 9, 30, 14, 2)
8
+ expect(outageSinceLabel(started.toISOString(), now)).toBe(started.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }))
9
+ })
10
+
11
+ it('adds the date for an outage that started on an earlier day', () => {
12
+ const now = new Date(2026, 9, 30, 9, 0)
13
+ const started = new Date(2026, 9, 29, 22, 15)
14
+ expect(outageSinceLabel(started.toISOString(), now)).toContain(started.toLocaleDateString([], { month: 'short', day: 'numeric' }))
15
+ })
16
+
17
+ it('shows nothing when the server sent no time or an invalid one', () => {
18
+ expect(outageSinceLabel(undefined)).toBeNull()
19
+ expect(outageSinceLabel('not a date')).toBeNull()
20
+ })
21
+ })
@@ -0,0 +1,10 @@
1
+ // "14:02" for an outage that started today, "Oct 29, 14:02" otherwise.
2
+ // Returns null when the server didn't say (older Radar) or sent garbage.
3
+ export function outageSinceLabel(disconnectedAt: string | undefined, now: Date = new Date()): string | null {
4
+ if (!disconnectedAt) return null
5
+ const started = new Date(disconnectedAt)
6
+ if (Number.isNaN(started.getTime())) return null
7
+ const time = started.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
8
+ if (started.toDateString() === now.toDateString()) return time
9
+ return `${started.toLocaleDateString([], { month: 'short', day: 'numeric' })}, ${time}`
10
+ }
@@ -20,6 +20,18 @@ describe('Pod request and limit overlays', () => {
20
20
  expect(computeRequestLimitLines(resource, 'Deployment', 'cpu')![0].value).toBeCloseTo(1.2)
21
21
  })
22
22
 
23
+ it.each([
24
+ ['.5', '1k', 0.5, 1000],
25
+ ['500u', '2.', 0.0005, 2],
26
+ ])('reads CPU request %s and limit %s as cores', (request, limit, wantRequest, wantLimit) => {
27
+ const resource = { spec: { containers: [
28
+ { resources: { requests: { cpu: request }, limits: { cpu: limit } } },
29
+ ] } }
30
+ const lines = computeRequestLimitLines(resource, 'Pod', 'cpu')!
31
+ expect(lines[0].value).toBeCloseTo(wantRequest)
32
+ expect(lines[1].value).toBeCloseTo(wantLimit)
33
+ })
34
+
23
35
  it.each([
24
36
  ['1024000m', '2048000m'],
25
37
  ['1024000000u', '2048000000u'],