@skyhook-io/radar-app 1.21.2 → 1.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/package.json +2 -2
- package/src/App.tsx +50 -28
- package/src/api/actions.test.ts +11 -0
- package/src/api/actions.ts +5 -0
- package/src/api/apiResources.navigation.test.tsx +58 -0
- package/src/api/apiResources.ts +22 -16
- package/src/api/client.diagnostics.test.ts +52 -0
- package/src/api/client.triggerCronJob.test.tsx +49 -0
- package/src/api/client.ts +140 -120
- package/src/api/connectionBinding.test.tsx +82 -0
- package/src/api/connectionBinding.ts +52 -0
- package/src/api/contextSwitch.test.ts +11 -0
- package/src/api/contextSwitch.ts +58 -0
- package/src/api/radarFeatures.ts +5 -0
- package/src/components/ConnectionErrorView.tsx +13 -0
- package/src/components/ContextSwitchActions.tsx +43 -0
- package/src/components/ContextSwitcher.tsx +13 -6
- package/src/components/SwitchAwareConnectionError.tsx +2 -2
- package/src/components/cost/ApplicationCostTab.test.ts +16 -0
- package/src/components/cost/ApplicationCostTab.tsx +41 -9
- package/src/components/cost/CostTrendChart.tsx +25 -2
- package/src/components/cost/CostTrendWithheld.render.test.tsx +105 -0
- package/src/components/cost/CostView.tsx +10 -2
- package/src/components/cost/CostViewTabs.test.tsx +18 -0
- package/src/components/cost/CostViewTabs.tsx +14 -22
- package/src/components/cost/WorkloadCostTab.test.ts +15 -0
- package/src/components/cost/WorkloadCostTab.tsx +42 -8
- package/src/components/cost/source.test.ts +16 -1
- package/src/components/cost/source.ts +34 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +35 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +16 -1
- package/src/components/dock/NodeTerminalTab.test.tsx +4 -2
- package/src/components/dock/NodeTerminalTab.tsx +8 -8
- package/src/components/dock/TerminalTab.test.tsx +12 -1
- package/src/components/dock/TerminalTab.tsx +6 -3
- package/src/components/home/CostCard.test.tsx +49 -0
- package/src/components/home/CostCard.tsx +98 -63
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/resource/DatadogRightsizingPanel.test.tsx +118 -0
- package/src/components/resource/DatadogRightsizingPanel.tsx +68 -0
- package/src/components/resource/DatadogWorkloadCharts.tsx +149 -0
- package/src/components/resource/HPACharts.render.test.tsx +42 -0
- package/src/components/resource/HPACharts.tsx +34 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +126 -3
- package/src/components/resource/PrometheusChartsGrid.tsx +58 -25
- package/src/components/resource/RestartChart.render.test.tsx +72 -0
- package/src/components/resource/RestartChart.tsx +31 -3
- package/src/components/resource/RightsizingPanel.access.test.tsx +24 -0
- package/src/components/resource/RightsizingStrip.render.test.tsx +44 -0
- package/src/components/resource/RightsizingStrip.test.ts +1 -188
- package/src/components/resource/RightsizingStrip.tsx +27 -300
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +22 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -4
- package/src/components/resource/nameMatchedScope.ts +39 -0
- package/src/components/resources/pod-file-upload.ts +3 -0
- package/src/components/resources/renderers/CAPIClusterRenderer.tsx +5 -2
- package/src/components/resources/renderers/LonghornVolumeRenderer.test.tsx +104 -0
- package/src/components/resources/renderers/LonghornVolumeRenderer.tsx +31 -0
- package/src/components/rightsizing/RightsizingScanLink.tsx +22 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +65 -528
- package/src/components/rightsizing/model.test.ts +20 -9
- package/src/components/rightsizing/model.ts +17 -176
- package/src/components/rightsizing/notices.test.tsx +30 -29
- package/src/components/ui/DiagnosticsOverlay.test.ts +3 -2
- package/src/components/ui/DiagnosticsOverlay.tsx +23 -13
- package/src/components/ui/command-items.ts +3 -4
- package/src/components/useContextSwitchFlow.test.tsx +9 -0
- package/src/components/useContextSwitchFlow.tsx +43 -5
- package/src/components/workload/WorkloadRightsizingSource.test.tsx +83 -0
- package/src/components/workload/WorkloadView.test.ts +22 -1
- package/src/components/workload/WorkloadView.tsx +57 -16
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +58 -15
- package/src/context/ConnectionProvider.connectionId.test.tsx +92 -0
- package/src/context/ConnectionProvider.retry.test.tsx +174 -1
- package/src/context/ContextSwitchContext.tsx +15 -1
- package/src/context/NavCustomization.tsx +6 -3
- package/src/hooks/useEventSource.test.tsx +85 -0
- package/src/hooks/useEventSource.ts +43 -16
- package/src/hooks/useResetViewsOnContextChange.test.tsx +34 -0
- package/src/hooks/useResetViewsOnContextChange.ts +27 -0
- package/src/index.ts +3 -0
- package/src/integrations/resourceHosts.test.tsx +1 -1
- package/src/integrations/resourceHosts.tsx +2 -0
- package/src/utils/navigation.ts +1 -15
- package/src/utils/page-links.ts +6 -0
- package/src/components/rightsizing/presentation.test.ts +0 -150
- package/src/components/rightsizing/presentation.ts +0 -109
|
@@ -1,40 +1,32 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
-
<
|
|
15
|
+
<Link to={{ pathname: '/cost', search }} role="tab" aria-selected={!rightsizing} className={tabClass(!rightsizing)}>
|
|
14
16
|
Overview
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
|
24
|
-
return (
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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)} · {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
|
-
|
|
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
|
+
})
|
|
@@ -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
|
+
})
|