@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
@@ -1,13 +1,16 @@
1
1
  import { clsx } from "clsx";
2
- import { useMemo } from "react";
2
+ import { useMemo, type ReactNode } from "react";
3
3
  import { useSearchParams } from "react-router-dom";
4
4
  import { Loader2, Wifi, WifiOff } from "lucide-react";
5
5
  import { Disclosure } from "@skyhook-io/k8s-ui/components/ui/Disclosure";
6
+ import { ClusterScopeNote } from "@skyhook-io/k8s-ui/components/ui/ClusterScopeNote";
7
+ import { isClusterScopeWithheld } from "@skyhook-io/k8s-ui/types/cluster-scope";
6
8
  import {
7
9
  AreaChart,
8
10
  SeriesLegend,
9
11
  computeSaturation,
10
12
  describePodCoverage,
13
+ PARTIAL_DATA_NOTE,
11
14
  type ReferenceLine,
12
15
  } from "@skyhook-io/k8s-ui/components/charts";
13
16
  import {
@@ -36,6 +39,7 @@ import { Tooltip } from "../ui/Tooltip";
36
39
  import { WorkloadMetricsSection } from "./WorkloadMetricsSection";
37
40
  import { RightsizingStrip } from "./RightsizingStrip";
38
41
  import { useNavCustomization } from "../../context/NavCustomization";
42
+ import { leastCertainScope, NAME_MATCHED_CLUSTER_NOTE, NAME_MATCHED_SUMMARY } from "./nameMatchedScope";
39
43
  import { previousSettingsNote, usePreviousIntegrationSettings } from '../../hooks/usePreviousIntegrationSettings';
40
44
 
41
45
  // Used when MetricsTabContent is in expanded (full-screen) mode. Drawer mode
@@ -49,6 +53,8 @@ export interface PrometheusChartsGridProps {
49
53
  resource?: any;
50
54
  /** Fill and scroll its container (default). False lets the parent scroll it with content below. */
51
55
  fill?: boolean;
56
+ workloadTotals?: ReactNode;
57
+ showRightsizing?: boolean;
52
58
  }
53
59
 
54
60
  const SUPPORTED_KINDS = new Set([
@@ -68,6 +74,8 @@ export function PrometheusChartsGrid({
68
74
  name,
69
75
  resource,
70
76
  fill = true,
77
+ workloadTotals,
78
+ showRightsizing = true,
71
79
  }: PrometheusChartsGridProps) {
72
80
  useAutoPromConnect();
73
81
  const { data: status, isLoading: statusLoading } = usePrometheusStatus();
@@ -98,8 +106,42 @@ export function PrometheusChartsGrid({
98
106
  [resource, kind],
99
107
  );
100
108
 
109
+ // Read from the cache the network and storage charts fill; never fetches itself.
110
+ const rxScope = usePrometheusResourceMetrics(kind, namespace, name, "network_rx", timeRange, false).data?.clusterScope;
111
+ const txScope = usePrometheusResourceMetrics(kind, namespace, name, "network_tx", timeRange, false).data?.clusterScope;
112
+ const diskScope = usePrometheusResourceMetrics(kind, namespace, name, "filesystem", timeRange, false).data?.clusterScope;
113
+ const nameMatchedScope = leastCertainScope(categories.some((c) => c.key === "filesystem") ? [rxScope, txScope, diskScope] : [rxScope, txScope]);
114
+ const nameMatchedNote = NAME_MATCHED_CLUSTER_NOTE[nameMatchedScope];
115
+
101
116
  if (!isSupported) return null;
102
117
 
118
+ const rangeControl = <select
119
+ aria-label="Metrics time range"
120
+ value={timeRange}
121
+ onChange={(e) => {
122
+ const next = new URLSearchParams(searchParams);
123
+ next.set("metricsRange", e.target.value);
124
+ setSearchParams(next, { replace: true });
125
+ }}
126
+ className="ml-auto rounded-md border border-theme-border bg-theme-elevated px-2 py-1 text-xs text-theme-text-secondary shadow-theme-sm focus:outline-none focus:ring-1 focus:ring-accent/50"
127
+ >
128
+ {TIME_RANGES.map((tr) => (
129
+ <option key={tr.value} value={tr.value}>
130
+ {tr.label}
131
+ </option>
132
+ ))}
133
+ </select>;
134
+
135
+ if (workloadTotals && !isConnected) {
136
+ return (
137
+ <div className={clsx("space-y-4 p-4", fill && "h-full overflow-auto")}>
138
+ <div className="flex">{rangeControl}</div>
139
+ {workloadTotals}
140
+ <RestartEventLane kind={kind} namespace={namespace} name={name} range={timeRange} />
141
+ </div>
142
+ );
143
+ }
144
+
103
145
  if (statusLoading) {
104
146
  return (
105
147
  <div className="flex items-center justify-center py-12 text-theme-text-tertiary">
@@ -178,30 +220,13 @@ export function PrometheusChartsGrid({
178
220
  <MetricsPanel key={def.key} category={def} kind={kind} namespace={namespace} name={name} timeRange={timeRange} referenceLines={refLines} />
179
221
  );
180
222
 
181
- const rangeControl = <select
182
- aria-label="Metrics time range"
183
- value={timeRange}
184
- onChange={(e) => {
185
- const next = new URLSearchParams(searchParams);
186
- next.set("metricsRange", e.target.value);
187
- setSearchParams(next, { replace: true });
188
- }}
189
- className="ml-auto rounded-md border border-theme-border bg-theme-elevated px-2 py-1 text-xs text-theme-text-secondary shadow-theme-sm focus:outline-none focus:ring-1 focus:ring-accent/50"
190
- >
191
- {TIME_RANGES.map((tr) => (
192
- <option key={tr.value} value={tr.value}>
193
- {tr.label}
194
- </option>
195
- ))}
196
- </select>;
197
-
198
223
  return (
199
224
  <div className={clsx("flex flex-col min-w-0 w-full", fill && "h-full overflow-auto")}>
200
225
  {!isWorkload && <div className="flex shrink-0 items-center justify-between gap-3 px-4 pt-3">{rangeControl}</div>}
201
226
 
202
227
  {isWorkload && (
203
228
  <WorkloadMetricsSection key={`${kind}/${namespace}/${name}`} kind={kind} namespace={namespace} name={name} range={timeRange}
204
- controls={rangeControl}
229
+ controls={rangeControl} workloadTotals={workloadTotals}
205
230
  cpuReferenceLines={cpuRefLines} memoryReferenceLines={memRefLines}
206
231
  nameMatchedCharts={{ cpu: cpu && renderPanel({ def: cpu }), memory: mem && renderPanel({ def: mem }) }}
207
232
  restartLane={showRestartLane && <div className="mb-3"><RestartEventLane kind={kind} namespace={namespace} name={name} range={timeRange} /></div>} />
@@ -222,8 +247,8 @@ export function PrometheusChartsGrid({
222
247
 
223
248
  <div className="metrics-layout min-w-0 px-4 pt-4">
224
249
  {isWorkload && <h3 className="mb-2 text-sm font-semibold text-theme-text-primary">Network and storage</h3>}
225
- {isWorkload && <Disclosure className="mb-2 text-xs text-theme-text-secondary" summary="Pod-name matched · identity unverified">
226
- <p className="mt-2 max-w-2xl text-sm leading-relaxed">These charts match current Pod names, independently of the identity-checked charts above. Matching names in a shared backend may include another cluster.</p>
250
+ {isWorkload && <Disclosure className="mb-2 text-xs text-theme-text-secondary" summary={`Pod-name matched · ${NAME_MATCHED_SUMMARY[nameMatchedScope]}`}>
251
+ <p className="mt-2 max-w-2xl text-sm leading-relaxed">These charts match current Pod names, independently of the identity-checked charts above. {nameMatchedNote ?? "Matching names in a shared backend may include another cluster."}</p>
227
252
  </Disclosure>}
228
253
  <div className="metrics-chart-grid">
229
254
  {chartPanels.filter(({ def }) => !isWorkload || (def.key !== "cpu" && def.key !== "memory")).map(renderPanel)}
@@ -237,7 +262,7 @@ export function PrometheusChartsGrid({
237
262
  timeRange={timeRange}
238
263
  category={isWorkload ? "network_rx" : "cpu"}
239
264
  />
240
- {["Deployment", "StatefulSet", "DaemonSet"].includes(kind) && (
265
+ {showRightsizing && isWorkload && (
241
266
  <div className="px-4 pb-4"><RightsizingStrip kind={kind} namespace={namespace} name={name} /></div>
242
267
  )}
243
268
  </div>
@@ -334,6 +359,8 @@ function MetricsPanel({
334
359
  <PanelLoading />
335
360
  ) : error ? (
336
361
  <PanelError message={(error as Error).message} />
362
+ ) : isClusterScopeWithheld(metrics?.clusterScope) ? (
363
+ <ClusterScopeNote scope={metrics?.clusterScope} />
337
364
  ) : hasData && series ? (
338
365
  <>
339
366
  <AreaChart
@@ -349,9 +376,12 @@ function MetricsPanel({
349
376
  <SeriesLegend series={series} color={category.chartColor} />
350
377
  </div>
351
378
  )}
379
+ {metrics?.partial && (
380
+ <p className="mt-1.5 text-xs text-theme-text-tertiary">{PARTIAL_DATA_NOTE}</p>
381
+ )}
352
382
  </>
353
383
  ) : (
354
- <PanelNoData hint={metrics?.hint} />
384
+ <PanelNoData hint={metrics?.hint} partial={metrics?.partial} />
355
385
  )}
356
386
  </div>
357
387
  </section>
@@ -406,10 +436,13 @@ function PanelError({ message }: { message: string }) {
406
436
  );
407
437
  }
408
438
 
409
- function PanelNoData({ hint }: { hint?: string }) {
439
+ function PanelNoData({ hint, partial }: { hint?: string; partial?: boolean }) {
410
440
  return (
411
441
  <div className="flex flex-col items-center justify-center h-[240px] text-theme-text-tertiary text-xs px-3 text-center">
412
- No data
442
+ {partial ? "No samples in a partial answer" : "No data"}
443
+ {partial && (
444
+ <span className="text-theme-text-quaternary mt-1 max-w-xs">{PARTIAL_DATA_NOTE}</span>
445
+ )}
413
446
  {hint && (
414
447
  <span className="text-theme-text-quaternary mt-1 max-w-xs">{hint}</span>
415
448
  )}
@@ -0,0 +1,72 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+ import { renderToString } from 'react-dom/server'
3
+ import { PARTIAL_DATA_NOTE } from '@skyhook-io/k8s-ui/components/charts'
4
+
5
+ let metricsResult: { data?: unknown; isLoading?: boolean; error?: unknown } = {}
6
+
7
+ vi.mock('../../api/client', async (importActual) => ({
8
+ ...(await importActual<typeof import('../../api/client')>()),
9
+ usePrometheusResourceMetrics: () => metricsResult,
10
+ usePrometheusStatus: () => ({ data: { connected: true } }),
11
+ }))
12
+
13
+ const { RestartEventLane } = await import('./RestartChart')
14
+
15
+ const empty = { resultType: 'matrix', series: [] }
16
+
17
+ /**
18
+ * The lane is also shown on its own (the workload view), so a withheld answer
19
+ * must say why rather than vanish like a pod that never restarted.
20
+ */
21
+ describe('RestartEventLane — cluster scope', () => {
22
+ it('says why the restart history is withheld instead of hiding', () => {
23
+ metricsResult = { data: { result: empty, clusterScope: { state: 'several_clusters', note: 'This store holds several clusters.' } } }
24
+ const html = renderToString(<RestartEventLane kind="Deployment" namespace="shop" name="api" />)
25
+ expect(html).toContain('data-cluster-scope="several_clusters"')
26
+ expect(html).toContain('Restart history withheld for this cluster')
27
+ expect(html).toContain('This store holds several clusters.')
28
+ })
29
+
30
+ it('stays hidden when a scoped answer has no restarts', () => {
31
+ metricsResult = { data: { result: empty, clusterScope: { state: 'scoped_verified', note: 'Matched.' } } }
32
+ expect(renderToString(<RestartEventLane kind="Deployment" namespace="shop" name="api" />)).toBe('')
33
+ })
34
+
35
+ it('stays hidden when an older Radar sends no clusterScope', () => {
36
+ metricsResult = { data: { result: empty } }
37
+ expect(renderToString(<RestartEventLane kind="Deployment" namespace="shop" name="api" />)).toBe('')
38
+ })
39
+ })
40
+
41
+ const restartSeries = (values: number[]) => ({
42
+ resultType: 'matrix',
43
+ series: [{ labels: { pod: 'api-1' }, dataPoints: values.map((value, i) => ({ timestamp: Date.now() / 1000 - 600 + i * 60, value })) }],
44
+ })
45
+
46
+ /**
47
+ * A partial answer may be missing restarts: an empty one must not read as a
48
+ * pod that never restarted, and a count from one is only a lower bound.
49
+ */
50
+ describe('RestartEventLane — partial answers', () => {
51
+ it('notes an empty partial answer instead of hiding', () => {
52
+ metricsResult = { data: { result: empty, partial: true } }
53
+ const html = renderToString(<RestartEventLane kind="Deployment" namespace="shop" name="api" />)
54
+ expect(html).toContain('No restarts seen in a partial answer')
55
+ expect(html).toContain(PARTIAL_DATA_NOTE)
56
+ })
57
+
58
+ it('qualifies the total of a partial answer as a lower bound', () => {
59
+ metricsResult = { data: { result: restartSeries([0, 1, 1, 3]), partial: true } }
60
+ const html = renderToString(<RestartEventLane kind="Deployment" namespace="shop" name="api" />)
61
+ expect(html).toContain('at least <!-- -->3<!-- --> total')
62
+ expect(html).toContain(PARTIAL_DATA_NOTE)
63
+ })
64
+
65
+ it('shows an exact total for a complete answer', () => {
66
+ metricsResult = { data: { result: restartSeries([0, 1, 1, 3]) } }
67
+ const html = renderToString(<RestartEventLane kind="Deployment" namespace="shop" name="api" />)
68
+ expect(html).toContain('3<!-- --> total')
69
+ expect(html).not.toContain('at least')
70
+ expect(html).not.toContain(PARTIAL_DATA_NOTE)
71
+ })
72
+ })
@@ -1,13 +1,18 @@
1
1
  import { useEffect, useMemo } from 'react'
2
2
  import { AlertCircle } from 'lucide-react'
3
3
  import { usePrometheusResourceMetrics, usePrometheusStatus, type PrometheusSeries, type PrometheusTimeRange } from '../../api/client'
4
+ import { PARTIAL_DATA_NOTE } from '@skyhook-io/k8s-ui/components/charts'
5
+ import { ClusterScopeNote } from '@skyhook-io/k8s-ui/components/ui/ClusterScopeNote'
6
+ import { isClusterScopeWithheld } from '@skyhook-io/k8s-ui/types/cluster-scope'
4
7
  import { Tooltip } from '../ui/Tooltip'
5
8
 
6
9
  /**
7
10
  * RestartEventLane — vertical markers at each restart event, on a dedicated
8
11
  * row below the chart. Markers stay readable when they cluster because they
9
12
  * don't overlay the chart waveform. KSM-gated (uses kube_pod_container_status_restarts_total)
10
- * — silently hidden when Prom isn't connected or the series doesn't exist.
13
+ * — silently hidden when Prom isn't connected or the series doesn't exist,
14
+ * but says why when the metrics store couldn't be kept to this cluster, and
15
+ * notes an answer the store gave only in part.
11
16
  */
12
17
  export function RestartEventLane({ kind, namespace, name, range = '1h' }: {
13
18
  kind: string
@@ -32,7 +37,27 @@ export function RestartEventLane({ kind, namespace, name, range = '1h' }: {
32
37
  }, [error])
33
38
 
34
39
  if (!isConnected || isLoading) return null
35
- if (restarts.length === 0) return null
40
+ // A withheld answer has no series; hiding the lane would read as "no restarts".
41
+ if (isClusterScopeWithheld(metrics?.clusterScope)) {
42
+ return <ClusterScopeNote scope={metrics?.clusterScope} title="Restart history withheld for this cluster" />
43
+ }
44
+ // A partial answer may be missing restarts: an empty one is not "no
45
+ // restarts", and its count is only a lower bound.
46
+ const partial = metrics?.partial === true
47
+ if (restarts.length === 0) {
48
+ if (!partial) return null
49
+ return (
50
+ <div className="rounded-md border border-theme-border bg-theme-surface/30 px-3 py-2">
51
+ <div className="flex items-center gap-2 mb-1">
52
+ <AlertCircle className="w-3.5 h-3.5 text-theme-text-tertiary" />
53
+ <span className="text-xs font-medium text-theme-text-secondary">
54
+ No restarts seen in a partial answer
55
+ </span>
56
+ </div>
57
+ <p className="text-xs text-theme-text-tertiary">{PARTIAL_DATA_NOTE}</p>
58
+ </div>
59
+ )
60
+ }
36
61
 
37
62
  // Position markers within the chart's full time window — not the
38
63
  // min/max of detected events — so a cluster of restarts at the start
@@ -49,7 +74,7 @@ export function RestartEventLane({ kind, namespace, name, range = '1h' }: {
49
74
  Restarts in last {range}
50
75
  </span>
51
76
  <span className="text-xs text-theme-text-quaternary tabular-nums">
52
- {restarts.reduce((n, r) => n + r.value, 0)} total
77
+ {partial ? 'at least ' : ''}{restarts.reduce((n, r) => n + r.value, 0)} total
53
78
  </span>
54
79
  </div>
55
80
  <div className="relative h-5">
@@ -70,6 +95,9 @@ export function RestartEventLane({ kind, namespace, name, range = '1h' }: {
70
95
  )
71
96
  })}
72
97
  </div>
98
+ {partial && (
99
+ <p className="mt-1.5 text-xs text-theme-text-tertiary">{PARTIAL_DATA_NOTE}</p>
100
+ )}
73
101
  </div>
74
102
  )
75
103
  }
@@ -0,0 +1,24 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { MemoryRouter } from 'react-router-dom'
3
+ import { expect, it, vi } from 'vitest'
4
+ import { RightsizingPanel } from './RightsizingStrip'
5
+
6
+ vi.mock('../../api/client', () => ({
7
+ useAutoPromConnect: () => {},
8
+ usePrometheusStatus: () => ({ data: { connected: true } }),
9
+ usePrometheusRightsizing: () => ({
10
+ error: new Error('Access denied'),
11
+ data: { window: '7d', ownerCoverage: 'ksm_history', rows: [], reason: 'Previous scan evidence' },
12
+ }),
13
+ }))
14
+
15
+ it('hides previous evidence after the workload read is denied', () => {
16
+ const html = renderToStaticMarkup(
17
+ <MemoryRouter>
18
+ <RightsizingPanel kind="Deployment" namespace="shop" name="api" />
19
+ </MemoryRouter>,
20
+ )
21
+ expect(html).toContain('Access denied')
22
+ expect(html).not.toContain('Previous scan evidence')
23
+ expect(html).not.toContain('retained ownership')
24
+ })
@@ -0,0 +1,44 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it } from 'vitest'
3
+ import type { PrometheusRightsizing } from '../../api/client'
4
+ import { RightsizingBody } from './RightsizingStrip'
5
+
6
+ const withheld: PrometheusRightsizing = {
7
+ kind: 'Deployment',
8
+ namespace: 'payments',
9
+ name: 'api',
10
+ window: '7d',
11
+ source: 'radar',
12
+ ownerCoverage: 'ksm_history',
13
+ replicas: 2,
14
+ scaledToZero: false,
15
+ sampleAvailable: false,
16
+ rows: [],
17
+ reason: 'Radar withheld recommendations.',
18
+ clusterScope: { state: 'several_clusters', note: 'This metrics store holds several clusters.' },
19
+ }
20
+
21
+ function render(data: PrometheusRightsizing, compact = true) {
22
+ return renderToStaticMarkup(
23
+ <RightsizingBody state={{ statusLoading: false, connected: true, isLoading: false, error: null, data }} compact={compact} />,
24
+ )
25
+ }
26
+
27
+ describe('RightsizingBody cluster scope', () => {
28
+ it('shows the cluster scope note instead of recommendations when withheld', () => {
29
+ for (const compact of [true, false]) {
30
+ const html = render(withheld, compact)
31
+ expect(html).toContain('This metrics store holds several clusters.')
32
+ expect(html).toContain('Recommendations withheld')
33
+ expect(html).not.toContain('Radar withheld recommendations.')
34
+ }
35
+ })
36
+
37
+ it('keeps the plain reason when the scope is not withheld or absent', () => {
38
+ for (const clusterScope of [undefined, { state: 'unlabeled' as const, note: 'unverified' }]) {
39
+ const html = render({ ...withheld, reason: 'No workload usage samples are available in the last 7d.', clusterScope })
40
+ expect(html).toContain('No workload usage samples')
41
+ expect(html).not.toContain('role="note"')
42
+ }
43
+ })
44
+ })
@@ -1,104 +1,11 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import type { RightsizingRow } from '../../api/client'
3
2
  import {
4
- getRightsizingExplanation,
5
- getRightsizingPresentation,
6
- podLevelOverUseNote,
7
3
  RIGHTSIZING_METHODOLOGY,
8
4
  RIGHTSIZING_DOCS_URL,
9
5
  RIGHTSIZING_SUMMARY,
10
6
  } from './RightsizingStrip'
11
7
 
12
- const row = (overrides: Partial<RightsizingRow> = {}): RightsizingRow => ({
13
- container: 'server',
14
- resource: 'cpu',
15
- fit: 'balanced',
16
- confidence: 'high',
17
- sampleCount: 2016,
18
- expectedSamples: 2016,
19
- coverage: 1,
20
- hpaManaged: false,
21
- hpaEvidenceAvailable: true,
22
- oomEvidenceAvailable: true,
23
- throttleAvailable: true,
24
- ...overrides,
25
- })
26
-
27
- describe('rightsizing presentation', () => {
28
- it('keeps fit, confidence, and runtime risk as separate concepts', () => {
29
- expect(getRightsizingPresentation('oversized')).toEqual({
30
- label: 'Oversized',
31
- severity: 'info',
32
- })
33
- expect(getRightsizingPresentation('under_requested')).toEqual({
34
- label: 'Under-requested',
35
- severity: 'warning',
36
- })
37
- expect(getRightsizingPresentation('insufficient_history')).toEqual({
38
- label: 'Insufficient history',
39
- severity: 'neutral',
40
- })
41
- })
42
-
43
- it('labels query failures independently from insufficient history', () => {
44
- expect(getRightsizingPresentation('insufficient_history', 'usage query failed')).toEqual({
45
- label: 'Query failed',
46
- severity: 'error',
47
- })
48
- })
49
-
50
- it('explains why recommendations are withheld without inventing a zero-risk result', () => {
51
- expect(getRightsizingExplanation(row({ recommendationReason: 'hpa_managed' }))).toContain(
52
- 'HPA manages cpu',
53
- )
54
- expect(
55
- getRightsizingExplanation(row({ resource: 'memory', recommendationReason: 'oom_evidence' })),
56
- ).toContain('OOM evidence')
57
- expect(
58
- getRightsizingExplanation(row({ recommendationReason: 'hpa_evidence_unavailable' })),
59
- ).toContain('could not verify HPA')
60
- expect(
61
- getRightsizingExplanation(
62
- row({
63
- resource: 'memory',
64
- recommendationReason: 'oom_evidence_unavailable',
65
- }),
66
- ),
67
- ).toContain('could not verify recent OOM')
68
- expect(getRightsizingExplanation(row({ throttleAvailable: false }))).toContain(
69
- 'throttling metrics are unavailable',
70
- )
71
- })
72
-
73
- it('separates the demand target from a conservative reduction step', () => {
74
- const explanation = getRightsizingExplanation(
75
- row({
76
- fit: 'oversized',
77
- currentRequest: '1',
78
- recommendedRequest: '500m',
79
- calculatedRequest: '10m',
80
- reductionLimited: true,
81
- bursty: true,
82
- peak: { name: 'P99', value: 0.2, formatted: '200m' },
83
- }),
84
- )
85
- expect(explanation).toContain('Demand-based target: 10m')
86
- expect(explanation).toContain('conservative next step')
87
- expect(explanation).toContain('CPU P99 reached 200m')
88
- })
89
-
90
- it('does not revive the misleading efficiency vocabulary', () => {
91
- const copy = [
92
- getRightsizingPresentation('balanced').label,
93
- getRightsizingPresentation('oversized').label,
94
- getRightsizingExplanation(row({ recommendationReason: 'request_within_fit_range' })),
95
- ]
96
- .join(' ')
97
- .toLowerCase()
98
- expect(copy).not.toContain('efficien')
99
- expect(copy).not.toContain('waste')
100
- })
101
-
8
+ describe('Prometheus rightsizing', () => {
102
9
  it('sets the workload-level scope and methodology without promising savings or changes', () => {
103
10
  expect(RIGHTSIZING_SUMMARY).toContain('this workload')
104
11
  expect(RIGHTSIZING_SUMMARY).toContain('not a savings estimate or automatic change')
@@ -108,97 +15,3 @@ describe('rightsizing presentation', () => {
108
15
  expect(RIGHTSIZING_DOCS_URL).toContain('/features/rightsizing')
109
16
  })
110
17
  })
111
-
112
- describe('live pod inventory', () => {
113
- it('qualifies a memory row when the pod list could not be read', () => {
114
- const explanation = getRightsizingExplanation(
115
- row({ resource: 'memory', liveInventoryUnavailable: true }),
116
- )
117
- expect(explanation).toContain('could not read')
118
- expect(explanation).toContain('out-of-memory restarts')
119
- })
120
-
121
- it('adds the caveat to a suppression reason instead of replacing it', () => {
122
- const explanation = getRightsizingExplanation(
123
- row({ resource: 'memory', recommendationReason: 'oom_evidence', liveInventoryUnavailable: true }),
124
- )
125
- expect(explanation).toContain('OOM evidence exists')
126
- expect(explanation).toContain('could not read')
127
- })
128
-
129
- it('keeps the caveat on a staged reduction, where an unchecked pod matters most', () => {
130
- const explanation = getRightsizingExplanation(
131
- row({
132
- resource: 'memory',
133
- liveInventoryUnavailable: true,
134
- reductionLimited: true,
135
- calculatedRequest: '256Mi',
136
- recommendedRequest: '384Mi',
137
- }),
138
- )
139
- expect(explanation).toContain('conservative next step')
140
- expect(explanation).toContain('could not read')
141
- })
142
-
143
- it('says nothing when the pods were read', () => {
144
- expect(getRightsizingExplanation(row({ resource: 'memory' })) ?? '').not.toContain(
145
- 'could not read',
146
- )
147
- })
148
- })
149
-
150
- describe('pod-level request rows', () => {
151
- it('explains the pod-level value instead of promising a per-container verdict', () => {
152
- const message = getRightsizingExplanation(
153
- row({
154
- fit: 'pod_level_request',
155
- recommendationReason: 'pod_level_request',
156
- podLevelRequest: '128Mi',
157
- resource: 'memory',
158
- }),
159
- )
160
- expect(message).toContain('128Mi')
161
- })
162
-
163
- it('labels a fit this frontend does not know instead of rendering nothing', () => {
164
- const unknownFit = 'future_fit' as unknown as Parameters<typeof getRightsizingPresentation>[0]
165
- expect(getRightsizingPresentation(unknownFit).label).toBe('future_fit')
166
- })
167
- })
168
-
169
- describe('pod-level request below one container\'s usage', () => {
170
- const podLevel = (observed: number, formatted: string) =>
171
- row({
172
- fit: 'pod_level_request',
173
- recommendationReason: 'pod_level_request',
174
- podLevelRequest: '200m',
175
- podLevelRequestValue: 0.2,
176
- observed: { name: 'P95', value: observed, formatted },
177
- })
178
-
179
- it('names the overuse when one container alone used more than the pod request', () => {
180
- const message = getRightsizingExplanation(podLevel(0.44, '440m'))
181
- expect(message).toContain('440m')
182
- expect(podLevelOverUseNote(podLevel(0.44, '440m'))).toBe(message)
183
- })
184
-
185
- it('says nothing about overuse when the container stayed under the pod request', () => {
186
- expect(podLevelOverUseNote(podLevel(0.15, '150m'))).toBeUndefined()
187
- })
188
-
189
- it('does not ask to raise the request when an HPA scales on it', () => {
190
- const note = podLevelOverUseNote({ ...podLevel(0.44, '440m'), hpaManaged: true })
191
- expect(note).toContain('440m')
192
- expect(note).toContain('HPA')
193
- })
194
-
195
- it('asks for an autoscaling check when Radar could not read HPAs', () => {
196
- const note = podLevelOverUseNote({ ...podLevel(0.44, '440m'), hpaEvidenceAvailable: false })
197
- expect(note).toContain('440m')
198
- expect(note).toContain('HPA')
199
- })
200
-
201
- it('stays quiet before six hours of samples', () => {
202
- expect(podLevelOverUseNote({ ...podLevel(0.44, '440m'), sampleCount: 1, coverage: 0 })).toBeUndefined()
203
- })
204
- })