@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.
Files changed (103) hide show
  1. package/README.md +11 -0
  2. package/package.json +2 -2
  3. package/src/App.tsx +53 -28
  4. package/src/api/actions.test.ts +11 -0
  5. package/src/api/actions.ts +5 -0
  6. package/src/api/apiResources.navigation.test.tsx +58 -0
  7. package/src/api/apiResources.ts +22 -16
  8. package/src/api/client.diagnostics.test.ts +52 -0
  9. package/src/api/client.triggerCronJob.test.tsx +49 -0
  10. package/src/api/client.ts +140 -120
  11. package/src/api/connectionBinding.test.tsx +82 -0
  12. package/src/api/connectionBinding.ts +52 -0
  13. package/src/api/contextSwitch.test.ts +11 -0
  14. package/src/api/contextSwitch.ts +58 -0
  15. package/src/api/radarFeatures.ts +6 -0
  16. package/src/api/vulnerabilities.export.test.ts +44 -0
  17. package/src/api/vulnerabilities.ts +73 -4
  18. package/src/components/ConnectionErrorView.tsx +13 -0
  19. package/src/components/ContextSwitchActions.tsx +43 -0
  20. package/src/components/ContextSwitcher.tsx +13 -6
  21. package/src/components/SwitchAwareConnectionError.tsx +2 -2
  22. package/src/components/audit/VulnerabilitiesView.test.tsx +177 -0
  23. package/src/components/audit/VulnerabilitiesView.tsx +197 -48
  24. package/src/components/cost/ApplicationCostTab.test.ts +16 -0
  25. package/src/components/cost/ApplicationCostTab.tsx +41 -9
  26. package/src/components/cost/CostTrendChart.tsx +25 -2
  27. package/src/components/cost/CostTrendWithheld.render.test.tsx +105 -0
  28. package/src/components/cost/CostView.tsx +10 -2
  29. package/src/components/cost/CostViewTabs.test.tsx +18 -0
  30. package/src/components/cost/CostViewTabs.tsx +14 -22
  31. package/src/components/cost/WorkloadCostTab.test.ts +15 -0
  32. package/src/components/cost/WorkloadCostTab.tsx +42 -8
  33. package/src/components/cost/source.test.ts +16 -1
  34. package/src/components/cost/source.ts +34 -0
  35. package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +35 -0
  36. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +16 -1
  37. package/src/components/dock/NodeTerminalTab.test.tsx +4 -2
  38. package/src/components/dock/NodeTerminalTab.tsx +8 -8
  39. package/src/components/dock/TerminalTab.test.tsx +12 -1
  40. package/src/components/dock/TerminalTab.tsx +6 -3
  41. package/src/components/home/CostCard.test.tsx +49 -0
  42. package/src/components/home/CostCard.tsx +98 -63
  43. package/src/components/home/mcpToolCatalog.ts +1 -0
  44. package/src/components/resource/DatadogRightsizingPanel.test.tsx +118 -0
  45. package/src/components/resource/DatadogRightsizingPanel.tsx +68 -0
  46. package/src/components/resource/DatadogWorkloadCharts.tsx +149 -0
  47. package/src/components/resource/HPACharts.render.test.tsx +42 -0
  48. package/src/components/resource/HPACharts.tsx +34 -1
  49. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +126 -3
  50. package/src/components/resource/PrometheusChartsGrid.tsx +58 -25
  51. package/src/components/resource/RestartChart.render.test.tsx +72 -0
  52. package/src/components/resource/RestartChart.tsx +31 -3
  53. package/src/components/resource/RightsizingPanel.access.test.tsx +24 -0
  54. package/src/components/resource/RightsizingStrip.render.test.tsx +44 -0
  55. package/src/components/resource/RightsizingStrip.test.ts +1 -188
  56. package/src/components/resource/RightsizingStrip.tsx +27 -300
  57. package/src/components/resource/WorkloadMetricsSection.render.test.tsx +22 -0
  58. package/src/components/resource/WorkloadMetricsSection.tsx +14 -4
  59. package/src/components/resource/nameMatchedScope.ts +39 -0
  60. package/src/components/resources/pod-file-upload.ts +3 -0
  61. package/src/components/resources/renderers/CAPIClusterRenderer.tsx +5 -2
  62. package/src/components/resources/renderers/LonghornVolumeRenderer.test.tsx +104 -0
  63. package/src/components/resources/renderers/LonghornVolumeRenderer.tsx +31 -0
  64. package/src/components/rightsizing/RightsizingScanLink.tsx +22 -0
  65. package/src/components/rightsizing/RightsizingScanView.tsx +65 -528
  66. package/src/components/rightsizing/model.test.ts +20 -9
  67. package/src/components/rightsizing/model.ts +17 -176
  68. package/src/components/rightsizing/notices.test.tsx +30 -29
  69. package/src/components/traffic/TrafficGraph.export.test.tsx +57 -0
  70. package/src/components/traffic/TrafficGraph.tsx +9 -4
  71. package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +1 -0
  72. package/src/components/traffic/TrafficView.tsx +17 -2
  73. package/src/components/ui/DiagnosticsOverlay.test.ts +3 -2
  74. package/src/components/ui/DiagnosticsOverlay.tsx +23 -13
  75. package/src/components/ui/command-items.ts +3 -4
  76. package/src/components/useContextSwitchFlow.test.tsx +9 -0
  77. package/src/components/useContextSwitchFlow.tsx +43 -5
  78. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.test.tsx +30 -1
  79. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +3 -2
  80. package/src/components/vulnerabilities/parts.test.ts +59 -3
  81. package/src/components/vulnerabilities/parts.tsx +199 -5
  82. package/src/components/workload/WorkloadRightsizingSource.test.tsx +83 -0
  83. package/src/components/workload/WorkloadView.test.ts +22 -1
  84. package/src/components/workload/WorkloadView.tsx +57 -16
  85. package/src/context/ConnectionContext.test.ts +1 -0
  86. package/src/context/ConnectionContext.tsx +58 -15
  87. package/src/context/ConnectionProvider.connectionId.test.tsx +92 -0
  88. package/src/context/ConnectionProvider.retry.test.tsx +174 -1
  89. package/src/context/ContextSwitchContext.tsx +15 -1
  90. package/src/context/NavCustomization.tsx +6 -3
  91. package/src/hooks/useDesktopDownload.test.tsx +57 -0
  92. package/src/hooks/useDesktopDownload.ts +31 -9
  93. package/src/hooks/useEventSource.test.tsx +85 -0
  94. package/src/hooks/useEventSource.ts +43 -16
  95. package/src/hooks/useResetViewsOnContextChange.test.tsx +34 -0
  96. package/src/hooks/useResetViewsOnContextChange.ts +27 -0
  97. package/src/index.ts +3 -0
  98. package/src/integrations/resourceHosts.test.tsx +1 -1
  99. package/src/integrations/resourceHosts.tsx +2 -0
  100. package/src/utils/navigation.ts +1 -15
  101. package/src/utils/page-links.ts +6 -0
  102. package/src/components/rightsizing/presentation.test.ts +0 -150
  103. package/src/components/rightsizing/presentation.ts +0 -109
@@ -14,7 +14,7 @@ import {
14
14
  type OpenCostTrendSeries,
15
15
  } from '../../api/client'
16
16
  import { Tooltip } from '../ui/Tooltip'
17
- import { ChartLegend, CostTimeRangeSelector, StackedAreaChart } from './CostTrendChart'
17
+ import { ChartLegend, CostTimeRangeSelector, CostTrendWithheldNote, StackedAreaChart } from './CostTrendChart'
18
18
  import {
19
19
  DEFAULT_COST_CURRENCY,
20
20
  formatCostPerHour,
@@ -31,10 +31,14 @@ import {
31
31
  costIntegrationUnavailableMessage,
32
32
  costRateLabels,
33
33
  costSourceLabel,
34
+ costTrendWithholding,
35
+ costWithheldScope,
34
36
  isCostDiscoveryPending,
35
37
  } from './source'
36
38
  import { useNavCustomization } from '../../context/NavCustomization'
37
39
  import { CostConnectionAction } from './CostConnectionAction'
40
+ import { ClusterScopeNote } from '@skyhook-io/k8s-ui/components/ui/ClusterScopeNote'
41
+ import type { ClusterScope } from '@skyhook-io/k8s-ui/types/cluster-scope'
38
42
 
39
43
  type ApplicationCostState =
40
44
  | 'loading'
@@ -136,6 +140,8 @@ export function ApplicationCostTab({
136
140
  state === 'deployment_configuration_error' ||
137
141
  state === 'metrics_settings_error' ||
138
142
  state === 'cost_settings_error' ||
143
+ state === 'cluster_scope' ||
144
+ state === 'partial_data' ||
139
145
  state === 'history_unsupported' ||
140
146
  state === 'load_error'
141
147
  ) {
@@ -153,7 +159,14 @@ export function ApplicationCostTab({
153
159
  )
154
160
  }
155
161
  const refusal = crossOriginRefusalMessage(currentQuery.error) ?? crossOriginRefusalMessage(trendQuery.error)
156
- return <ApplicationCostUnavailable state={state} message={refusal} settingsAvailable={settingsAvailable} />
162
+ return (
163
+ <ApplicationCostUnavailable
164
+ state={state}
165
+ message={refusal}
166
+ settingsAvailable={settingsAvailable}
167
+ withheld={costWithheldScope(currentQuery.data) ?? costWithheldScope(trendQuery.data)}
168
+ />
169
+ )
157
170
  }
158
171
 
159
172
  const current = currentQuery.data
@@ -176,6 +189,9 @@ export function ApplicationCostTab({
176
189
  const trendCurrency = trend?.currency ?? current?.currency ?? DEFAULT_COST_CURRENCY
177
190
  const source = current?.source ?? trend?.source
178
191
  const historyUnsupported = trend?.reason === 'history_unsupported'
192
+ // Current costs stand while the trend was withheld: say why, rather than
193
+ // that the range has no history.
194
+ const trendWithholding = state === 'partial_missing_history' ? costTrendWithholding(trend) : undefined
179
195
  const currentWindow = current?.window
180
196
  const rateLabels = costRateLabels(currentWindow)
181
197
 
@@ -183,7 +199,7 @@ export function ApplicationCostTab({
183
199
  <div className="mx-auto w-full max-w-[1600px] space-y-4">
184
200
  {(current?.partial ||
185
201
  trend?.partial ||
186
- (state === 'partial_missing_history' && !historyUnsupported) ||
202
+ (state === 'partial_missing_history' && !historyUnsupported && !trendWithholding) ||
187
203
  state === 'partial_missing_current' ||
188
204
  unsupportedCount > 0) && (
189
205
  <div className="flex items-start gap-2 rounded-lg border border-theme-border bg-theme-base px-3 py-2 text-sm text-theme-text-secondary">
@@ -248,8 +264,10 @@ export function ApplicationCostTab({
248
264
  trendCurrency,
249
265
  )}
250
266
  subvalue={
251
- state === 'partial_missing_history'
252
- ? 'Historical data incomplete'
267
+ trendWithholding
268
+ ? 'Historical data withheld'
269
+ : state === 'partial_missing_history'
270
+ ? 'Historical data incomplete'
253
271
  : `${included} of ${total} workloads included`
254
272
  }
255
273
  />
@@ -275,8 +293,12 @@ export function ApplicationCostTab({
275
293
  <ChartLegend series={chartSeries} />
276
294
  </div>
277
295
  ) : (
278
- <div className="flex h-[240px] items-center justify-center rounded-md border border-dashed border-theme-border bg-theme-base/60 text-sm text-theme-text-tertiary">
279
- No historical workload owner cost points for this range.
296
+ <div className="flex h-[240px] items-center justify-center rounded-md border border-dashed border-theme-border bg-theme-base/60 px-4 text-sm text-theme-text-tertiary">
297
+ {trendWithholding ? (
298
+ <CostTrendWithheldNote withholding={trendWithholding} />
299
+ ) : (
300
+ 'No historical workload owner cost points for this range.'
301
+ )}
280
302
  </div>
281
303
  )}
282
304
  </div>
@@ -409,7 +431,9 @@ export function getApplicationCostState(
409
431
  reason === 'configuration_mismatch' ||
410
432
  reason === 'deployment_configuration_error' ||
411
433
  reason === 'metrics_settings_error' ||
412
- reason === 'cost_settings_error'
434
+ reason === 'cost_settings_error' ||
435
+ reason === 'cluster_scope' ||
436
+ reason === 'partial_data'
413
437
  )
414
438
  return reason
415
439
  if (queryError) return 'load_error'
@@ -525,6 +549,8 @@ function reasonLabel(reason?: CostUnavailableReason) {
525
549
  if (reason === 'deployment_configuration_error') return 'Radar configuration is invalid'
526
550
  if (reason === 'metrics_settings_error') return 'Saved metrics settings need review'
527
551
  if (reason === 'cost_settings_error') return 'Saved cost settings need review'
552
+ if (reason === 'cluster_scope') return 'Withheld: shared metrics store'
553
+ if (reason === 'partial_data') return 'Partial answer from the metrics store'
528
554
  return 'No workload cost metrics'
529
555
  }
530
556
 
@@ -564,10 +590,12 @@ function ApplicationCostUnavailable({
564
590
  state,
565
591
  message,
566
592
  settingsAvailable,
593
+ withheld,
567
594
  }: {
568
595
  state: CostUnavailableReason | 'load_error'
569
596
  message?: string
570
597
  settingsAvailable: boolean
598
+ withheld?: ClusterScope
571
599
  }) {
572
600
  const text =
573
601
  message ??
@@ -587,7 +615,11 @@ function ApplicationCostUnavailable({
587
615
  <div className="flex h-full min-h-[320px] items-center justify-center">
588
616
  <div className="flex max-w-md flex-col items-center gap-3 text-center text-theme-text-secondary">
589
617
  <Coins className="h-8 w-8 text-theme-text-tertiary/50" />
590
- <div className="text-sm">{text}</div>
618
+ {state === 'cluster_scope' && withheld ? (
619
+ <ClusterScopeNote scope={withheld} title="Costs withheld for this cluster" className="text-left" />
620
+ ) : (
621
+ <div className="text-sm">{text}</div>
622
+ )}
591
623
  <CostConnectionAction reason={state} />
592
624
  </div>
593
625
  </div>
@@ -9,7 +9,14 @@ import {
9
9
  type OpenCostTrendSeries,
10
10
  } from '../../api/client'
11
11
  import { DEFAULT_COST_CURRENCY, formatCostAxis, formatCostPerHour } from './format'
12
- import { costDataThroughLabel } from './source'
12
+ import { ClusterScopeNote } from '@skyhook-io/k8s-ui/components/ui/ClusterScopeNote'
13
+ import {
14
+ COST_TREND_PARTIAL_NOTE,
15
+ COST_TREND_WITHHELD_TITLE,
16
+ costDataThroughLabel,
17
+ costTrendWithholding,
18
+ type CostTrendWithholding,
19
+ } from './source'
13
20
 
14
21
  const SERIES_COLORS = [
15
22
  '#3b82f6', // blue-500
@@ -45,7 +52,11 @@ export function CostTrendChart({ namespaceScoped = false }: { namespaceScoped?:
45
52
  }
46
53
 
47
54
  const showKubecostUnavailable = data?.source === 'kubecost' && data.available === false
48
- if ((!data?.available || !data.series?.length) && !showKubecostUnavailable) {
55
+ // Hiding a withheld trend (cluster scope, or a partial answer) would read as
56
+ // "no history"; other unavailable Prometheus trends stay hidden.
57
+ const withholding = costTrendWithholding(data)
58
+ const withheld = !showKubecostUnavailable && withholding && (withholding.reason === 'partial_data' || withholding.scope) ? withholding : undefined
59
+ if (!data || ((!data.available || !data.series?.length) && !showKubecostUnavailable && !withheld)) {
49
60
  return null
50
61
  }
51
62
 
@@ -76,6 +87,10 @@ export function CostTrendChart({ namespaceScoped = false }: { namespaceScoped?:
76
87
  <div className="min-h-[268px] flex items-center justify-center px-6 text-center text-xs text-theme-text-tertiary">
77
88
  {kubecostTrendUnavailableMessage(data.reason, namespaceScoped)}
78
89
  </div>
90
+ ) : withheld ? (
91
+ <div className="min-h-[268px] flex items-center justify-center px-6">
92
+ <CostTrendWithheldNote withholding={withheld} />
93
+ </div>
79
94
  ) : (
80
95
  <>
81
96
  <StackedAreaChart
@@ -93,6 +108,14 @@ export function CostTrendChart({ namespaceScoped = false }: { namespaceScoped?:
93
108
  )
94
109
  }
95
110
 
111
+ /** Says why a cost trend was withheld, in place of an empty chart. */
112
+ export function CostTrendWithheldNote({ withholding }: { withholding: CostTrendWithholding }) {
113
+ if (withholding.reason === 'cluster_scope') {
114
+ return <ClusterScopeNote scope={withholding.scope} title={COST_TREND_WITHHELD_TITLE} className="max-w-md text-left" />
115
+ }
116
+ return <p className="max-w-md text-center text-sm text-theme-text-tertiary">{COST_TREND_PARTIAL_NOTE}</p>
117
+ }
118
+
96
119
  export function StackedAreaChart({
97
120
  series,
98
121
  currency,
@@ -0,0 +1,105 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { renderToStaticMarkup } from 'react-dom/server'
3
+ import { MemoryRouter } from 'react-router-dom'
4
+ import type { AppRow, AppWorkload } from '@skyhook-io/k8s-ui'
5
+
6
+ const sharedStore = { state: 'several_clusters' as const, note: 'This metrics store holds several clusters.' }
7
+ let workloadTrend: Record<string, unknown> | undefined
8
+ let applicationTrend: Record<string, unknown> | undefined
9
+ let namespaceTrend: Record<string, unknown> | undefined
10
+
11
+ const query = (data: unknown) => ({ data, isLoading: false, isFetching: false, error: null, refetch: vi.fn() })
12
+
13
+ vi.mock('../../api/client', async (importActual) => ({
14
+ ...(await importActual<typeof import('../../api/client')>()),
15
+ useOpenCostWorkload: () => query({
16
+ available: true,
17
+ currency: 'USD',
18
+ namespace: 'shop',
19
+ kind: 'Deployment',
20
+ name: 'api',
21
+ current: {
22
+ name: 'api', kind: 'Deployment', hourlyCost: 0.2, cpuCost: 0.12, memoryCost: 0.08, replicas: 2,
23
+ cpuUsageAvailable: true, memoryUsageAvailable: true, cpuAllocationUse: 25, memoryAllocationUse: 25,
24
+ },
25
+ }),
26
+ useOpenCostWorkloadTrend: () => query(workloadTrend),
27
+ useOpenCostApplicationCost: () => query({
28
+ available: true,
29
+ currency: 'USD',
30
+ totals: { hourlyCost: 0.2, cpuCost: 0.12, memoryCost: 0.08, replicas: 2, cpuUsageAvailable: true, memoryUsageAvailable: true },
31
+ coverage: { total: 1, included: 1 },
32
+ workloads: [],
33
+ }),
34
+ useOpenCostApplicationCostTrend: () => query(applicationTrend),
35
+ useOpenCostTrend: () => query(namespaceTrend),
36
+ }))
37
+
38
+ const { WorkloadCostTab } = await import('./WorkloadCostTab')
39
+ const { ApplicationCostTab } = await import('./ApplicationCostTab')
40
+ const { CostTrendChart } = await import('./CostTrendChart')
41
+ const { COST_TREND_PARTIAL_NOTE, COST_TREND_WITHHELD_TITLE } = await import('./source')
42
+
43
+ const NO_HISTORY = 'No historical workload owner cost points for this range.'
44
+ const withRouter = (node: React.ReactNode) => renderToStaticMarkup(<MemoryRouter>{node}</MemoryRouter>)
45
+ const renderWorkload = () => withRouter(<WorkloadCostTab kind="Deployment" namespace="shop" name="api" />)
46
+ const app = { name: 'shop' } as AppRow
47
+ const workloads = [{ kind: 'Deployment', namespace: 'shop', name: 'api' }] as AppWorkload[]
48
+ const renderApplication = () => withRouter(<ApplicationCostTab app={app} workloads={workloads} />)
49
+
50
+ function trend(reason: string, extra: Record<string, unknown> = {}) {
51
+ return { available: false, reason, currency: 'USD', namespace: 'shop', kind: 'Deployment', name: 'api', range: '24h', ...extra }
52
+ }
53
+
54
+ beforeEach(() => {
55
+ workloadTrend = undefined
56
+ applicationTrend = undefined
57
+ namespaceTrend = undefined
58
+ })
59
+
60
+ describe('a withheld cost trend beside current costs', () => {
61
+ it.each([
62
+ ['workload', (t: Record<string, unknown>) => { workloadTrend = t }, renderWorkload],
63
+ ['application', (t: Record<string, unknown>) => { applicationTrend = t }, renderApplication],
64
+ ] as const)('%s tab says why the trend was withheld', (_name, setTrend, render) => {
65
+ setTrend(trend('cluster_scope', { clusterScope: sharedStore }))
66
+ let html = render()
67
+ expect(html).toContain(COST_TREND_WITHHELD_TITLE)
68
+ expect(html).toContain(sharedStore.note)
69
+ expect(html).not.toContain(NO_HISTORY)
70
+
71
+ setTrend(trend('partial_data'))
72
+ html = render()
73
+ expect(html).toContain(COST_TREND_PARTIAL_NOTE)
74
+ expect(html).not.toContain(NO_HISTORY)
75
+
76
+ setTrend(trend('query_error'))
77
+ html = render()
78
+ expect(html).toContain(NO_HISTORY)
79
+ expect(html).not.toContain(COST_TREND_PARTIAL_NOTE)
80
+ expect(html).not.toContain(COST_TREND_WITHHELD_TITLE)
81
+ })
82
+ })
83
+
84
+ describe('CostTrendChart', () => {
85
+ it('shows a cluster-scope withheld Prometheus trend instead of hiding it', () => {
86
+ namespaceTrend = { available: false, reason: 'cluster_scope', source: 'prometheus', range: '24h', clusterScope: sharedStore }
87
+ const html = renderToStaticMarkup(<CostTrendChart />)
88
+ expect(html).toContain(COST_TREND_WITHHELD_TITLE)
89
+ expect(html).toContain(sharedStore.note)
90
+ })
91
+
92
+ it('says a Prometheus trend was withheld for a partial answer instead of hiding it', () => {
93
+ namespaceTrend = { available: false, reason: 'partial_data', source: 'prometheus', range: '24h' }
94
+ const html = renderToStaticMarkup(<CostTrendChart />)
95
+ expect(html).toContain(COST_TREND_PARTIAL_NOTE)
96
+ expect(html).not.toContain(COST_TREND_WITHHELD_TITLE)
97
+ })
98
+
99
+ it('keeps hiding other unavailable Prometheus trends', () => {
100
+ for (const reason of ['query_error', 'no_metrics']) {
101
+ namespaceTrend = { available: false, reason, source: 'prometheus', range: '24h' }
102
+ expect(renderToStaticMarkup(<CostTrendChart />)).toBe('')
103
+ }
104
+ })
105
+ })
@@ -1,3 +1,4 @@
1
+ import { isRightsizingScanPath } from '../../utils/page-links'
1
2
  import { useState, useEffect } from 'react'
2
3
  import { useLocation } from 'react-router-dom'
3
4
  import {
@@ -42,11 +43,13 @@ import { RightsizingScanView } from '../rightsizing/RightsizingScanView'
42
43
  import { CostViewTabs } from './CostViewTabs'
43
44
  import { useNavCustomization } from '../../context/NavCustomization'
44
45
  import { CostConnectionAction } from './CostConnectionAction'
46
+ import { ClusterScopeNote } from '@skyhook-io/k8s-ui/components/ui/ClusterScopeNote'
45
47
  import {
46
48
  costFreshnessLabel,
47
49
  costIntegrationUnavailableMessage,
48
50
  costRateLabels,
49
51
  costSourceLabel,
52
+ costWithheldScope,
50
53
  isCostDiscoveryPending,
51
54
  } from './source'
52
55
 
@@ -62,7 +65,7 @@ const STORAGE_UNKNOWN_HINT =
62
65
 
63
66
  export function CostView(props: CostViewProps) {
64
67
  const { pathname } = useLocation()
65
- if (pathname.startsWith('/cost/rightsizing')) {
68
+ if (isRightsizingScanPath(pathname)) {
66
69
  return <RightsizingScanView namespaces={props.namespaces} />
67
70
  }
68
71
  return <CostOverview {...props} />
@@ -132,13 +135,18 @@ function CostOverview({ onBack, onOpenResource }: CostViewProps) {
132
135
  settingsAvailable,
133
136
  namespaceScoped: namespaceScopeCount > 0,
134
137
  })
138
+ const withheld = costWithheldScope(data)
135
139
 
136
140
  return (
137
141
  <CostOverviewState>
138
142
  <div className="flex min-h-64 items-center justify-center">
139
143
  <div className="flex flex-col items-center gap-3 text-theme-text-secondary">
140
144
  <Coins className="w-8 h-8 text-theme-text-tertiary/40" />
141
- <p className="text-sm">{message}</p>
145
+ {withheld ? (
146
+ <ClusterScopeNote scope={withheld} title="Costs withheld for this cluster" className="max-w-md" />
147
+ ) : (
148
+ <p className="text-sm">{message}</p>
149
+ )}
142
150
  <CostConnectionAction reason={reason}>
143
151
  {(reason === 'no_prometheus' || reason === 'no_cost_source' || reason === 'source_unavailable') && (
144
152
  <button
@@ -2,8 +2,26 @@ import { renderToStaticMarkup } from 'react-dom/server'
2
2
  import { MemoryRouter } from 'react-router-dom'
3
3
  import { describe, expect, it } from 'vitest'
4
4
  import { CostViewTabs } from './CostViewTabs'
5
+ import { NavCustomizationProvider } from '../../context/NavCustomization'
6
+ import { isRightsizingScanPath } from '../../utils/page-links'
5
7
 
6
8
  describe('CostViewTabs', () => {
9
+ it('opens the host rightsizing scan with the nested router scope without taking over cost allocation', () => {
10
+ const html = renderToStaticMarkup(
11
+ <MemoryRouter initialEntries={['/cost?namespaces=shop']}>
12
+ <NavCustomizationProvider value={{
13
+ fleetTakeoverHref: (target, search) => target === 'rightsizing' ? `/rightsizing${search}` : undefined,
14
+ }}>
15
+ <CostViewTabs />
16
+ </NavCustomizationProvider>
17
+ </MemoryRouter>,
18
+ )
19
+ expect(html).toContain('href="/rightsizing?namespaces=shop"')
20
+ expect(html).toContain('href="/cost?namespaces=shop"')
21
+ expect(isRightsizingScanPath('/cost/rightsizing/')).toBe(true)
22
+ expect(isRightsizingScanPath('/cost/rightsizing-other')).toBe(false)
23
+ })
24
+
7
25
  it('preserves namespace and rightsizing filters between cost views', () => {
8
26
  const html = renderToStaticMarkup(
9
27
  <MemoryRouter
@@ -1,40 +1,32 @@
1
- import { Link, useLocation, type To } from 'react-router-dom'
1
+ import { isRightsizingScanPath } from '../../utils/page-links'
2
+ import { Link, useLocation } from 'react-router-dom'
3
+ import { RightsizingScanLink } from '../rightsizing/RightsizingScanLink'
2
4
  import { clsx } from 'clsx'
3
5
 
4
6
  export function CostViewTabs() {
5
7
  const { pathname, search } = useLocation()
6
- const rightsizing = pathname.startsWith('/cost/rightsizing')
8
+ const rightsizing = isRightsizingScanPath(pathname)
7
9
  return (
8
10
  <div
9
11
  className="flex items-center gap-1 border-b border-theme-border"
10
12
  role="tablist"
11
13
  aria-label="Cost views"
12
14
  >
13
- <CostTab to={{ pathname: '/cost', search }} active={!rightsizing}>
15
+ <Link to={{ pathname: '/cost', search }} role="tab" aria-selected={!rightsizing} className={tabClass(!rightsizing)}>
14
16
  Overview
15
- </CostTab>
16
- <CostTab to={{ pathname: '/cost/rightsizing', search }} active={rightsizing}>
17
+ {!rightsizing && <span className="absolute inset-x-2 bottom-0 h-0.5 rounded-full bg-accent" />}
18
+ </Link>
19
+ <RightsizingScanLink role="tab" aria-selected={rightsizing} className={tabClass(rightsizing)}>
17
20
  Rightsizing
18
- </CostTab>
21
+ {rightsizing && <span className="absolute inset-x-2 bottom-0 h-0.5 rounded-full bg-accent" />}
22
+ </RightsizingScanLink>
19
23
  </div>
20
24
  )
21
25
  }
22
26
 
23
- function CostTab({ to, active, children }: { to: To; active: boolean; children: React.ReactNode }) {
24
- return (
25
- <Link
26
- to={to}
27
- role="tab"
28
- aria-selected={active}
29
- className={clsx(
30
- 'relative px-3 py-2 text-sm font-medium transition-colors',
31
- active
32
- ? 'text-theme-text-primary'
33
- : 'text-theme-text-tertiary hover:text-theme-text-secondary',
34
- )}
35
- >
36
- {children}
37
- {active && <span className="absolute inset-x-2 bottom-0 h-0.5 rounded-full bg-accent" />}
38
- </Link>
27
+ function tabClass(active: boolean) {
28
+ return clsx(
29
+ 'relative px-3 py-2 text-sm font-medium transition-colors',
30
+ active ? 'text-theme-text-primary' : 'text-theme-text-tertiary hover:text-theme-text-secondary',
39
31
  )
40
32
  }
@@ -211,3 +211,18 @@ describe('getWorkloadCostState', () => {
211
211
  expect(getWorkloadCostState(current, undefined, { trendLoading: true })).toBe('no_prometheus')
212
212
  })
213
213
  })
214
+
215
+ describe('getWorkloadCostState cluster scope', () => {
216
+ it.each(['cluster_scope', 'partial_data'] as const)('reports %s instead of no data', (reason) => {
217
+ const current: OpenCostWorkloadDetailResponse = {
218
+ available: false,
219
+ reason,
220
+ currency: 'USD',
221
+ namespace: 'shop',
222
+ kind: 'Deployment',
223
+ name: 'api',
224
+ clusterScope: { state: 'several_clusters', note: 'several' },
225
+ }
226
+ expect(getWorkloadCostState(current, undefined, false)).toBe(reason)
227
+ })
228
+ })
@@ -10,7 +10,7 @@ import {
10
10
  type OpenCostWorkloadTrendResponse,
11
11
  } from '../../api/client'
12
12
  import { Tooltip } from '../ui/Tooltip'
13
- import { CostTimeRangeSelector, StackedAreaChart } from './CostTrendChart'
13
+ import { CostTimeRangeSelector, CostTrendWithheldNote, StackedAreaChart } from './CostTrendChart'
14
14
  import {
15
15
  DEFAULT_COST_CURRENCY,
16
16
  formatCostPerHour,
@@ -25,10 +25,14 @@ import {
25
25
  costIntegrationUnavailableMessage,
26
26
  costRateLabels,
27
27
  costSourceLabel,
28
+ costTrendWithholding,
29
+ costWithheldScope,
28
30
  isCostDiscoveryPending,
29
31
  } from './source'
30
32
  import { useNavCustomization } from '../../context/NavCustomization'
33
+ import type { ClusterScope } from '@skyhook-io/k8s-ui/types/cluster-scope'
31
34
  import { CostConnectionAction } from './CostConnectionAction'
35
+ import { ClusterScopeNote } from '@skyhook-io/k8s-ui/components/ui/ClusterScopeNote'
32
36
 
33
37
  type WorkloadCostState =
34
38
  | 'loading'
@@ -103,6 +107,8 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
103
107
  state === 'deployment_configuration_error' ||
104
108
  state === 'metrics_settings_error' ||
105
109
  state === 'cost_settings_error' ||
110
+ state === 'cluster_scope' ||
111
+ state === 'partial_data' ||
106
112
  state === 'history_unsupported' ||
107
113
  state === 'load_error'
108
114
  ) {
@@ -119,7 +125,13 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
119
125
  />
120
126
  )
121
127
  }
122
- return <WorkloadCostUnavailable state={state} settingsAvailable={settingsAvailable} />
128
+ return (
129
+ <WorkloadCostUnavailable
130
+ state={state}
131
+ settingsAvailable={settingsAvailable}
132
+ withheld={costWithheldScope(currentQuery.data) ?? costWithheldScope(trendQuery.data)}
133
+ />
134
+ )
123
135
  }
124
136
 
125
137
  const current = currentQuery.data?.current
@@ -141,6 +153,9 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
141
153
  )
142
154
  const source = currentQuery.data?.source ?? trend?.source
143
155
  const historyUnsupported = trend?.reason === 'history_unsupported'
156
+ // Current costs stand while the trend was withheld: say why, rather than
157
+ // that the range has no history.
158
+ const trendWithholding = state === 'partial_missing_history' ? costTrendWithholding(trend) : undefined
144
159
  const currentWindow = currentQuery.data?.window
145
160
  const rateLabels = costRateLabels(currentWindow)
146
161
 
@@ -185,7 +200,11 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
185
200
  label={`Spend over ${range}`}
186
201
  value={windowSpendValue}
187
202
  subvalue={
188
- state === 'partial_missing_history' ? 'Historical data unavailable' : undefined
203
+ trendWithholding
204
+ ? 'Historical data withheld'
205
+ : state === 'partial_missing_history'
206
+ ? 'Historical data unavailable'
207
+ : undefined
189
208
  }
190
209
  />
191
210
  <MetricBlock
@@ -210,8 +229,12 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
210
229
  currency={trendCurrency}
211
230
  />
212
231
  ) : (
213
- <div className="flex h-[240px] items-center justify-center rounded-md border border-dashed border-theme-border bg-theme-base/60 text-sm text-theme-text-tertiary">
214
- No historical workload owner cost points for this range.
232
+ <div className="flex h-[240px] items-center justify-center rounded-md border border-dashed border-theme-border bg-theme-base/60 px-4 text-sm text-theme-text-tertiary">
233
+ {trendWithholding ? (
234
+ <CostTrendWithheldNote withholding={trendWithholding} />
235
+ ) : (
236
+ 'No historical workload owner cost points for this range.'
237
+ )}
215
238
  </div>
216
239
  )}
217
240
  </div>
@@ -219,7 +242,7 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
219
242
  )}
220
243
  </section>
221
244
 
222
- {state === 'partial_missing_history' && !historyUnsupported && (
245
+ {state === 'partial_missing_history' && !historyUnsupported && !trendWithholding && (
223
246
  <div className="flex items-start gap-2 rounded-lg border border-theme-border bg-theme-base px-3 py-2 text-sm text-theme-text-secondary">
224
247
  <AlertCircle className="mt-0.5 h-4 w-4 shrink-0 text-theme-text-tertiary" />
225
248
  <span>Current cost is available, but historical workload owner metrics are not available for this range.</span>
@@ -259,6 +282,9 @@ export function WorkloadCostTab({ kind, namespace, name }: WorkloadCostTabProps)
259
282
  memoryUsageAvailable={current?.memoryUsageAvailable ?? false}
260
283
  window={source === 'kubecost' ? currentWindow : undefined}
261
284
  />
285
+ {currentQuery.data?.efficiencyUnavailable && (
286
+ <ClusterScopeNote scope={currentQuery.data.usageClusterScope} title="Usage withheld for this cluster" />
287
+ )}
262
288
 
263
289
  <div className="text-xs text-theme-text-tertiary">
264
290
  {costSourceLabel(source)} &middot; {costFreshnessLabel(source, source === 'kubecost' ? currentWindow : '1h', currentQuery.data?.dataThrough)}.{' '}
@@ -315,7 +341,9 @@ export function getWorkloadCostState(
315
341
  reason === 'configuration_mismatch' ||
316
342
  reason === 'deployment_configuration_error' ||
317
343
  reason === 'metrics_settings_error' ||
318
- reason === 'cost_settings_error'
344
+ reason === 'cost_settings_error' ||
345
+ reason === 'cluster_scope' ||
346
+ reason === 'partial_data'
319
347
  )
320
348
  return reason
321
349
  if (queryError) return 'load_error'
@@ -359,9 +387,11 @@ function WorkloadCostDiscovering({
359
387
  function WorkloadCostUnavailable({
360
388
  state,
361
389
  settingsAvailable,
390
+ withheld,
362
391
  }: {
363
392
  state: CostUnavailableReason | 'load_error'
364
393
  settingsAvailable: boolean
394
+ withheld?: ClusterScope
365
395
  }) {
366
396
  const message =
367
397
  costIntegrationUnavailableMessage(state, settingsAvailable) ??
@@ -381,7 +411,11 @@ function WorkloadCostUnavailable({
381
411
  <div className="flex h-full min-h-[320px] items-center justify-center">
382
412
  <div className="flex max-w-md flex-col items-center gap-3 text-center text-theme-text-secondary">
383
413
  <Coins className="h-8 w-8 text-theme-text-tertiary/50" />
384
- <div className="text-sm">{message}</div>
414
+ {state === 'cluster_scope' && withheld ? (
415
+ <ClusterScopeNote scope={withheld} title="Costs withheld for this cluster" className="text-left" />
416
+ ) : (
417
+ <div className="text-sm">{message}</div>
418
+ )}
385
419
  <CostConnectionAction reason={state} />
386
420
  </div>
387
421
  </div>
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { COST_SOURCE_OPTIONS, costSourcePreferenceLabel, costConfigurationAction, isCostConfigurable, costDataThroughLabel, costFreshnessLabel, costIntegrationUnavailableMessage, costRateLabels, costSourceLabel, isCostDiscoveryPending } from './source'
2
+ import { COST_SOURCE_OPTIONS, costSourcePreferenceLabel, costConfigurationAction, isCostConfigurable, costDataThroughLabel, costFreshnessLabel, costIntegrationUnavailableMessage, costRateLabels, costSourceLabel, costWithheldScope, isCostDiscoveryPending } from './source'
3
3
 
4
4
  describe('cost source presentation', () => {
5
5
  it('routes missing sources to one applicable previous connection', () => {
@@ -73,3 +73,18 @@ it('gives connection guidance without claiming an unreachable source ran a query
73
73
  expect(embedded).toContain('Ask your operator')
74
74
  expect(embedded).not.toContain('Settings')
75
75
  })
76
+
77
+ describe('costWithheldScope', () => {
78
+ const several = { state: 'several_clusters' as const, note: 'several' }
79
+ it('returns the scope only for costs withheld by cluster scope', () => {
80
+ expect(costWithheldScope({ available: false, reason: 'cluster_scope', clusterScope: several })).toBe(several)
81
+ expect(costWithheldScope({ available: false, reason: 'cluster_scope' })).toBeUndefined()
82
+ expect(costWithheldScope({ available: false, reason: 'query_error', clusterScope: several })).toBeUndefined()
83
+ expect(costWithheldScope({ available: true, clusterScope: several })).toBeUndefined()
84
+ expect(costWithheldScope(undefined)).toBeUndefined()
85
+ })
86
+ it('explains withheld and partial costs', () => {
87
+ expect(costIntegrationUnavailableMessage('cluster_scope')).toContain('several clusters')
88
+ expect(costIntegrationUnavailableMessage('partial_data')).toContain('partially')
89
+ })
90
+ })