@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.
- 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 +7 -0
- package/src/api/sealedSecrets.test.ts +22 -0
- package/src/api/sealedSecrets.ts +37 -0
- package/src/api/vulnerabilities.ts +80 -7
- 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/audit/Java4ShellPanel.test.tsx +104 -7
- package/src/components/audit/Java4ShellPanel.tsx +169 -72
- 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/resources/renderers/SealedSecretRenderer.test.tsx +41 -0
- package/src/components/resources/renderers/SealedSecretRenderer.tsx +14 -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/traffic/TrafficFlowList.tsx +8 -4
- package/src/components/traffic/TrafficGraph.test.tsx +31 -1
- package/src/components/traffic/TrafficGraph.tsx +11 -6
- package/src/components/traffic/trafficFilters.ts +4 -4
- 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/vulnerabilities/WorkloadVulnerabilitiesSection.test.tsx +54 -0
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +50 -109
- package/src/components/whats-new/releaseNotes.ts +1 -1
- 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 +2 -2
- package/src/integrations/resourceHosts.tsx +4 -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,5 +1,7 @@
|
|
|
1
1
|
import { TerminalTab as SharedTerminalTab } from '@skyhook-io/k8s-ui'
|
|
2
2
|
import { apiUrl, getWsUrl } from '../../api/config'
|
|
3
|
+
import { apiFetch } from '../../api/client'
|
|
4
|
+
import { connectionHeaders, useOpenedConnection, withConnectionParam } from '../../api/connectionBinding'
|
|
3
5
|
import { readErrorBody } from '../../api/httpErrors'
|
|
4
6
|
|
|
5
7
|
interface TerminalTabProps {
|
|
@@ -13,15 +15,16 @@ interface TerminalTabProps {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export function TerminalTab({ namespace, podName, containerName, containers, isActive, shell, note }: TerminalTabProps) {
|
|
18
|
+
const connection = useOpenedConnection()
|
|
16
19
|
const createSession = (container: string) =>
|
|
17
20
|
Promise.resolve({
|
|
18
|
-
wsUrl: getWsUrl(`/pods/${namespace}/${podName}/exec?container=${container}${shell ? `&shell=${encodeURIComponent(shell)}` : ''}`),
|
|
21
|
+
wsUrl: withConnectionParam(getWsUrl(`/pods/${namespace}/${podName}/exec?container=${container}${shell ? `&shell=${encodeURIComponent(shell)}` : ''}`), connection),
|
|
19
22
|
})
|
|
20
23
|
|
|
21
24
|
const createDebugContainer = async (targetContainer: string) => {
|
|
22
|
-
const response = await
|
|
25
|
+
const response = await apiFetch(apiUrl(`/pods/${namespace}/${podName}/debug`), {
|
|
23
26
|
method: 'POST',
|
|
24
|
-
headers: { 'Content-Type': 'application/json' },
|
|
27
|
+
headers: { 'Content-Type': 'application/json', ...connectionHeaders(connection) },
|
|
25
28
|
body: JSON.stringify({ targetContainer }),
|
|
26
29
|
})
|
|
27
30
|
if (!response.ok) {
|
|
@@ -98,3 +98,52 @@ describe('CostCard namespace scope', () => {
|
|
|
98
98
|
.map((url) => url.searchParams.get('namespaces'))).toEqual(['team-a', null])
|
|
99
99
|
})
|
|
100
100
|
})
|
|
101
|
+
|
|
102
|
+
describe('CostCard unavailable answers', () => {
|
|
103
|
+
async function renderWithSummary(summary: unknown) {
|
|
104
|
+
vi.stubGlobal('fetch', vi.fn((input: RequestInfo | URL) => {
|
|
105
|
+
const url = new URL(String(input), 'http://radar.invalid')
|
|
106
|
+
if (url.pathname === '/api/opencost/summary') {
|
|
107
|
+
return Promise.resolve(new Response(JSON.stringify(summary), { status: 200, headers: { 'Content-Type': 'application/json' } }))
|
|
108
|
+
}
|
|
109
|
+
return new Promise<Response>(() => {})
|
|
110
|
+
}))
|
|
111
|
+
const container = document.createElement('div')
|
|
112
|
+
const localRoot = createRoot(container)
|
|
113
|
+
await act(async () => {
|
|
114
|
+
localRoot.render(
|
|
115
|
+
<QueryClientProvider client={client}>
|
|
116
|
+
<CostCard />
|
|
117
|
+
</QueryClientProvider>,
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
await act(async () => {
|
|
121
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
122
|
+
})
|
|
123
|
+
return { container, unmount: () => act(async () => localRoot.unmount()) }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
it('shows why costs were withheld in a shared metrics store', async () => {
|
|
127
|
+
const { container, unmount } = await renderWithSummary({
|
|
128
|
+
available: false,
|
|
129
|
+
reason: 'cluster_scope',
|
|
130
|
+
currency: 'USD',
|
|
131
|
+
clusterScope: { state: 'several_clusters', note: 'This metrics store holds several clusters.' },
|
|
132
|
+
})
|
|
133
|
+
const note = container.querySelector('[role="note"]')
|
|
134
|
+
expect(note?.getAttribute('data-cluster-scope')).toBe('several_clusters')
|
|
135
|
+
expect(container.textContent).toContain('Costs withheld for this cluster')
|
|
136
|
+
expect(container.textContent).toContain('This metrics store holds several clusters.')
|
|
137
|
+
await unmount()
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it.each([
|
|
141
|
+
{ label: 'no metrics', summary: { available: false, reason: 'no_metrics', currency: 'USD' } },
|
|
142
|
+
{ label: 'partial answer', summary: { available: false, reason: 'partial_data', currency: 'USD', clusterScope: { state: 'scoped_verified', note: 'ok' } } },
|
|
143
|
+
{ label: 'older Radar without a scope', summary: { available: false, reason: 'cluster_scope', currency: 'USD' } },
|
|
144
|
+
])('still hides for $label', async ({ summary }) => {
|
|
145
|
+
const { container, unmount } = await renderWithSummary(summary)
|
|
146
|
+
expect(container.innerHTML).toBe('')
|
|
147
|
+
await unmount()
|
|
148
|
+
})
|
|
149
|
+
})
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { OpenCostSummary } from '../../api/client'
|
|
2
2
|
import { useOpenCostSummary } from '../../api/client'
|
|
3
3
|
import { Coins } from 'lucide-react'
|
|
4
|
+
import { ClusterScopeNote } from '@skyhook-io/k8s-ui/components/ui/ClusterScopeNote'
|
|
5
|
+
import type { ClusterScope } from '@skyhook-io/k8s-ui/types/cluster-scope'
|
|
4
6
|
import {
|
|
5
7
|
DEFAULT_COST_CURRENCY,
|
|
6
8
|
formatCostPerHour,
|
|
@@ -8,12 +10,17 @@ import {
|
|
|
8
10
|
formatProjectedMonthlyCost,
|
|
9
11
|
formatProjectedMonthlyRate,
|
|
10
12
|
} from '../cost/format'
|
|
11
|
-
import { costFreshnessLabel } from '../cost/source'
|
|
13
|
+
import { costFreshnessLabel, costWithheldScope } from '../cost/source'
|
|
12
14
|
|
|
13
15
|
export function CostCard({ namespaces, onNavigate }: { namespaces?: string[]; onNavigate?: () => void }) {
|
|
14
16
|
const { data } = useOpenCostSummary(true, namespaces)
|
|
15
17
|
|
|
16
|
-
//
|
|
18
|
+
// Costs withheld in a shared metrics store say why; any other unavailable
|
|
19
|
+
// answer shows no placeholder card.
|
|
20
|
+
const withheld = costWithheldScope(data)
|
|
21
|
+
if (withheld) {
|
|
22
|
+
return <CostCardWithheld scope={withheld} onNavigate={onNavigate} />
|
|
23
|
+
}
|
|
17
24
|
if (!data || !data.available) {
|
|
18
25
|
return null
|
|
19
26
|
}
|
|
@@ -21,6 +28,43 @@ export function CostCard({ namespaces, onNavigate }: { namespaces?: string[]; on
|
|
|
21
28
|
return <CostCardContent data={data} onNavigate={onNavigate} />
|
|
22
29
|
}
|
|
23
30
|
|
|
31
|
+
function CostCardShell({ onNavigate, children }: { onNavigate?: () => void; children: React.ReactNode }) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
onClick={onNavigate}
|
|
35
|
+
className={`h-[260px] rounded-xl bg-theme-surface shadow-theme-sm text-left animate-fade-in-up ${onNavigate ? 'cursor-pointer hover:-translate-y-1 hover:shadow-theme-md transition-all duration-200' : ''}`}
|
|
36
|
+
>
|
|
37
|
+
<div className="flex flex-col h-full w-full">{children}</div>
|
|
38
|
+
</div>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function CostCardHeader({ children }: { children?: React.ReactNode }) {
|
|
43
|
+
return (
|
|
44
|
+
<div className="flex items-center justify-between px-5 py-3 border-b border-theme-border/50">
|
|
45
|
+
<div className="flex items-center gap-2">
|
|
46
|
+
<Coins className="w-4 h-4 text-accent-text" />
|
|
47
|
+
<span className="text-xs font-semibold uppercase tracking-wider text-accent-text">Cost Insights</span>
|
|
48
|
+
{children}
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function CostCardWithheld({ scope, onNavigate }: { scope: ClusterScope; onNavigate?: () => void }) {
|
|
55
|
+
return (
|
|
56
|
+
<CostCardShell onNavigate={onNavigate}>
|
|
57
|
+
<CostCardHeader />
|
|
58
|
+
<div className="flex-1 min-h-0 px-4 py-3">
|
|
59
|
+
<ClusterScopeNote scope={scope} title="Costs withheld for this cluster" />
|
|
60
|
+
</div>
|
|
61
|
+
<div className="px-4 py-1.5 border-t border-theme-border/50 flex items-center justify-end">
|
|
62
|
+
<span className="text-[10px] font-semibold uppercase tracking-wider text-accent-text">OpenCost</span>
|
|
63
|
+
</div>
|
|
64
|
+
</CostCardShell>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
24
68
|
function CostCardContent({ data, onNavigate }: { data: OpenCostSummary; onNavigate?: () => void }) {
|
|
25
69
|
const hourlyCost = data.totalHourlyCost ?? 0
|
|
26
70
|
const currency = data.currency ?? DEFAULT_COST_CURRENCY
|
|
@@ -31,73 +75,64 @@ function CostCardContent({ data, onNavigate }: { data: OpenCostSummary; onNaviga
|
|
|
31
75
|
const maxCost = topNamespaces.length > 0 ? topNamespaces[0].hourlyCost : 0
|
|
32
76
|
|
|
33
77
|
return (
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<span className="text-xs font-semibold uppercase tracking-wider text-accent-text">Cost Insights</span>
|
|
43
|
-
{namespaces.length > 0 && (
|
|
44
|
-
<span className="badge-sm border border-theme-border bg-accent-muted text-accent-text">
|
|
45
|
-
{namespaces.length} ns
|
|
46
|
-
</span>
|
|
47
|
-
)}
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
78
|
+
<CostCardShell onNavigate={onNavigate}>
|
|
79
|
+
<CostCardHeader>
|
|
80
|
+
{namespaces.length > 0 && (
|
|
81
|
+
<span className="badge-sm border border-theme-border bg-accent-muted text-accent-text">
|
|
82
|
+
{namespaces.length} ns
|
|
83
|
+
</span>
|
|
84
|
+
)}
|
|
85
|
+
</CostCardHeader>
|
|
50
86
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
</div>
|
|
60
|
-
<div className="flex items-baseline gap-1.5 text-theme-text-secondary">
|
|
61
|
-
<span className="text-xs font-medium tabular-nums">{formatProjectedDailyRate(hourlyCost, currency)}</span>
|
|
62
|
-
<span className="text-[10px] text-theme-text-quaternary">·</span>
|
|
63
|
-
<span className="text-xs font-medium tabular-nums">{formatCostPerHour(hourlyCost, currency)}</span>
|
|
64
|
-
</div>
|
|
87
|
+
<div className="flex-1 min-h-0 flex flex-col px-4 py-3">
|
|
88
|
+
{/* Hero cost numbers */}
|
|
89
|
+
<div className="flex items-baseline gap-3 mb-3">
|
|
90
|
+
<div className="flex items-baseline gap-1">
|
|
91
|
+
<span className="text-2xl font-bold text-theme-text-primary tabular-nums">
|
|
92
|
+
{formatProjectedMonthlyCost(hourlyCost, currency)}
|
|
93
|
+
</span>
|
|
94
|
+
<span className="text-xs text-theme-text-tertiary">/mo</span>
|
|
65
95
|
</div>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
{
|
|
70
|
-
const pct = maxCost > 0 ? (ns.hourlyCost / maxCost) * 100 : 0
|
|
71
|
-
return (
|
|
72
|
-
<div key={ns.name} className="flex items-center gap-2">
|
|
73
|
-
<span className="text-[11px] text-theme-text-secondary truncate w-24 shrink-0">{ns.name}</span>
|
|
74
|
-
<div className="flex-1 h-2 rounded-full overflow-hidden bg-theme-hover">
|
|
75
|
-
<div className="h-full rounded-full bg-indigo-500/60" style={{ width: `${Math.max(pct, 2)}%` }} />
|
|
76
|
-
</div>
|
|
77
|
-
<span className="text-[10px] text-theme-text-tertiary tabular-nums w-20 text-right shrink-0">
|
|
78
|
-
{formatProjectedMonthlyRate(ns.hourlyCost, currency)}
|
|
79
|
-
</span>
|
|
80
|
-
</div>
|
|
81
|
-
)
|
|
82
|
-
})}
|
|
83
|
-
{namespaces.length > 5 && (
|
|
84
|
-
<span className="text-[10px] text-theme-text-tertiary">+{namespaces.length - 5} more namespaces</span>
|
|
85
|
-
)}
|
|
96
|
+
<div className="flex items-baseline gap-1.5 text-theme-text-secondary">
|
|
97
|
+
<span className="text-xs font-medium tabular-nums">{formatProjectedDailyRate(hourlyCost, currency)}</span>
|
|
98
|
+
<span className="text-[10px] text-theme-text-quaternary">·</span>
|
|
99
|
+
<span className="text-xs font-medium tabular-nums">{formatCostPerHour(hourlyCost, currency)}</span>
|
|
86
100
|
</div>
|
|
87
101
|
</div>
|
|
88
102
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
{/* Top namespaces */}
|
|
104
|
+
<div className="flex-1 min-h-0 space-y-1.5">
|
|
105
|
+
{topNamespaces.map((ns) => {
|
|
106
|
+
const pct = maxCost > 0 ? (ns.hourlyCost / maxCost) * 100 : 0
|
|
107
|
+
return (
|
|
108
|
+
<div key={ns.name} className="flex items-center gap-2">
|
|
109
|
+
<span className="text-[11px] text-theme-text-secondary truncate w-24 shrink-0">{ns.name}</span>
|
|
110
|
+
<div className="flex-1 h-2 rounded-full overflow-hidden bg-theme-hover">
|
|
111
|
+
<div className="h-full rounded-full bg-indigo-500/60" style={{ width: `${Math.max(pct, 2)}%` }} />
|
|
112
|
+
</div>
|
|
113
|
+
<span className="text-[10px] text-theme-text-tertiary tabular-nums w-20 text-right shrink-0">
|
|
114
|
+
{formatProjectedMonthlyRate(ns.hourlyCost, currency)}
|
|
115
|
+
</span>
|
|
116
|
+
</div>
|
|
117
|
+
)
|
|
118
|
+
})}
|
|
119
|
+
{namespaces.length > 5 && (
|
|
120
|
+
<span className="text-[10px] text-theme-text-tertiary">+{namespaces.length - 5} more namespaces</span>
|
|
121
|
+
)}
|
|
99
122
|
</div>
|
|
100
123
|
</div>
|
|
101
|
-
|
|
124
|
+
|
|
125
|
+
<div className="px-4 py-1.5 border-t border-theme-border/50 flex items-center justify-between">
|
|
126
|
+
<span className="text-[10px] text-theme-text-tertiary">
|
|
127
|
+
{currency} · projected from {costFreshnessLabel(data.source, data.window, data.dataThrough)}
|
|
128
|
+
{currency !== DEFAULT_COST_CURRENCY && (
|
|
129
|
+
<> · no conversion</>
|
|
130
|
+
)}
|
|
131
|
+
</span>
|
|
132
|
+
<span className="flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-accent-text">
|
|
133
|
+
{data.source === 'kubecost' ? 'Kubecost' : 'OpenCost'}
|
|
134
|
+
</span>
|
|
135
|
+
</div>
|
|
136
|
+
</CostCardShell>
|
|
102
137
|
)
|
|
103
138
|
}
|
|
@@ -417,6 +417,7 @@ export const MCP_TOOL_CATALOG: MCPToolInfo[] = [
|
|
|
417
417
|
{ arg: 'action', required: true, desc: 'trigger, suspend, or resume' },
|
|
418
418
|
{ arg: 'namespace', required: true, desc: 'cronjob namespace' },
|
|
419
419
|
{ arg: 'name', required: true, desc: 'cronjob name' },
|
|
420
|
+
{ arg: 'job_name', desc: 'trigger only: name for the new Job; omit to generate one' },
|
|
420
421
|
],
|
|
421
422
|
},
|
|
422
423
|
{
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import { DatadogRightsizingPanel } from './DatadogRightsizingPanel'
|
|
7
|
+
import { getApiBase } from '../../api/config'
|
|
8
|
+
import { radarControlBlockedReason } from '../../api/radarFeatures'
|
|
9
|
+
|
|
10
|
+
const state = vi.hoisted(() => ({ fetch: vi.fn(), support: 'supported' as 'supported' | 'unknown' | 'unsupported', capabilitiesFailed: false }))
|
|
11
|
+
vi.mock('../../api/client', () => ({
|
|
12
|
+
fetchJSON: (...args: unknown[]) => state.fetch(...args),
|
|
13
|
+
usePrometheusStatus: () => ({ data: { connected: false } }),
|
|
14
|
+
useRadarFeature: () => ({
|
|
15
|
+
support: state.support,
|
|
16
|
+
blockedReason: radarControlBlockedReason('datadogRightsizing', state.support, state.capabilitiesFailed),
|
|
17
|
+
}),
|
|
18
|
+
}))
|
|
19
|
+
const detail = {
|
|
20
|
+
configured: true,
|
|
21
|
+
rightsizing: {
|
|
22
|
+
kind: 'Deployment',
|
|
23
|
+
namespace: 'team',
|
|
24
|
+
name: 'api',
|
|
25
|
+
source: 'datadog',
|
|
26
|
+
ownerCoverage: 'current_pods',
|
|
27
|
+
replicas: 1,
|
|
28
|
+
scaledToZero: false,
|
|
29
|
+
rows: [],
|
|
30
|
+
sampleAvailable: false,
|
|
31
|
+
reason: 'Insufficient history',
|
|
32
|
+
window: '7d',
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
let root: ReturnType<typeof createRoot>
|
|
36
|
+
let client: QueryClient
|
|
37
|
+
let host: HTMLDivElement
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
state.support = 'supported'
|
|
41
|
+
state.capabilitiesFailed = false
|
|
42
|
+
state.fetch.mockReset()
|
|
43
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
44
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
45
|
+
host = document.createElement('div')
|
|
46
|
+
root = createRoot(host)
|
|
47
|
+
})
|
|
48
|
+
afterEach(async () => {
|
|
49
|
+
await act(async () => root.unmount())
|
|
50
|
+
client.clear()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
async function render(name = 'api') {
|
|
54
|
+
await act(async () =>
|
|
55
|
+
root.render(
|
|
56
|
+
<QueryClientProvider client={client}>
|
|
57
|
+
<DatadogRightsizingPanel kind="Deployment" namespace="team" name={name} />
|
|
58
|
+
</QueryClientProvider>,
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
it('skips sizing reads for spokes without the feature', async () => {
|
|
63
|
+
state.support = 'unsupported'
|
|
64
|
+
await render()
|
|
65
|
+
expect(host.textContent).toContain('Upgrade this cluster')
|
|
66
|
+
expect(state.fetch).not.toHaveBeenCalled()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it.each([
|
|
70
|
+
{ failed: false, message: 'Checking this cluster' },
|
|
71
|
+
{ failed: true, message: 'Refresh to try again' },
|
|
72
|
+
])('explains unknown agent support (failed=$failed) without reading metrics', async ({ failed, message }) => {
|
|
73
|
+
state.support = 'unknown'
|
|
74
|
+
state.capabilitiesFailed = failed
|
|
75
|
+
await render()
|
|
76
|
+
expect(host.querySelector('[role="status"]')?.textContent).toContain(message)
|
|
77
|
+
expect(state.fetch).not.toHaveBeenCalled()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('reads the selected workload and displays its measured coverage', async () => {
|
|
81
|
+
state.fetch.mockResolvedValueOnce(detail)
|
|
82
|
+
await render()
|
|
83
|
+
await vi.waitFor(() => expect(host.textContent).toContain('Insufficient history'))
|
|
84
|
+
expect(host.textContent).toContain('1 current replica')
|
|
85
|
+
expect(state.fetch).toHaveBeenCalledWith(
|
|
86
|
+
'/metrics/datadog/rightsizing/Deployment/team/api',
|
|
87
|
+
expect.any(AbortSignal),
|
|
88
|
+
)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('removes cached workload evidence when a fresh read is denied', async () => {
|
|
92
|
+
state.fetch
|
|
93
|
+
.mockResolvedValueOnce(detail)
|
|
94
|
+
.mockRejectedValueOnce(new Error('Kubernetes denied this read'))
|
|
95
|
+
await render()
|
|
96
|
+
await vi.waitFor(() => expect(host.textContent).toContain('Insufficient history'))
|
|
97
|
+
await act(async () => {
|
|
98
|
+
await client.invalidateQueries({
|
|
99
|
+
queryKey: [
|
|
100
|
+
'datadog-rightsizing',
|
|
101
|
+
getApiBase(),
|
|
102
|
+
'/metrics/datadog/rightsizing/Deployment/team/api',
|
|
103
|
+
],
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
await vi.waitFor(() =>
|
|
107
|
+
expect(host.querySelector('[role="alert"]')?.textContent).toContain(
|
|
108
|
+
'Kubernetes denied this read',
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
expect(host.textContent).not.toContain('Insufficient history')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('reports disabled cluster approval', async () => {
|
|
115
|
+
state.fetch.mockResolvedValueOnce({ configured: false })
|
|
116
|
+
await render()
|
|
117
|
+
await vi.waitFor(() => expect(host.textContent).toContain('unavailable for this cluster'))
|
|
118
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { DatadogRightsizingEvidence } from '@skyhook-io/k8s-ui/components/rightsizing/DatadogRightsizingEvidence'
|
|
3
|
+
import type { DatadogSizingDetail } from '@skyhook-io/k8s-ui/types/rightsizing'
|
|
4
|
+
import { fetchJSON, useRadarFeature } from '../../api/client'
|
|
5
|
+
import { getApiBase } from '../../api/config'
|
|
6
|
+
|
|
7
|
+
export function DatadogRightsizingPanel({
|
|
8
|
+
kind,
|
|
9
|
+
namespace,
|
|
10
|
+
name,
|
|
11
|
+
}: {
|
|
12
|
+
kind: string
|
|
13
|
+
namespace: string
|
|
14
|
+
name: string
|
|
15
|
+
}) {
|
|
16
|
+
const { support, blockedReason } = useRadarFeature('datadogRightsizing')
|
|
17
|
+
const path =
|
|
18
|
+
'/metrics/datadog/rightsizing/' + [kind, namespace, name].map(encodeURIComponent).join('/')
|
|
19
|
+
const queryKey = ['datadog-rightsizing', getApiBase(), path]
|
|
20
|
+
const query = useQuery({
|
|
21
|
+
queryKey,
|
|
22
|
+
enabled: support === 'supported',
|
|
23
|
+
queryFn: ({ signal }) => fetchJSON<DatadogSizingDetail>(path, signal),
|
|
24
|
+
staleTime: 2 * 60_000,
|
|
25
|
+
refetchOnWindowFocus: false,
|
|
26
|
+
retry: false,
|
|
27
|
+
})
|
|
28
|
+
if (support === 'unsupported') {
|
|
29
|
+
return (
|
|
30
|
+
<p className="mt-4 text-sm text-theme-text-secondary">
|
|
31
|
+
Upgrade this cluster’s Radar agent to see Datadog rightsizing.
|
|
32
|
+
</p>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
if (support === 'unknown') {
|
|
36
|
+
return <p role="status" className="mt-4 text-sm text-theme-text-secondary">{blockedReason}</p>
|
|
37
|
+
}
|
|
38
|
+
if (!query.error && query.data?.configured === false) {
|
|
39
|
+
return (
|
|
40
|
+
<p role="status" className="mt-4 text-sm text-theme-text-secondary">
|
|
41
|
+
Datadog rightsizing is unavailable for this cluster.
|
|
42
|
+
</p>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
return (
|
|
46
|
+
<section className="mt-4 rounded-lg border border-theme-border bg-theme-surface p-3">
|
|
47
|
+
<h3 className="text-sm font-medium text-theme-text-primary">Rightsizing</h3>
|
|
48
|
+
{query.error ? (
|
|
49
|
+
<p role="alert" className="mt-2 text-sm text-theme-text-secondary">
|
|
50
|
+
{query.error.message}{' '}
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
className="text-accent hover:underline"
|
|
54
|
+
onClick={() => void query.refetch()}
|
|
55
|
+
>
|
|
56
|
+
Retry
|
|
57
|
+
</button>
|
|
58
|
+
</p>
|
|
59
|
+
) : !query.data?.configured ? (
|
|
60
|
+
<p role="status" className="mt-2 text-sm text-theme-text-secondary">
|
|
61
|
+
Checking workload demand…
|
|
62
|
+
</p>
|
|
63
|
+
) : (
|
|
64
|
+
<DatadogRightsizingEvidence data={query.data.rightsizing} />
|
|
65
|
+
)}
|
|
66
|
+
</section>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { AreaChart, MetricsSummary, type TimeSeries } from '@skyhook-io/k8s-ui/components/charts'
|
|
3
|
+
import { ApiError, fetchJSON, usePrometheusStatus, useRadarFeature, type PrometheusTimeRange } from '../../api/client'
|
|
4
|
+
import { getApiBase } from '../../api/config'
|
|
5
|
+
import { WORKLOAD_CATEGORIES } from './PrometheusCharts'
|
|
6
|
+
import { useNavCustomization } from '../../context/NavCustomization'
|
|
7
|
+
import { RightsizingPanel } from './RightsizingStrip'
|
|
8
|
+
import { DatadogRightsizingPanel } from './DatadogRightsizingPanel'
|
|
9
|
+
|
|
10
|
+
type Metric = 'cpu' | 'memory'
|
|
11
|
+
type Panel = { unit: string; series: TimeSeries[] }
|
|
12
|
+
type Panels = Record<Metric, Panel> & { throttling?: Panel }
|
|
13
|
+
type Workload = { kind: string; namespace: string; name: string }
|
|
14
|
+
type WorkloadCharts = { configured: false } | { configured: true; charts: Panels }
|
|
15
|
+
|
|
16
|
+
const datadogCategories = [
|
|
17
|
+
...WORKLOAD_CATEGORIES.filter((category) => category.key === 'cpu' || category.key === 'memory'),
|
|
18
|
+
{ key: 'throttling', label: 'CPU throttled periods', color: 'text-warning-text', chartColor: 'var(--warning-text)', fillColor: 'color-mix(in srgb, var(--warning-text) 14%, transparent)' },
|
|
19
|
+
] as const
|
|
20
|
+
|
|
21
|
+
interface DatadogStatus {
|
|
22
|
+
configured: boolean
|
|
23
|
+
rightsizing?: boolean
|
|
24
|
+
rightsizingProvider?: 'datadog' | 'prometheus'
|
|
25
|
+
setup?: 'owner' | 'member'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type RightsizingSource = 'datadog' | 'prometheus' | 'unknown' | 'datadog_unavailable'
|
|
29
|
+
|
|
30
|
+
function resolveRightsizingSource(status: DatadogStatus | undefined, error: Error | null, providerRequired: boolean): RightsizingSource {
|
|
31
|
+
if (error) return !providerRequired && error instanceof ApiError && error.unknownRoute ? 'prometheus' : 'unknown'
|
|
32
|
+
if (!status || (providerRequired && !status.rightsizingProvider)) return 'unknown'
|
|
33
|
+
if (status.rightsizingProvider === 'datadog') return status.rightsizing ? 'datadog' : 'datadog_unavailable'
|
|
34
|
+
return 'prometheus'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function useDatadogStatus(kind: string, namespace: string, embedded: boolean) {
|
|
38
|
+
const { rightsizingProviderStatus = false } = useNavCustomization()
|
|
39
|
+
const enabled = embedded && !!namespace && ['Deployment', 'StatefulSet', 'DaemonSet'].includes(kind)
|
|
40
|
+
const apiBase = getApiBase()
|
|
41
|
+
const status = useQuery({
|
|
42
|
+
queryKey: ['datadog-metrics-status', apiBase],
|
|
43
|
+
enabled,
|
|
44
|
+
staleTime: 60_000,
|
|
45
|
+
retry: false,
|
|
46
|
+
queryFn: ({ signal }) => fetchJSON<DatadogStatus>('/metrics/datadog/status', signal),
|
|
47
|
+
})
|
|
48
|
+
const source = enabled ? resolveRightsizingSource(status.data, status.error, rightsizingProviderStatus) : 'prometheus'
|
|
49
|
+
return { status, enabled, source, mapped: enabled && !status.isError && status.data?.configured === true }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function rightsizingOverride(workload: Workload, source: RightsizingSource, retry: () => void, error?: Error | null) {
|
|
53
|
+
if (source === 'prometheus') return null
|
|
54
|
+
if (source === 'datadog') return <DatadogRightsizingPanel key={[workload.kind, workload.namespace, workload.name].join('/')} {...workload} />
|
|
55
|
+
return <section className="mt-4 rounded-lg border border-theme-border bg-theme-surface p-3">
|
|
56
|
+
<h3 className="text-sm font-medium text-theme-text-primary">Rightsizing</h3>
|
|
57
|
+
<p role="alert" className="mt-2 text-sm text-theme-text-secondary">
|
|
58
|
+
{source === 'datadog_unavailable'
|
|
59
|
+
? 'Datadog rightsizing is selected, but this cluster has no usable rightsizing connection.'
|
|
60
|
+
: 'Radar could not determine the rightsizing source.'} {error?.message}{' '}
|
|
61
|
+
<button type="button" className="text-accent hover:underline" onClick={retry}>Retry</button>
|
|
62
|
+
</p>
|
|
63
|
+
</section>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function WorkloadCostRightsizing(workload: Workload) {
|
|
67
|
+
const { embedded = false } = useNavCustomization()
|
|
68
|
+
const { status, source } = useDatadogStatus(workload.kind, workload.namespace, embedded)
|
|
69
|
+
if (status.isLoading) return <p role="status" className="p-3 text-sm text-theme-text-secondary">Checking rightsizing source…</p>
|
|
70
|
+
return rightsizingOverride(workload, source, () => void status.refetch(), status.error) ?? <RightsizingPanel {...workload} />
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function useDatadogWorkloadCharts({ kind, namespace, name }: Workload, range: PrometheusTimeRange, embedded: boolean) {
|
|
74
|
+
const { status, enabled, mapped, source } = useDatadogStatus(kind, namespace, embedded)
|
|
75
|
+
const apiBase = getApiBase()
|
|
76
|
+
const path = [kind, namespace, name].map(encodeURIComponent).join('/')
|
|
77
|
+
const charts = useQuery<WorkloadCharts>({
|
|
78
|
+
queryKey: ['datadog-workload-metrics', apiBase, path, range],
|
|
79
|
+
enabled: mapped,
|
|
80
|
+
staleTime: 30_000,
|
|
81
|
+
retry: false,
|
|
82
|
+
queryFn: ({ signal }) => fetchJSON<WorkloadCharts>(`/metrics/datadog/workloads/${path}?range=${range}`, signal),
|
|
83
|
+
})
|
|
84
|
+
const rightsizing = rightsizingOverride({ kind, namespace, name }, source, () => void status.refetch(), status.error)
|
|
85
|
+
return { charts, rightsizing, setup: enabled && !status.isError ? status.data?.setup : undefined, checking: status.isLoading, configured: mapped && charts.data?.configured !== false }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function DatadogSetupHint({ owner }: { owner: boolean }) {
|
|
89
|
+
const { data: prom, isError } = usePrometheusStatus()
|
|
90
|
+
const { support } = useRadarFeature('datadogAgentPresence')
|
|
91
|
+
const empty = !isError && prom?.connected === false && !prom.discovering && !prom.address
|
|
92
|
+
const presence = useQuery({
|
|
93
|
+
queryKey: ['datadog-agent-presence', getApiBase()],
|
|
94
|
+
enabled: empty && support === 'supported',
|
|
95
|
+
queryFn: ({ signal }) => fetchJSON<{detected: boolean}>('/metrics/datadog/agent', signal),
|
|
96
|
+
staleTime: 60_000, retry: false,
|
|
97
|
+
})
|
|
98
|
+
if (!empty || support !== 'supported' || presence.isError || !presence.data?.detected) return null
|
|
99
|
+
return <div className="p-4 text-center text-sm">
|
|
100
|
+
<p className="font-medium text-theme-text-primary">Datadog Agent detected</p>
|
|
101
|
+
<p className="mt-1 text-theme-text-secondary">{owner ? 'Connect Datadog once for CPU and memory charts across your matched clusters.' : 'An organization owner can connect Datadog for CPU and memory charts.'}</p>
|
|
102
|
+
{owner && <a href="/settings/organization/integrations#datadog-metrics" className="mt-2 inline-block text-accent underline">Connect Datadog</a>}
|
|
103
|
+
</div>
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function DatadogWorkloadCharts({
|
|
107
|
+
charts, error, loading, onRetry,
|
|
108
|
+
}: {
|
|
109
|
+
charts?: Panels
|
|
110
|
+
error?: Error | null
|
|
111
|
+
loading: boolean
|
|
112
|
+
onRetry: () => void
|
|
113
|
+
}) {
|
|
114
|
+
return (
|
|
115
|
+
<section aria-label="Datadog workload totals">
|
|
116
|
+
<h2 className="text-sm font-medium text-theme-text-primary">Datadog <span className="text-theme-text-tertiary">· Beta</span></h2>
|
|
117
|
+
<p className="mb-3 text-xs text-theme-text-secondary">Workload totals across reporting containers, from workload creation</p>
|
|
118
|
+
{loading && <p role="status" className="py-4 text-sm text-theme-text-secondary">Loading Datadog metrics…</p>}
|
|
119
|
+
{error && (
|
|
120
|
+
<div className="py-4 text-sm">
|
|
121
|
+
<p role="alert" className="text-theme-text-secondary">{error.message}</p>
|
|
122
|
+
<button type="button" className="mt-2 text-accent hover:underline" onClick={onRetry}>Retry</button>
|
|
123
|
+
</div>
|
|
124
|
+
)}
|
|
125
|
+
{!error && !loading && charts && (
|
|
126
|
+
<div className="grid gap-3 lg:grid-cols-2">
|
|
127
|
+
{datadogCategories.map((category) => {
|
|
128
|
+
const panel = charts[category.key as keyof Panels]
|
|
129
|
+
if (!panel) return null
|
|
130
|
+
const { unit, series } = panel
|
|
131
|
+
const throttling = category.key === 'throttling'
|
|
132
|
+
return (
|
|
133
|
+
<section key={category.key} className={`min-w-0 rounded-lg border border-theme-border bg-theme-surface p-3${throttling ? ' lg:col-span-2' : ''}`}>
|
|
134
|
+
<header className="mb-2 flex flex-wrap items-center justify-between gap-2">
|
|
135
|
+
<h3 className="text-xs font-medium uppercase tracking-wide text-theme-text-secondary">{category.label}</h3>
|
|
136
|
+
{series.length > 0 && <MetricsSummary series={series} unit={unit} currentColorClass={category.color} />}
|
|
137
|
+
</header>
|
|
138
|
+
{series.length > 0
|
|
139
|
+
? <AreaChart series={series} unit={unit} color={category.chartColor} fillColor={category.fillColor} layout="dashboard" />
|
|
140
|
+
: <p className="py-6 text-center text-xs text-theme-text-secondary">No Datadog samples in this time range.</p>}
|
|
141
|
+
{throttling && <p className="mt-2 text-xs text-theme-text-tertiary">Share of CPU quota periods throttled across reporting containers.</p>}
|
|
142
|
+
</section>
|
|
143
|
+
)
|
|
144
|
+
})}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</section>
|
|
148
|
+
)
|
|
149
|
+
}
|