@skyhook-io/radar-app 1.21.2 → 1.21.4
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 +53 -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 +6 -0
- package/src/api/vulnerabilities.export.test.ts +44 -0
- package/src/api/vulnerabilities.ts +73 -4
- 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/VulnerabilitiesView.test.tsx +177 -0
- package/src/components/audit/VulnerabilitiesView.tsx +197 -48
- 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/traffic/TrafficGraph.export.test.tsx +57 -0
- package/src/components/traffic/TrafficGraph.tsx +9 -4
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +1 -0
- package/src/components/traffic/TrafficView.tsx +17 -2
- 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 +30 -1
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +3 -2
- package/src/components/vulnerabilities/parts.test.ts +59 -3
- package/src/components/vulnerabilities/parts.tsx +199 -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/useDesktopDownload.test.tsx +57 -0
- package/src/hooks/useDesktopDownload.ts +31 -9
- 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,4 +1,5 @@
|
|
|
1
1
|
import type { CostDataSource, CostUnavailableReason } from '../../api/client'
|
|
2
|
+
import { isClusterScopeWithheld, type ClusterScope } from '@skyhook-io/k8s-ui/types/cluster-scope'
|
|
2
3
|
import { previousSettingsNote, type PreviousIntegrationSettings } from '../../hooks/usePreviousIntegrationSettings'
|
|
3
4
|
|
|
4
5
|
export function isCostConfigurable(reason?: string): boolean {
|
|
@@ -8,6 +9,35 @@ export function isCostConfigurable(reason?: string): boolean {
|
|
|
8
9
|
|| reason === 'metrics_settings_error' || reason === 'cost_settings_error'
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The scope a cost answer was withheld under, when its costs couldn't be kept
|
|
14
|
+
* to this cluster in a shared metrics store. Older Radar never sends one.
|
|
15
|
+
*/
|
|
16
|
+
export function costWithheldScope(data?: { available?: boolean; reason?: CostUnavailableReason; clusterScope?: ClusterScope }): ClusterScope | undefined {
|
|
17
|
+
if (!data || data.available || data.reason !== 'cluster_scope') return undefined
|
|
18
|
+
return isClusterScopeWithheld(data.clusterScope) ? data.clusterScope : undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Why an unavailable cost trend was withheld, when the trend view should say
|
|
23
|
+
* so rather than read as "no history": its costs couldn't be kept to this
|
|
24
|
+
* cluster, or the store answered only in part.
|
|
25
|
+
*/
|
|
26
|
+
export type CostTrendWithholding =
|
|
27
|
+
| { reason: 'cluster_scope'; scope?: ClusterScope }
|
|
28
|
+
| { reason: 'partial_data' }
|
|
29
|
+
|
|
30
|
+
export function costTrendWithholding(trend?: { available?: boolean; reason?: CostUnavailableReason; clusterScope?: ClusterScope }): CostTrendWithholding | undefined {
|
|
31
|
+
if (!trend || trend.available) return undefined
|
|
32
|
+
if (trend.reason === 'cluster_scope') return { reason: 'cluster_scope', scope: costWithheldScope(trend) }
|
|
33
|
+
if (trend.reason === 'partial_data') return { reason: 'partial_data' }
|
|
34
|
+
return undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const COST_TREND_WITHHELD_TITLE = 'Cost history withheld for this cluster'
|
|
38
|
+
export const COST_TREND_PARTIAL_NOTE =
|
|
39
|
+
'The metrics store answered only in part for this range, so cost history is withheld rather than shown too low.'
|
|
40
|
+
|
|
11
41
|
export type CostSourcePreference = 'auto' | CostDataSource
|
|
12
42
|
|
|
13
43
|
export const COST_SOURCE_OPTIONS: { value: CostSourcePreference; label: string; description: string }[] = [
|
|
@@ -134,6 +164,10 @@ export function costIntegrationUnavailableMessage(
|
|
|
134
164
|
return 'This cluster’s saved metrics settings need review before cost data can load. Review them in Settings → Metrics.'
|
|
135
165
|
case 'cost_settings_error':
|
|
136
166
|
return 'This cluster’s saved cost settings need review before cost data can load. Review them in Settings → Cost.'
|
|
167
|
+
case 'cluster_scope':
|
|
168
|
+
return "This metrics store holds several clusters, and Radar couldn't keep these costs to this one, so it withholds them rather than show another cluster's spend."
|
|
169
|
+
case 'partial_data':
|
|
170
|
+
return 'The metrics store answered only partially, so cost totals could be missing data. Try again shortly.'
|
|
137
171
|
case 'deployment_configuration_error':
|
|
138
172
|
return "Radar's operator-supplied cost or metrics configuration is invalid. Check local launch flags or the deployment environment variables and Helm values."
|
|
139
173
|
case 'authentication_error':
|
|
@@ -432,6 +432,41 @@ describe("diagnose metrics evidence", () => {
|
|
|
432
432
|
expect(data.partial).toBe(true);
|
|
433
433
|
});
|
|
434
434
|
|
|
435
|
+
it("marks a category the store answered only in part", () => {
|
|
436
|
+
const [cpu, memory, restarts] = vitals().series;
|
|
437
|
+
const projection = project([
|
|
438
|
+
tool(
|
|
439
|
+
"diag",
|
|
440
|
+
"diagnose",
|
|
441
|
+
{
|
|
442
|
+
resource: deployment,
|
|
443
|
+
pods: 2,
|
|
444
|
+
metrics: vitals({
|
|
445
|
+
series: [
|
|
446
|
+
cpu,
|
|
447
|
+
{
|
|
448
|
+
...memory,
|
|
449
|
+
incomplete: true,
|
|
450
|
+
incompleteNote:
|
|
451
|
+
"the metrics store answered only in part, so values may be understated: shard eu-2 did not answer",
|
|
452
|
+
},
|
|
453
|
+
restarts,
|
|
454
|
+
],
|
|
455
|
+
}),
|
|
456
|
+
},
|
|
457
|
+
{ summary: JSON.stringify(args) },
|
|
458
|
+
),
|
|
459
|
+
]);
|
|
460
|
+
const groups = groupsOf(projection.groups, "metrics");
|
|
461
|
+
const summaries = groups.map((group) => group.latest.summary);
|
|
462
|
+
expect(summaries.filter((s) => s?.includes("store answered in part"))).toHaveLength(1);
|
|
463
|
+
const limitation = projection.limitations.find(
|
|
464
|
+
(item) => item.source === "Workload metrics",
|
|
465
|
+
);
|
|
466
|
+
expect(limitation?.kind).toBe("truncated");
|
|
467
|
+
expect(limitation?.message).toContain("shard eu-2 did not answer");
|
|
468
|
+
});
|
|
469
|
+
|
|
435
470
|
it("keeps a neighbour's vitals broader with the neighbour as subject", () => {
|
|
436
471
|
const worker = {
|
|
437
472
|
...deployment,
|
|
@@ -942,12 +942,18 @@ function addDiagnoseMetrics(
|
|
|
942
942
|
!nonEmptyString(entry.unit) ||
|
|
943
943
|
!Array.isArray(rawSeries) ||
|
|
944
944
|
!series ||
|
|
945
|
-
series.length !== rawSeries.length
|
|
945
|
+
series.length !== rawSeries.length ||
|
|
946
|
+
(entry.incomplete !== undefined && typeof entry.incomplete !== "boolean") ||
|
|
947
|
+
(entry.incompleteNote !== undefined &&
|
|
948
|
+
typeof entry.incompleteNote !== "string")
|
|
946
949
|
) {
|
|
947
950
|
invalidPayload(builder, source, "Workload metrics");
|
|
948
951
|
continue;
|
|
949
952
|
}
|
|
950
953
|
const label = DIAGNOSE_METRICS_LABELS[entry.category];
|
|
954
|
+
// The store answered this category only in part: what it returned may
|
|
955
|
+
// understate the workload, so the card and the limitations say so.
|
|
956
|
+
const incomplete = entry.incomplete === true;
|
|
951
957
|
const data: InvestigationMetricsEvidence = {
|
|
952
958
|
type: "metrics",
|
|
953
959
|
origin: "diagnose",
|
|
@@ -978,12 +984,21 @@ function addDiagnoseMetrics(
|
|
|
978
984
|
series.length === 0 ? "No samples in the window" : podsLabel,
|
|
979
985
|
windowLabel,
|
|
980
986
|
partial ? "partial pod set" : undefined,
|
|
987
|
+
incomplete ? "store answered in part" : undefined,
|
|
981
988
|
]
|
|
982
989
|
.filter((part): part is string => Boolean(part))
|
|
983
990
|
.join(" · "),
|
|
984
991
|
data,
|
|
985
992
|
},
|
|
986
993
|
);
|
|
994
|
+
if (incomplete) {
|
|
995
|
+
builder.limit(
|
|
996
|
+
source,
|
|
997
|
+
"Workload metrics",
|
|
998
|
+
`${label}: ${nonEmptyString(entry.incompleteNote) ? entry.incompleteNote : "the metrics store answered only in part"}`,
|
|
999
|
+
"truncated",
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
987
1002
|
}
|
|
988
1003
|
if (nonEmptyString(value.error)) {
|
|
989
1004
|
builder.limit(source, "Workload metrics", value.error, "error");
|
|
@@ -7,7 +7,8 @@ const captured = vi.hoisted(() => ({ props: null as NodeTerminalTabProps | null
|
|
|
7
7
|
vi.mock('@skyhook-io/k8s-ui', () => ({
|
|
8
8
|
NodeTerminalTab: (props: NodeTerminalTabProps) => { captured.props = props; return null },
|
|
9
9
|
}))
|
|
10
|
-
vi.mock('../../api/config', () => ({
|
|
10
|
+
vi.mock('../../api/config', async (importOriginal) => ({
|
|
11
|
+
...await importOriginal<typeof import('../../api/config')>(),
|
|
11
12
|
apiUrl: (path: string) => `/api${path}`,
|
|
12
13
|
getWsUrl: (path: string) => path,
|
|
13
14
|
getAuthHeaders: () => ({ Authorization: 'Bearer test' }),
|
|
@@ -29,6 +30,7 @@ it('passes the created UID to exact-pod cleanup query parameters with keepalive'
|
|
|
29
30
|
const parsed = new URL(url, 'http://localhost')
|
|
30
31
|
expect(parsed.pathname).toBe('/api/nodes/node%2Fa/debug')
|
|
31
32
|
expect(Object.fromEntries(parsed.searchParams)).toEqual({ namespace: 'default', podName: 'debug-a', uid: 'uid/a+b' })
|
|
32
|
-
expect(options).toMatchObject({ method: 'DELETE', keepalive: true, credentials: 'include'
|
|
33
|
+
expect(options).toMatchObject({ method: 'DELETE', keepalive: true, credentials: 'include' })
|
|
34
|
+
expect(new Headers(options.headers).get('Authorization')).toBe('Bearer test')
|
|
33
35
|
expect(options).not.toHaveProperty('body')
|
|
34
36
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NodeTerminalTab as SharedNodeTerminalTab, type NodeTerminalTabProps as SharedNodeTerminalTabProps } from '@skyhook-io/k8s-ui'
|
|
2
|
-
import { apiUrl, getWsUrl
|
|
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 NodeTerminalTabProps {
|
|
@@ -8,11 +10,11 @@ interface NodeTerminalTabProps {
|
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export function NodeTerminalTab({ nodeName, isActive }: NodeTerminalTabProps) {
|
|
13
|
+
const connection = useOpenedConnection()
|
|
11
14
|
const createNodeDebugPod = async (name: string) => {
|
|
12
|
-
const response = await
|
|
15
|
+
const response = await apiFetch(apiUrl(`/nodes/${encodeURIComponent(name)}/debug`), {
|
|
13
16
|
method: 'POST',
|
|
14
|
-
|
|
15
|
-
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
|
17
|
+
headers: { 'Content-Type': 'application/json', ...connectionHeaders(connection) },
|
|
16
18
|
body: JSON.stringify({}),
|
|
17
19
|
})
|
|
18
20
|
if (!response.ok) {
|
|
@@ -25,10 +27,8 @@ export function NodeTerminalTab({ nodeName, isActive }: NodeTerminalTabProps) {
|
|
|
25
27
|
const cleanupNodeDebugPod: SharedNodeTerminalTabProps['cleanupNodeDebugPod'] = async (name, pod) => {
|
|
26
28
|
const query = new URLSearchParams({ namespace: pod.namespace, podName: pod.podName, uid: pod.uid })
|
|
27
29
|
try {
|
|
28
|
-
const response = await
|
|
30
|
+
const response = await apiFetch(apiUrl(`/nodes/${encodeURIComponent(name)}/debug?${query}`), {
|
|
29
31
|
method: 'DELETE',
|
|
30
|
-
credentials: getCredentialsMode(),
|
|
31
|
-
headers: getAuthHeaders(),
|
|
32
32
|
keepalive: true,
|
|
33
33
|
})
|
|
34
34
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
@@ -38,7 +38,7 @@ export function NodeTerminalTab({ nodeName, isActive }: NodeTerminalTabProps) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const createSession = async (namespace: string, podName: string, containerName: string) => ({
|
|
41
|
-
wsUrl: getWsUrl(`/pods/${encodeURIComponent(namespace)}/${encodeURIComponent(podName)}/exec?container=${encodeURIComponent(containerName)}`),
|
|
41
|
+
wsUrl: withConnectionParam(getWsUrl(`/pods/${encodeURIComponent(namespace)}/${encodeURIComponent(podName)}/exec?container=${encodeURIComponent(containerName)}`), connection),
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
return (
|
|
@@ -4,7 +4,7 @@ import type { TerminalTabProps } from '@skyhook-io/k8s-ui'
|
|
|
4
4
|
import { TerminalTab } from './TerminalTab'
|
|
5
5
|
const captured = vi.hoisted(() => ({ props: null as TerminalTabProps | null }))
|
|
6
6
|
vi.mock('@skyhook-io/k8s-ui', () => ({ TerminalTab: (props: TerminalTabProps) => { captured.props = props; return null } }))
|
|
7
|
-
vi.mock('../../api/config', () => ({ apiUrl: (path: string) => `/api${path}`, getWsUrl: (path: string) => `ws://localhost/api${path}` }))
|
|
7
|
+
vi.mock('../../api/config', async (importOriginal) => ({ ...await importOriginal<typeof import('../../api/config')>(), apiUrl: (path: string) => `/api${path}`, getWsUrl: (path: string) => `ws://localhost/api${path}` }))
|
|
8
8
|
it.each([undefined, '/bin/custom+command'])('forwards the executable and context through the shared terminal (%s)', async shell => {
|
|
9
9
|
renderToString(<TerminalTab namespace="app" podName="worker" containerName="app" containers={['app', 'sidecar']} shell={shell} note="Primary" />)
|
|
10
10
|
const props = captured.props!
|
|
@@ -15,3 +15,14 @@ it.each([undefined, '/bin/custom+command'])('forwards the executable and context
|
|
|
15
15
|
expect(url.pathname).toBe('/api/pods/app/worker/exec'); expect(url.searchParams.get('container')).toBe('app')
|
|
16
16
|
expect(url.searchParams.get('shell')).toBe(shell ?? null)
|
|
17
17
|
})
|
|
18
|
+
|
|
19
|
+
it('reconnects on the connection the tab was opened on, not the latest', async () => {
|
|
20
|
+
const { observeConnectionStatus, resetConnectionBindingForTest } = await import('../../api/connectionBinding')
|
|
21
|
+
resetConnectionBindingForTest()
|
|
22
|
+
observeConnectionStatus({ connectionId: 'n-1' })
|
|
23
|
+
renderToString(<TerminalTab namespace="app" podName="worker" containerName="app" containers={['app']} />)
|
|
24
|
+
observeConnectionStatus({ connectionId: 'n-2' }) // switched since the tab opened
|
|
25
|
+
const { wsUrl } = await captured.props!.createSession('app')
|
|
26
|
+
expect(new URL(wsUrl).searchParams.get('connection')).toBe('n-1')
|
|
27
|
+
resetConnectionBindingForTest()
|
|
28
|
+
})
|
|
@@ -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
|
+
})
|