@skyhook-io/radar-app 1.21.2 → 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.
- package/README.md +11 -0
- package/package.json +2 -2
- package/src/App.tsx +50 -28
- package/src/api/actions.test.ts +11 -0
- package/src/api/actions.ts +5 -0
- package/src/api/apiResources.navigation.test.tsx +58 -0
- package/src/api/apiResources.ts +22 -16
- package/src/api/client.diagnostics.test.ts +52 -0
- package/src/api/client.triggerCronJob.test.tsx +49 -0
- package/src/api/client.ts +140 -120
- package/src/api/connectionBinding.test.tsx +82 -0
- package/src/api/connectionBinding.ts +52 -0
- package/src/api/contextSwitch.test.ts +11 -0
- package/src/api/contextSwitch.ts +58 -0
- package/src/api/radarFeatures.ts +5 -0
- package/src/components/ConnectionErrorView.tsx +13 -0
- package/src/components/ContextSwitchActions.tsx +43 -0
- package/src/components/ContextSwitcher.tsx +13 -6
- package/src/components/SwitchAwareConnectionError.tsx +2 -2
- package/src/components/cost/ApplicationCostTab.test.ts +16 -0
- package/src/components/cost/ApplicationCostTab.tsx +41 -9
- package/src/components/cost/CostTrendChart.tsx +25 -2
- package/src/components/cost/CostTrendWithheld.render.test.tsx +105 -0
- package/src/components/cost/CostView.tsx +10 -2
- package/src/components/cost/CostViewTabs.test.tsx +18 -0
- package/src/components/cost/CostViewTabs.tsx +14 -22
- package/src/components/cost/WorkloadCostTab.test.ts +15 -0
- package/src/components/cost/WorkloadCostTab.tsx +42 -8
- package/src/components/cost/source.test.ts +16 -1
- package/src/components/cost/source.ts +34 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +35 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +16 -1
- package/src/components/dock/NodeTerminalTab.test.tsx +4 -2
- package/src/components/dock/NodeTerminalTab.tsx +8 -8
- package/src/components/dock/TerminalTab.test.tsx +12 -1
- package/src/components/dock/TerminalTab.tsx +6 -3
- package/src/components/home/CostCard.test.tsx +49 -0
- package/src/components/home/CostCard.tsx +98 -63
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/resource/DatadogRightsizingPanel.test.tsx +118 -0
- package/src/components/resource/DatadogRightsizingPanel.tsx +68 -0
- package/src/components/resource/DatadogWorkloadCharts.tsx +149 -0
- package/src/components/resource/HPACharts.render.test.tsx +42 -0
- package/src/components/resource/HPACharts.tsx +34 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +126 -3
- package/src/components/resource/PrometheusChartsGrid.tsx +58 -25
- package/src/components/resource/RestartChart.render.test.tsx +72 -0
- package/src/components/resource/RestartChart.tsx +31 -3
- package/src/components/resource/RightsizingPanel.access.test.tsx +24 -0
- package/src/components/resource/RightsizingStrip.render.test.tsx +44 -0
- package/src/components/resource/RightsizingStrip.test.ts +1 -188
- package/src/components/resource/RightsizingStrip.tsx +27 -300
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +22 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -4
- package/src/components/resource/nameMatchedScope.ts +39 -0
- package/src/components/resources/pod-file-upload.ts +3 -0
- package/src/components/resources/renderers/CAPIClusterRenderer.tsx +5 -2
- package/src/components/resources/renderers/LonghornVolumeRenderer.test.tsx +104 -0
- package/src/components/resources/renderers/LonghornVolumeRenderer.tsx +31 -0
- package/src/components/rightsizing/RightsizingScanLink.tsx +22 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +65 -528
- package/src/components/rightsizing/model.test.ts +20 -9
- package/src/components/rightsizing/model.ts +17 -176
- package/src/components/rightsizing/notices.test.tsx +30 -29
- package/src/components/ui/DiagnosticsOverlay.test.ts +3 -2
- package/src/components/ui/DiagnosticsOverlay.tsx +23 -13
- package/src/components/ui/command-items.ts +3 -4
- package/src/components/useContextSwitchFlow.test.tsx +9 -0
- package/src/components/useContextSwitchFlow.tsx +43 -5
- package/src/components/workload/WorkloadRightsizingSource.test.tsx +83 -0
- package/src/components/workload/WorkloadView.test.ts +22 -1
- package/src/components/workload/WorkloadView.tsx +57 -16
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +58 -15
- package/src/context/ConnectionProvider.connectionId.test.tsx +92 -0
- package/src/context/ConnectionProvider.retry.test.tsx +174 -1
- package/src/context/ContextSwitchContext.tsx +15 -1
- package/src/context/NavCustomization.tsx +6 -3
- package/src/hooks/useEventSource.test.tsx +85 -0
- package/src/hooks/useEventSource.ts +43 -16
- package/src/hooks/useResetViewsOnContextChange.test.tsx +34 -0
- package/src/hooks/useResetViewsOnContextChange.ts +27 -0
- package/src/index.ts +3 -0
- package/src/integrations/resourceHosts.test.tsx +1 -1
- package/src/integrations/resourceHosts.tsx +2 -0
- package/src/utils/navigation.ts +1 -15
- package/src/utils/page-links.ts +6 -0
- package/src/components/rightsizing/presentation.test.ts +0 -150
- package/src/components/rightsizing/presentation.ts +0 -109
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import type { RightsizingScanResponse, RightsizingRow } from '../../api/client'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
classifyRows,
|
|
6
|
-
flattenScanResults,
|
|
7
|
-
isActionableClass,
|
|
8
|
-
scanClassCounts,
|
|
9
|
-
} from './model'
|
|
3
|
+
import { calculateImpact, classifyRows, matchesResultClass, scanClassCounts } from '@skyhook-io/k8s-ui/components/rightsizing/results-model'
|
|
4
|
+
import { flattenScanResults } from './model'
|
|
10
5
|
|
|
11
6
|
function metric(overrides: Partial<RightsizingRow> = {}): RightsizingRow {
|
|
12
7
|
return {
|
|
@@ -29,7 +24,7 @@ function response(
|
|
|
29
24
|
replicas = 1,
|
|
30
25
|
namespace = 'shop',
|
|
31
26
|
scaledToZero = false,
|
|
32
|
-
): RightsizingScanResponse {
|
|
27
|
+
): RightsizingScanResponse & { workloads: NonNullable<RightsizingScanResponse['workloads']> } {
|
|
33
28
|
return {
|
|
34
29
|
scanId: 'rs_test', scanStatus: 'finished', deadlineAt: '2026-09-19T10:03:00Z',
|
|
35
30
|
state: 'complete',
|
|
@@ -57,6 +52,10 @@ function response(
|
|
|
57
52
|
}
|
|
58
53
|
|
|
59
54
|
describe('rightsizing scan model', () => {
|
|
55
|
+
it('can render a retained unavailable scan from a disconnected spoke', () => {
|
|
56
|
+
expect(flattenScanResults({ ...response([]), state: 'unavailable', workloads: null })).toEqual([])
|
|
57
|
+
})
|
|
58
|
+
|
|
60
59
|
it('prioritizes reliability guidance and explicit safety review', () => {
|
|
61
60
|
expect(
|
|
62
61
|
classifyRows([
|
|
@@ -193,7 +192,7 @@ describe('rightsizing scan model', () => {
|
|
|
193
192
|
expect(rows[0].cpu).toBe(cpu)
|
|
194
193
|
expect(rows[0].memory).toBe(memory)
|
|
195
194
|
expect(scanClassCounts(rows)[rows[0].classification]).toBe(1)
|
|
196
|
-
const actions = rows.filter((row) =>
|
|
195
|
+
const actions = rows.filter((row) => matchesResultClass(row, 'actions'))
|
|
197
196
|
expect(actions).toHaveLength(classification === 'need_data' ? 0 : 1)
|
|
198
197
|
})
|
|
199
198
|
})
|
|
@@ -354,3 +353,15 @@ describe('pod-level requests', () => {
|
|
|
354
353
|
expect(calculateImpact(rows, 2)).toMatchObject({ cpuChange: 0, memoryChange: 0 })
|
|
355
354
|
})
|
|
356
355
|
})
|
|
356
|
+
|
|
357
|
+
it('finds independent actions on one container without counting a guarded proposal as capacity', () => {
|
|
358
|
+
const rows = flattenScanResults(response([
|
|
359
|
+
metric({ fit: 'under_requested', recommendedRequest: '250m', recommendedRequestValue: 0.25,
|
|
360
|
+
currentRequestValue: 0.1, decision: { status: 'review', reasons: ['hpa_evidence_unavailable'] } }),
|
|
361
|
+
metric({ resource: 'memory', fit: 'oversized', recommendedRequest: '128Mi',
|
|
362
|
+
recommendedRequestValue: 128 * 1024 ** 2, currentRequestValue: 256 * 1024 ** 2, decision: { status: 'actionable' } }),
|
|
363
|
+
]));
|
|
364
|
+
expect(scanClassCounts(rows)).toEqual({ increase: 1, review: 1, reduction: 1, in_range: 0, need_data: 0 });
|
|
365
|
+
expect(matchesResultClass(rows[0], 'actions')).toBe(true);
|
|
366
|
+
expect(rows[0].impact.cpuChange).toBe(0);
|
|
367
|
+
});
|
|
@@ -1,183 +1,24 @@
|
|
|
1
|
-
import type { RightsizingScanResponse
|
|
1
|
+
import type { RightsizingScanResponse } from '../../api/client'
|
|
2
|
+
import {
|
|
3
|
+
compareScanResults,
|
|
4
|
+
workloadResultRows,
|
|
5
|
+
type RightsizingResultRow,
|
|
6
|
+
isSizingSystemNamespace,
|
|
7
|
+
} from '@skyhook-io/k8s-ui/components/rightsizing/results-model'
|
|
2
8
|
|
|
3
|
-
export type ScanClass
|
|
9
|
+
export type { ScanClass } from '@skyhook-io/k8s-ui/components/rightsizing/results-model'
|
|
4
10
|
|
|
5
|
-
export interface
|
|
6
|
-
replicas: number
|
|
7
|
-
cpuChange: number
|
|
8
|
-
memoryChange: number
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface RightsizingScanRow {
|
|
12
|
-
id: string
|
|
13
|
-
kind: string
|
|
14
|
-
namespace: string
|
|
15
|
-
name: string
|
|
16
|
-
container: string
|
|
17
|
-
replicas: number
|
|
18
|
-
cpu?: RightsizingRow
|
|
19
|
-
memory?: RightsizingRow
|
|
20
|
-
classification: ScanClass
|
|
21
|
-
impact: RightsizingImpact
|
|
11
|
+
export interface RightsizingScanRow extends RightsizingResultRow {
|
|
22
12
|
system: boolean
|
|
23
|
-
scaledToZero: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const CLASS_RANK: Record<ScanClass, number> = {
|
|
27
|
-
increase: 1,
|
|
28
|
-
reduction: 2,
|
|
29
|
-
review: 3,
|
|
30
|
-
need_data: 4,
|
|
31
|
-
in_range: 5,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const MIN_CPU_REDUCTION = 0.05
|
|
35
|
-
const MIN_MEMORY_REDUCTION = 64 * 1024 * 1024
|
|
36
|
-
|
|
37
|
-
export function classifyRows(
|
|
38
|
-
rows: RightsizingRow[],
|
|
39
|
-
replicas = 1,
|
|
40
|
-
scaledToZero = false,
|
|
41
|
-
): ScanClass {
|
|
42
|
-
const evidenced = rows.filter((row) => !row.queryError && row.fit !== 'insufficient_history')
|
|
43
|
-
if (evidenced.length === 0) return 'need_data'
|
|
44
|
-
if (scaledToZero) return 'review'
|
|
45
|
-
if (
|
|
46
|
-
evidenced.some(
|
|
47
|
-
(row) =>
|
|
48
|
-
(row.fit === 'under_requested' || row.fit === 'missing_request') && row.recommendedRequest,
|
|
49
|
-
)
|
|
50
|
-
)
|
|
51
|
-
return 'increase'
|
|
52
|
-
if (evidenced.some(needsManualReview)) return 'review'
|
|
53
|
-
const impact = calculateImpact(evidenced, replicas)
|
|
54
|
-
if (-impact.cpuChange >= MIN_CPU_REDUCTION || -impact.memoryChange >= MIN_MEMORY_REDUCTION)
|
|
55
|
-
return 'reduction'
|
|
56
|
-
return evidenced.length === rows.length ? 'in_range' : 'need_data'
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function needsManualReview(row: RightsizingRow): boolean {
|
|
60
|
-
return (
|
|
61
|
-
row.hpaManaged ||
|
|
62
|
-
needsSafetyReview(row) ||
|
|
63
|
-
(isReduction(row) && row.bursty === true) ||
|
|
64
|
-
row.recommendationReason === 'hpa_evidence_unavailable' ||
|
|
65
|
-
row.recommendationReason === 'oom_evidence_unavailable' ||
|
|
66
|
-
// Mirrors ManualReviewReasons: Radar does not size a pod-level request.
|
|
67
|
-
row.fit === 'pod_level_request'
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function needsSafetyReview(row: RightsizingRow): boolean {
|
|
72
|
-
return (
|
|
73
|
-
row.currentPodOOM === true ||
|
|
74
|
-
row.windowOomEvidence === true ||
|
|
75
|
-
row.limitConflict === true ||
|
|
76
|
-
(isReduction(row) && (row.throttleRatio ?? 0) >= 0.1)
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function scanPriority(row: RightsizingScanRow): number {
|
|
81
|
-
if (
|
|
82
|
-
!row.scaledToZero &&
|
|
83
|
-
[row.cpu, row.memory].some(
|
|
84
|
-
(resource) =>
|
|
85
|
-
resource &&
|
|
86
|
-
!resource.queryError &&
|
|
87
|
-
resource.fit !== 'insufficient_history' &&
|
|
88
|
-
needsSafetyReview(resource),
|
|
89
|
-
)
|
|
90
|
-
)
|
|
91
|
-
return 0
|
|
92
|
-
return CLASS_RANK[row.classification]
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function isReduction(row: RightsizingRow): boolean {
|
|
96
|
-
return (
|
|
97
|
-
row.recommendedRequestValue != null &&
|
|
98
|
-
row.currentRequestValue != null &&
|
|
99
|
-
row.recommendedRequestValue < row.currentRequestValue
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function calculateImpact(rows: RightsizingRow[], replicas: number): RightsizingImpact {
|
|
104
|
-
const count = Math.max(replicas, 0)
|
|
105
|
-
let cpuChange = 0
|
|
106
|
-
let memoryChange = 0
|
|
107
|
-
for (const row of rows) {
|
|
108
|
-
if (row.recommendedRequestValue == null || needsManualReview(row)) continue
|
|
109
|
-
const change = (row.recommendedRequestValue - (row.currentRequestValue ?? 0)) * count
|
|
110
|
-
if (row.resource === 'cpu') cpuChange += change
|
|
111
|
-
else memoryChange += change
|
|
112
|
-
}
|
|
113
|
-
return { replicas: count, cpuChange, memoryChange }
|
|
114
13
|
}
|
|
115
14
|
|
|
116
15
|
export function flattenScanResults(scan: RightsizingScanResponse): RightsizingScanRow[] {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
for (const [container, rows] of byContainer) {
|
|
126
|
-
const replicas = workload.replicas ?? 1
|
|
127
|
-
result.push({
|
|
128
|
-
id: `${workload.kind}/${workload.namespace}/${workload.name}/${container}`,
|
|
129
|
-
kind: workload.kind,
|
|
130
|
-
namespace: workload.namespace,
|
|
131
|
-
name: workload.name,
|
|
132
|
-
container,
|
|
133
|
-
replicas,
|
|
134
|
-
cpu: rows.find((row) => row.resource === 'cpu'),
|
|
135
|
-
memory: rows.find((row) => row.resource === 'memory'),
|
|
136
|
-
classification: classifyRows(rows, replicas, workload.scaledToZero),
|
|
137
|
-
impact: calculateImpact(rows, replicas),
|
|
138
|
-
system: isSystemNamespace(workload.namespace),
|
|
139
|
-
scaledToZero: workload.scaledToZero,
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return result.sort(
|
|
144
|
-
(a, b) =>
|
|
145
|
-
scanPriority(a) - scanPriority(b) ||
|
|
146
|
-
impactScore(b) - impactScore(a) ||
|
|
147
|
-
a.namespace.localeCompare(b.namespace) ||
|
|
148
|
-
a.name.localeCompare(b.name) ||
|
|
149
|
-
a.container.localeCompare(b.container),
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function impactScore(row: RightsizingScanRow): number {
|
|
154
|
-
return Math.max(
|
|
155
|
-
Math.abs(row.impact.cpuChange) / MIN_CPU_REDUCTION,
|
|
156
|
-
Math.abs(row.impact.memoryChange) / MIN_MEMORY_REDUCTION,
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function scanClassCounts(rows: RightsizingScanRow[]): Record<ScanClass, number> {
|
|
161
|
-
const counts: Record<ScanClass, number> = {
|
|
162
|
-
increase: 0,
|
|
163
|
-
reduction: 0,
|
|
164
|
-
review: 0,
|
|
165
|
-
in_range: 0,
|
|
166
|
-
need_data: 0,
|
|
167
|
-
}
|
|
168
|
-
for (const row of rows) counts[row.classification]++
|
|
169
|
-
return counts
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function isActionableClass(value: ScanClass): boolean {
|
|
173
|
-
return value === 'increase' || value === 'reduction' || value === 'review'
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function isSystemNamespace(namespace: string): boolean {
|
|
177
|
-
return (
|
|
178
|
-
namespace === 'kube-system' ||
|
|
179
|
-
namespace === 'kube-public' ||
|
|
180
|
-
namespace === 'kube-node-lease' ||
|
|
181
|
-
namespace.startsWith('gke-managed-')
|
|
182
|
-
)
|
|
16
|
+
return (scan.workloads ?? [])
|
|
17
|
+
.flatMap((workload) =>
|
|
18
|
+
workloadResultRows(workload).map((row) => ({
|
|
19
|
+
...row,
|
|
20
|
+
system: isSizingSystemNamespace(row.namespace),
|
|
21
|
+
})),
|
|
22
|
+
)
|
|
23
|
+
.sort(compareScanResults)
|
|
183
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
3
|
+
import type { RightsizingScanResponse } from '../../api/client'
|
|
4
|
+
import { ScanNotices, ScanSummary, ScanUnavailableState } from './RightsizingScanView'
|
|
5
5
|
|
|
6
6
|
const scan: RightsizingScanResponse = {
|
|
7
7
|
scanId: 'rs_test', scanStatus: 'finished', deadlineAt: '2026-09-19T10:03:00Z',
|
|
@@ -105,33 +105,6 @@ describe('rightsizing scan notices', () => {
|
|
|
105
105
|
})
|
|
106
106
|
})
|
|
107
107
|
|
|
108
|
-
describe('rightsizing evidence explanation', () => {
|
|
109
|
-
const row: RightsizingRow = {
|
|
110
|
-
container: 'app',
|
|
111
|
-
resource: 'cpu',
|
|
112
|
-
fit: 'insufficient_history',
|
|
113
|
-
confidence: 'low',
|
|
114
|
-
coverage: 0,
|
|
115
|
-
sampleCount: 0,
|
|
116
|
-
expectedSamples: 2017,
|
|
117
|
-
hpaManaged: false,
|
|
118
|
-
hpaEvidenceAvailable: true,
|
|
119
|
-
oomEvidenceAvailable: false,
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
it('distinguishes failed queries from successfully measured short history', () => {
|
|
123
|
-
const failed = renderToStaticMarkup(
|
|
124
|
-
<FitWhy label="CPU" row={{ ...row, queryError: 'usage query failed' }} />,
|
|
125
|
-
)
|
|
126
|
-
expect(failed).toContain('Metrics could not be queried')
|
|
127
|
-
expect(failed).not.toContain('0.0 days')
|
|
128
|
-
expect(failed).not.toContain('Wait for more runtime history')
|
|
129
|
-
const short = renderToStaticMarkup(<FitWhy label="CPU" row={row} />)
|
|
130
|
-
expect(short).toContain('0.0 days')
|
|
131
|
-
expect(short).toContain('Wait for more runtime history')
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
|
|
135
108
|
describe('rightsizing scope and coverage summary', () => {
|
|
136
109
|
const counts = {
|
|
137
110
|
increase: 1,
|
|
@@ -174,3 +147,31 @@ describe('rightsizing scope and coverage summary', () => {
|
|
|
174
147
|
expect(html).toContain('All visible namespaces')
|
|
175
148
|
})
|
|
176
149
|
})
|
|
150
|
+
|
|
151
|
+
describe('rightsizing scan withheld cluster scope', () => {
|
|
152
|
+
it('shows the note once instead of the unavailable message', () => {
|
|
153
|
+
const html = renderToStaticMarkup(
|
|
154
|
+
<ScanUnavailableState
|
|
155
|
+
result={{
|
|
156
|
+
...scan,
|
|
157
|
+
state: 'unavailable',
|
|
158
|
+
reason: 'cluster_scope_withheld',
|
|
159
|
+
warnings: [{ code: 'cluster_scope_withheld', message: 'This metrics store holds several clusters.' }],
|
|
160
|
+
clusterScope: { state: 'label_missing', note: "The container_cpu_usage_seconds_total series don't carry this cluster's label." },
|
|
161
|
+
}}
|
|
162
|
+
onRun={() => {}}
|
|
163
|
+
/>,
|
|
164
|
+
)
|
|
165
|
+
expect(html.match(/role="note"/g)).toHaveLength(1)
|
|
166
|
+
expect(html).toContain("don't carry this cluster's label")
|
|
167
|
+
expect(html).not.toContain('Rightsizing is unavailable')
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('keeps the unavailable message for other reasons and older Radar', () => {
|
|
171
|
+
const html = renderToStaticMarkup(
|
|
172
|
+
<ScanUnavailableState result={{ ...scan, state: 'unavailable', reason: 'owner_metrics_missing' }} onRun={() => {}} />,
|
|
173
|
+
)
|
|
174
|
+
expect(html).toContain('Rightsizing is unavailable')
|
|
175
|
+
expect(html).not.toContain('role="note"')
|
|
176
|
+
})
|
|
177
|
+
})
|
|
@@ -117,9 +117,10 @@ describe('formatForGitHub kubeconfig section', () => {
|
|
|
117
117
|
|
|
118
118
|
expect(md).toContain('Mode: `multi-source` | Files: 3 | Directory Files: 2 | Contexts (after source resolution): 7')
|
|
119
119
|
expect(md).toContain('KUBECONFIG Captured From Shell: Yes | Ignored: Yes — directories-only configuration')
|
|
120
|
+
expect(md).toContain('Current Context Uses Exec: No')
|
|
120
121
|
})
|
|
121
122
|
|
|
122
|
-
it('omits directory counts
|
|
123
|
+
it('omits directory counts and unobserved current-context auth', () => {
|
|
123
124
|
const md = formatForGitHub({
|
|
124
125
|
...baseSnapshot,
|
|
125
126
|
kubeconfig: {
|
|
@@ -130,11 +131,11 @@ describe('formatForGitHub kubeconfig section', () => {
|
|
|
130
131
|
enrichedFromShell: false,
|
|
131
132
|
kubeconfigEnvIgnored: false,
|
|
132
133
|
kubeconfigEnvIgnoredReason: '',
|
|
133
|
-
currentContextUsesExec: true,
|
|
134
134
|
},
|
|
135
135
|
}, undefined, false)
|
|
136
136
|
|
|
137
137
|
expect(md).toContain('Mode: `multi-env` | Files: 2 | Contexts (after source resolution): 4')
|
|
138
138
|
expect(md).not.toContain('Directory Files:')
|
|
139
|
+
expect(md).not.toContain('Current Context Uses Exec:')
|
|
139
140
|
})
|
|
140
141
|
})
|
|
@@ -19,7 +19,7 @@ interface DiagnosticsOverlayProps {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function DiagnosticsOverlay({ onClose, isOpen = true, focus, communityUrl }: DiagnosticsOverlayProps) {
|
|
22
|
-
const { data, isLoading, error } = useDiagnostics(true)
|
|
22
|
+
const { data, isLoading, isFetching, error, refetch } = useDiagnostics(true)
|
|
23
23
|
const [copied, setCopied] = useState<'json' | 'formatted' | null>(null)
|
|
24
24
|
const [reportOpened, setReportOpened] = useState(false)
|
|
25
25
|
const timelineRef = useRef<HTMLDivElement>(null)
|
|
@@ -124,7 +124,11 @@ export function DiagnosticsOverlay({ onClose, isOpen = true, focus, communityUrl
|
|
|
124
124
|
<div className="text-sm text-theme-text-tertiary text-center py-8">Loading diagnostics…</div>
|
|
125
125
|
)}
|
|
126
126
|
{error && (
|
|
127
|
-
<div className="text-sm text-
|
|
127
|
+
<div role="alert" className="text-sm text-center py-8 space-y-3">
|
|
128
|
+
<p className="text-theme-text-primary">{error.message}</p>
|
|
129
|
+
{data && <p className="text-theme-text-secondary">Showing the snapshot from {new Date(data.timestamp).toLocaleTimeString()}.</p>}
|
|
130
|
+
<button type="button" className="btn-brand px-3 py-1.5 text-sm font-medium" disabled={isFetching} onClick={() => void refetch()}>{isFetching ? 'Retrying…' : 'Retry diagnostics'}</button>
|
|
131
|
+
</div>
|
|
128
132
|
)}
|
|
129
133
|
{data && (
|
|
130
134
|
<>
|
|
@@ -156,8 +160,8 @@ export function DiagnosticsOverlay({ onClose, isOpen = true, focus, communityUrl
|
|
|
156
160
|
|
|
157
161
|
{/* Footer */}
|
|
158
162
|
<div className="flex items-center gap-2 px-5 py-3 border-t border-theme-border shrink-0">
|
|
159
|
-
<CopyButton label="Copy as Markdown" onClick={() => copyToClipboard('formatted')} copied={copied === 'formatted'} />
|
|
160
|
-
<CopyButton label="Copy Raw JSON" onClick={() => copyToClipboard('json')} copied={copied === 'json'} />
|
|
163
|
+
<CopyButton disabled={!data} label="Copy as Markdown" onClick={() => copyToClipboard('formatted')} copied={copied === 'formatted'} />
|
|
164
|
+
<CopyButton disabled={!data} label="Copy Raw JSON" onClick={() => copyToClipboard('json')} copied={copied === 'json'} />
|
|
161
165
|
<div className="flex-1" />
|
|
162
166
|
{communityUrl && (
|
|
163
167
|
<a
|
|
@@ -236,6 +240,7 @@ function ConnectionSection({ data }: { data: DiagnosticsSnapshot }) {
|
|
|
236
240
|
<Row label="State" value={c.state} warn={warn} />
|
|
237
241
|
<Row label="Context" value={c.context} />
|
|
238
242
|
{c.clusterName && <Row label="Cluster" value={c.clusterName} />}
|
|
243
|
+
{c.progressMessage && <Row label="Progress" value={c.progressMessage} />}
|
|
239
244
|
{c.error && <Row label="Error" value={c.error} warn />}
|
|
240
245
|
{c.errorType && <Row label="Error Type" value={c.errorType} warn />}
|
|
241
246
|
</Section>
|
|
@@ -266,10 +271,9 @@ function KubeconfigSection({ data }: { data: DiagnosticsSnapshot }) {
|
|
|
266
271
|
value={k.kubeconfigEnvIgnored ? `Yes — ${k.kubeconfigEnvIgnoredReason}` : 'No'}
|
|
267
272
|
warn={k.kubeconfigEnvIgnored}
|
|
268
273
|
/>
|
|
269
|
-
|
|
270
|
-
label="Current Context Uses Exec"
|
|
271
|
-
|
|
272
|
-
/>
|
|
274
|
+
{k.currentContextUsesExec !== undefined && (
|
|
275
|
+
<Row label="Current Context Uses Exec" value={k.currentContextUsesExec ? 'Yes' : 'No'} />
|
|
276
|
+
)}
|
|
273
277
|
{present.length > 0 && (
|
|
274
278
|
<Row label="Exec Plugins on PATH" value={present.join(', ')} />
|
|
275
279
|
)}
|
|
@@ -289,6 +293,7 @@ function ClusterSection({ data }: { data: DiagnosticsSnapshot }) {
|
|
|
289
293
|
const c = data.cluster
|
|
290
294
|
return (
|
|
291
295
|
<Section title="Cluster">
|
|
296
|
+
{c.observedAt && <Row label="Last observed" value={new Date(c.observedAt).toLocaleString()} />}
|
|
292
297
|
<Row label="Platform" value={c.platform} />
|
|
293
298
|
<Row label="Kubernetes" value={c.kubernetesVersion} />
|
|
294
299
|
<Row label="Nodes" value={c.nodeCount} />
|
|
@@ -385,7 +390,7 @@ function InformersSection({ data }: { data: DiagnosticsSnapshot }) {
|
|
|
385
390
|
return (
|
|
386
391
|
<Section title="Informers" warn={sectionWarn}>
|
|
387
392
|
<Row label="Typed" value={inf.typedCount} />
|
|
388
|
-
<Row label="Dynamic (CRDs)" value={inf.dynamicCount} />
|
|
393
|
+
<Row label="Dynamic (CRDs)" value={inf.dynamicCount ?? 'Unavailable'} />
|
|
389
394
|
{sync && (
|
|
390
395
|
<>
|
|
391
396
|
<Row
|
|
@@ -648,12 +653,13 @@ function ConfigSection({ data }: { data: DiagnosticsSnapshot }) {
|
|
|
648
653
|
|
|
649
654
|
// --- Copy button ---
|
|
650
655
|
|
|
651
|
-
function CopyButton({ label, onClick, copied }: { label: string; onClick: () => void; copied: boolean }) {
|
|
656
|
+
function CopyButton({ label, onClick, copied, disabled }: { label: string; onClick: () => void; copied: boolean; disabled: boolean }) {
|
|
652
657
|
return (
|
|
653
658
|
<button
|
|
659
|
+
disabled={disabled}
|
|
654
660
|
onClick={onClick}
|
|
655
661
|
className={clsx(
|
|
656
|
-
'flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-md transition-colors',
|
|
662
|
+
'flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-md transition-colors disabled:opacity-50',
|
|
657
663
|
copied
|
|
658
664
|
? 'bg-green-500/20 text-green-400'
|
|
659
665
|
: 'bg-theme-elevated text-theme-text-secondary hover:text-theme-text-primary hover:bg-theme-elevated/80'
|
|
@@ -679,6 +685,7 @@ export function formatForGitHub(data: DiagnosticsSnapshot, frontendPerf?: K8sUIP
|
|
|
679
685
|
lines.push(`### Connection`)
|
|
680
686
|
lines.push(`- State: \`${c.state}\``)
|
|
681
687
|
lines.push(`- Context: \`${c.context}\``)
|
|
688
|
+
if (c.progressMessage) lines.push(`- Progress: ${c.progressMessage}`)
|
|
682
689
|
if (c.clusterName) lines.push(`- Cluster: \`${c.clusterName}\``)
|
|
683
690
|
if (c.error) lines.push(`- Error: ${c.error}`)
|
|
684
691
|
if (c.errorType) lines.push(`- Error Type: \`${c.errorType}\``)
|
|
@@ -693,7 +700,9 @@ export function formatForGitHub(data: DiagnosticsSnapshot, frontendPerf?: K8sUIP
|
|
|
693
700
|
: ''
|
|
694
701
|
lines.push(`- Mode: \`${k.mode || '(not initialized)'}\` | Files: ${k.fileCount}${directoryFiles} | Contexts (after source resolution): ${k.contextCount}`)
|
|
695
702
|
lines.push(`- KUBECONFIG Captured From Shell: ${k.enrichedFromShell ? 'Yes' : 'No'} | Ignored: ${k.kubeconfigEnvIgnored ? `Yes — ${k.kubeconfigEnvIgnoredReason}` : 'No'}`)
|
|
696
|
-
|
|
703
|
+
if (k.currentContextUsesExec !== undefined) {
|
|
704
|
+
lines.push(`- Current Context Uses Exec: ${k.currentContextUsesExec ? 'Yes' : 'No'}`)
|
|
705
|
+
}
|
|
697
706
|
if (k.execPluginsPresent && k.execPluginsPresent.length > 0) {
|
|
698
707
|
lines.push(`- Exec Plugins on PATH: \`${k.execPluginsPresent.join('`, `')}\``)
|
|
699
708
|
}
|
|
@@ -706,6 +715,7 @@ export function formatForGitHub(data: DiagnosticsSnapshot, frontendPerf?: K8sUIP
|
|
|
706
715
|
if (data.cluster) {
|
|
707
716
|
const c = data.cluster
|
|
708
717
|
lines.push(`### Cluster`)
|
|
718
|
+
if (c.observedAt) lines.push(`- Last observed: ${c.observedAt}`)
|
|
709
719
|
lines.push(`- Platform: \`${c.platform}\` | K8s: \`${c.kubernetesVersion}\` | Nodes: ${c.nodeCount} | Namespaces: ${c.namespaceCount}${c.inCluster ? ' | In-Cluster' : ''}`)
|
|
710
720
|
lines.push(``)
|
|
711
721
|
}
|
|
@@ -754,7 +764,7 @@ export function formatForGitHub(data: DiagnosticsSnapshot, frontendPerf?: K8sUIP
|
|
|
754
764
|
if (data.informers) {
|
|
755
765
|
const inf = data.informers
|
|
756
766
|
lines.push(`### Informers`)
|
|
757
|
-
lines.push(`- Typed: ${inf.typedCount} | Dynamic: ${inf.dynamicCount}`)
|
|
767
|
+
lines.push(`- Typed: ${inf.typedCount} | Dynamic: ${inf.dynamicCount ?? 'unavailable'}`)
|
|
758
768
|
if (inf.syncStatus) {
|
|
759
769
|
const sync = inf.syncStatus
|
|
760
770
|
lines.push(`- Sync Phase: \`${sync.phase}\` (${formatElapsed(sync.elapsedSec)})`)
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
Megaphone,
|
|
20
20
|
} from "lucide-react";
|
|
21
21
|
import { SlackIcon } from "../community";
|
|
22
|
+
import type { ContextInfo } from "../../types";
|
|
22
23
|
import { useNamespaces, useContexts } from "../../api/client";
|
|
23
24
|
import { CORE_RESOURCES, useAPIResources } from "../../api/apiResources";
|
|
24
25
|
import { getResourceIcon } from "../../utils/resource-icons";
|
|
@@ -126,7 +127,7 @@ export function bestScore(item: CommandItem, query: string): number {
|
|
|
126
127
|
export interface CommandItemCallbacks {
|
|
127
128
|
onNavigateView: (view: MainView) => void;
|
|
128
129
|
onNavigateKind: (kind: string, group: string) => void;
|
|
129
|
-
onSwitchContext: (
|
|
130
|
+
onSwitchContext: (context: ContextInfo) => void;
|
|
130
131
|
onSetNamespaces: (ns: string[]) => void;
|
|
131
132
|
onToggleTheme: () => void;
|
|
132
133
|
onShowDiagnostics?: () => void;
|
|
@@ -238,9 +239,7 @@ export function useCommandItems(cb: CommandItemCallbacks): CommandItem[] {
|
|
|
238
239
|
sublabel: sub || undefined,
|
|
239
240
|
category: "Clusters",
|
|
240
241
|
icon: Server,
|
|
241
|
-
action: () =>
|
|
242
|
-
if (!ctx.isCurrent) cb.onSwitchContext(ctx.name);
|
|
243
|
-
},
|
|
242
|
+
action: () => cb.onSwitchContext(ctx),
|
|
244
243
|
searchTerms: [ctx.name, account || ""].filter(Boolean),
|
|
245
244
|
});
|
|
246
245
|
}
|
|
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
5
5
|
import type { ContextInfo } from '../types'
|
|
6
6
|
|
|
7
7
|
const mocks = vi.hoisted(() => ({
|
|
8
|
+
connection: { errorType: undefined as string | undefined },
|
|
8
9
|
mutateAsync: vi.fn(),
|
|
9
10
|
setFailedSwitch: vi.fn(),
|
|
10
11
|
startSwitch: vi.fn(),
|
|
@@ -14,6 +15,7 @@ vi.mock('../api/client', () => ({
|
|
|
14
15
|
fetchSessionCounts: async () => ({ portForwards: 0 }),
|
|
15
16
|
SwitchContextError: class extends Error {},
|
|
16
17
|
}))
|
|
18
|
+
vi.mock('../context/ConnectionContext', () => ({ useConnection: () => ({ connection: mocks.connection }) }))
|
|
17
19
|
vi.mock('../context/ContextSwitchContext', () => ({
|
|
18
20
|
useContextSwitch: () => ({
|
|
19
21
|
startSwitch: mocks.startSwitch,
|
|
@@ -39,6 +41,7 @@ function Probe() {
|
|
|
39
41
|
|
|
40
42
|
beforeEach(() => {
|
|
41
43
|
vi.clearAllMocks()
|
|
44
|
+
mocks.connection.errorType = undefined
|
|
42
45
|
root = createRoot(document.createElement('div'))
|
|
43
46
|
act(() => root.render(<Probe />))
|
|
44
47
|
})
|
|
@@ -54,6 +57,12 @@ describe('useContextSwitchFlow', () => {
|
|
|
54
57
|
expect(mocks.mutateAsync).not.toHaveBeenCalled()
|
|
55
58
|
})
|
|
56
59
|
|
|
60
|
+
it('selecting the stopped target starts a fresh tracked switch', async () => {
|
|
61
|
+
mocks.connection.errorType = 'switch-stopped'
|
|
62
|
+
await act(() => flow().requestSwitch(ctx('current', true)))
|
|
63
|
+
expect(mocks.mutateAsync).toHaveBeenCalledWith({ name: 'current' })
|
|
64
|
+
})
|
|
65
|
+
|
|
57
66
|
it('picking another cluster still switches', async () => {
|
|
58
67
|
await act(() => flow().requestSwitch(ctx('staging', false)))
|
|
59
68
|
expect(mocks.mutateAsync).toHaveBeenCalledWith({ name: 'staging' })
|
|
@@ -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
|
+
}
|