@skyhook-io/radar-app 1.21.2 → 1.21.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/package.json +2 -2
- package/src/App.tsx +53 -28
- package/src/api/actions.test.ts +11 -0
- package/src/api/actions.ts +5 -0
- package/src/api/apiResources.navigation.test.tsx +58 -0
- package/src/api/apiResources.ts +22 -16
- package/src/api/client.diagnostics.test.ts +52 -0
- package/src/api/client.triggerCronJob.test.tsx +49 -0
- package/src/api/client.ts +140 -120
- package/src/api/connectionBinding.test.tsx +82 -0
- package/src/api/connectionBinding.ts +52 -0
- package/src/api/contextSwitch.test.ts +11 -0
- package/src/api/contextSwitch.ts +58 -0
- package/src/api/radarFeatures.ts +6 -0
- package/src/api/vulnerabilities.export.test.ts +44 -0
- package/src/api/vulnerabilities.ts +73 -4
- package/src/components/ConnectionErrorView.tsx +13 -0
- package/src/components/ContextSwitchActions.tsx +43 -0
- package/src/components/ContextSwitcher.tsx +13 -6
- package/src/components/SwitchAwareConnectionError.tsx +2 -2
- package/src/components/audit/VulnerabilitiesView.test.tsx +177 -0
- package/src/components/audit/VulnerabilitiesView.tsx +197 -48
- package/src/components/cost/ApplicationCostTab.test.ts +16 -0
- package/src/components/cost/ApplicationCostTab.tsx +41 -9
- package/src/components/cost/CostTrendChart.tsx +25 -2
- package/src/components/cost/CostTrendWithheld.render.test.tsx +105 -0
- package/src/components/cost/CostView.tsx +10 -2
- package/src/components/cost/CostViewTabs.test.tsx +18 -0
- package/src/components/cost/CostViewTabs.tsx +14 -22
- package/src/components/cost/WorkloadCostTab.test.ts +15 -0
- package/src/components/cost/WorkloadCostTab.tsx +42 -8
- package/src/components/cost/source.test.ts +16 -1
- package/src/components/cost/source.ts +34 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +35 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +16 -1
- package/src/components/dock/NodeTerminalTab.test.tsx +4 -2
- package/src/components/dock/NodeTerminalTab.tsx +8 -8
- package/src/components/dock/TerminalTab.test.tsx +12 -1
- package/src/components/dock/TerminalTab.tsx +6 -3
- package/src/components/home/CostCard.test.tsx +49 -0
- package/src/components/home/CostCard.tsx +98 -63
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/resource/DatadogRightsizingPanel.test.tsx +118 -0
- package/src/components/resource/DatadogRightsizingPanel.tsx +68 -0
- package/src/components/resource/DatadogWorkloadCharts.tsx +149 -0
- package/src/components/resource/HPACharts.render.test.tsx +42 -0
- package/src/components/resource/HPACharts.tsx +34 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +126 -3
- package/src/components/resource/PrometheusChartsGrid.tsx +58 -25
- package/src/components/resource/RestartChart.render.test.tsx +72 -0
- package/src/components/resource/RestartChart.tsx +31 -3
- package/src/components/resource/RightsizingPanel.access.test.tsx +24 -0
- package/src/components/resource/RightsizingStrip.render.test.tsx +44 -0
- package/src/components/resource/RightsizingStrip.test.ts +1 -188
- package/src/components/resource/RightsizingStrip.tsx +27 -300
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +22 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -4
- package/src/components/resource/nameMatchedScope.ts +39 -0
- package/src/components/resources/pod-file-upload.ts +3 -0
- package/src/components/resources/renderers/CAPIClusterRenderer.tsx +5 -2
- package/src/components/resources/renderers/LonghornVolumeRenderer.test.tsx +104 -0
- package/src/components/resources/renderers/LonghornVolumeRenderer.tsx +31 -0
- package/src/components/rightsizing/RightsizingScanLink.tsx +22 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +65 -528
- package/src/components/rightsizing/model.test.ts +20 -9
- package/src/components/rightsizing/model.ts +17 -176
- package/src/components/rightsizing/notices.test.tsx +30 -29
- package/src/components/traffic/TrafficGraph.export.test.tsx +57 -0
- package/src/components/traffic/TrafficGraph.tsx +9 -4
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +1 -0
- package/src/components/traffic/TrafficView.tsx +17 -2
- package/src/components/ui/DiagnosticsOverlay.test.ts +3 -2
- package/src/components/ui/DiagnosticsOverlay.tsx +23 -13
- package/src/components/ui/command-items.ts +3 -4
- package/src/components/useContextSwitchFlow.test.tsx +9 -0
- package/src/components/useContextSwitchFlow.tsx +43 -5
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.test.tsx +30 -1
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +3 -2
- package/src/components/vulnerabilities/parts.test.ts +59 -3
- package/src/components/vulnerabilities/parts.tsx +199 -5
- package/src/components/workload/WorkloadRightsizingSource.test.tsx +83 -0
- package/src/components/workload/WorkloadView.test.ts +22 -1
- package/src/components/workload/WorkloadView.tsx +57 -16
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +58 -15
- package/src/context/ConnectionProvider.connectionId.test.tsx +92 -0
- package/src/context/ConnectionProvider.retry.test.tsx +174 -1
- package/src/context/ContextSwitchContext.tsx +15 -1
- package/src/context/NavCustomization.tsx +6 -3
- package/src/hooks/useDesktopDownload.test.tsx +57 -0
- package/src/hooks/useDesktopDownload.ts +31 -9
- package/src/hooks/useEventSource.test.tsx +85 -0
- package/src/hooks/useEventSource.ts +43 -16
- package/src/hooks/useResetViewsOnContextChange.test.tsx +34 -0
- package/src/hooks/useResetViewsOnContextChange.ts +27 -0
- package/src/index.ts +3 -0
- package/src/integrations/resourceHosts.test.tsx +1 -1
- package/src/integrations/resourceHosts.tsx +2 -0
- package/src/utils/navigation.ts +1 -15
- package/src/utils/page-links.ts +6 -0
- package/src/components/rightsizing/presentation.test.ts +0 -150
- package/src/components/rightsizing/presentation.ts +0 -109
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { DatadogRightsizingEvidence } from '@skyhook-io/k8s-ui/components/rightsizing/DatadogRightsizingEvidence'
|
|
3
|
+
import type { DatadogSizingDetail } from '@skyhook-io/k8s-ui/types/rightsizing'
|
|
4
|
+
import { fetchJSON, useRadarFeature } from '../../api/client'
|
|
5
|
+
import { getApiBase } from '../../api/config'
|
|
6
|
+
|
|
7
|
+
export function DatadogRightsizingPanel({
|
|
8
|
+
kind,
|
|
9
|
+
namespace,
|
|
10
|
+
name,
|
|
11
|
+
}: {
|
|
12
|
+
kind: string
|
|
13
|
+
namespace: string
|
|
14
|
+
name: string
|
|
15
|
+
}) {
|
|
16
|
+
const { support, blockedReason } = useRadarFeature('datadogRightsizing')
|
|
17
|
+
const path =
|
|
18
|
+
'/metrics/datadog/rightsizing/' + [kind, namespace, name].map(encodeURIComponent).join('/')
|
|
19
|
+
const queryKey = ['datadog-rightsizing', getApiBase(), path]
|
|
20
|
+
const query = useQuery({
|
|
21
|
+
queryKey,
|
|
22
|
+
enabled: support === 'supported',
|
|
23
|
+
queryFn: ({ signal }) => fetchJSON<DatadogSizingDetail>(path, signal),
|
|
24
|
+
staleTime: 2 * 60_000,
|
|
25
|
+
refetchOnWindowFocus: false,
|
|
26
|
+
retry: false,
|
|
27
|
+
})
|
|
28
|
+
if (support === 'unsupported') {
|
|
29
|
+
return (
|
|
30
|
+
<p className="mt-4 text-sm text-theme-text-secondary">
|
|
31
|
+
Upgrade this cluster’s Radar agent to see Datadog rightsizing.
|
|
32
|
+
</p>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
if (support === 'unknown') {
|
|
36
|
+
return <p role="status" className="mt-4 text-sm text-theme-text-secondary">{blockedReason}</p>
|
|
37
|
+
}
|
|
38
|
+
if (!query.error && query.data?.configured === false) {
|
|
39
|
+
return (
|
|
40
|
+
<p role="status" className="mt-4 text-sm text-theme-text-secondary">
|
|
41
|
+
Datadog rightsizing is unavailable for this cluster.
|
|
42
|
+
</p>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
return (
|
|
46
|
+
<section className="mt-4 rounded-lg border border-theme-border bg-theme-surface p-3">
|
|
47
|
+
<h3 className="text-sm font-medium text-theme-text-primary">Rightsizing</h3>
|
|
48
|
+
{query.error ? (
|
|
49
|
+
<p role="alert" className="mt-2 text-sm text-theme-text-secondary">
|
|
50
|
+
{query.error.message}{' '}
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
className="text-accent hover:underline"
|
|
54
|
+
onClick={() => void query.refetch()}
|
|
55
|
+
>
|
|
56
|
+
Retry
|
|
57
|
+
</button>
|
|
58
|
+
</p>
|
|
59
|
+
) : !query.data?.configured ? (
|
|
60
|
+
<p role="status" className="mt-2 text-sm text-theme-text-secondary">
|
|
61
|
+
Checking workload demand…
|
|
62
|
+
</p>
|
|
63
|
+
) : (
|
|
64
|
+
<DatadogRightsizingEvidence data={query.data.rightsizing} />
|
|
65
|
+
)}
|
|
66
|
+
</section>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { AreaChart, MetricsSummary, type TimeSeries } from '@skyhook-io/k8s-ui/components/charts'
|
|
3
|
+
import { ApiError, fetchJSON, usePrometheusStatus, useRadarFeature, type PrometheusTimeRange } from '../../api/client'
|
|
4
|
+
import { getApiBase } from '../../api/config'
|
|
5
|
+
import { WORKLOAD_CATEGORIES } from './PrometheusCharts'
|
|
6
|
+
import { useNavCustomization } from '../../context/NavCustomization'
|
|
7
|
+
import { RightsizingPanel } from './RightsizingStrip'
|
|
8
|
+
import { DatadogRightsizingPanel } from './DatadogRightsizingPanel'
|
|
9
|
+
|
|
10
|
+
type Metric = 'cpu' | 'memory'
|
|
11
|
+
type Panel = { unit: string; series: TimeSeries[] }
|
|
12
|
+
type Panels = Record<Metric, Panel> & { throttling?: Panel }
|
|
13
|
+
type Workload = { kind: string; namespace: string; name: string }
|
|
14
|
+
type WorkloadCharts = { configured: false } | { configured: true; charts: Panels }
|
|
15
|
+
|
|
16
|
+
const datadogCategories = [
|
|
17
|
+
...WORKLOAD_CATEGORIES.filter((category) => category.key === 'cpu' || category.key === 'memory'),
|
|
18
|
+
{ key: 'throttling', label: 'CPU throttled periods', color: 'text-warning-text', chartColor: 'var(--warning-text)', fillColor: 'color-mix(in srgb, var(--warning-text) 14%, transparent)' },
|
|
19
|
+
] as const
|
|
20
|
+
|
|
21
|
+
interface DatadogStatus {
|
|
22
|
+
configured: boolean
|
|
23
|
+
rightsizing?: boolean
|
|
24
|
+
rightsizingProvider?: 'datadog' | 'prometheus'
|
|
25
|
+
setup?: 'owner' | 'member'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type RightsizingSource = 'datadog' | 'prometheus' | 'unknown' | 'datadog_unavailable'
|
|
29
|
+
|
|
30
|
+
function resolveRightsizingSource(status: DatadogStatus | undefined, error: Error | null, providerRequired: boolean): RightsizingSource {
|
|
31
|
+
if (error) return !providerRequired && error instanceof ApiError && error.unknownRoute ? 'prometheus' : 'unknown'
|
|
32
|
+
if (!status || (providerRequired && !status.rightsizingProvider)) return 'unknown'
|
|
33
|
+
if (status.rightsizingProvider === 'datadog') return status.rightsizing ? 'datadog' : 'datadog_unavailable'
|
|
34
|
+
return 'prometheus'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function useDatadogStatus(kind: string, namespace: string, embedded: boolean) {
|
|
38
|
+
const { rightsizingProviderStatus = false } = useNavCustomization()
|
|
39
|
+
const enabled = embedded && !!namespace && ['Deployment', 'StatefulSet', 'DaemonSet'].includes(kind)
|
|
40
|
+
const apiBase = getApiBase()
|
|
41
|
+
const status = useQuery({
|
|
42
|
+
queryKey: ['datadog-metrics-status', apiBase],
|
|
43
|
+
enabled,
|
|
44
|
+
staleTime: 60_000,
|
|
45
|
+
retry: false,
|
|
46
|
+
queryFn: ({ signal }) => fetchJSON<DatadogStatus>('/metrics/datadog/status', signal),
|
|
47
|
+
})
|
|
48
|
+
const source = enabled ? resolveRightsizingSource(status.data, status.error, rightsizingProviderStatus) : 'prometheus'
|
|
49
|
+
return { status, enabled, source, mapped: enabled && !status.isError && status.data?.configured === true }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function rightsizingOverride(workload: Workload, source: RightsizingSource, retry: () => void, error?: Error | null) {
|
|
53
|
+
if (source === 'prometheus') return null
|
|
54
|
+
if (source === 'datadog') return <DatadogRightsizingPanel key={[workload.kind, workload.namespace, workload.name].join('/')} {...workload} />
|
|
55
|
+
return <section className="mt-4 rounded-lg border border-theme-border bg-theme-surface p-3">
|
|
56
|
+
<h3 className="text-sm font-medium text-theme-text-primary">Rightsizing</h3>
|
|
57
|
+
<p role="alert" className="mt-2 text-sm text-theme-text-secondary">
|
|
58
|
+
{source === 'datadog_unavailable'
|
|
59
|
+
? 'Datadog rightsizing is selected, but this cluster has no usable rightsizing connection.'
|
|
60
|
+
: 'Radar could not determine the rightsizing source.'} {error?.message}{' '}
|
|
61
|
+
<button type="button" className="text-accent hover:underline" onClick={retry}>Retry</button>
|
|
62
|
+
</p>
|
|
63
|
+
</section>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function WorkloadCostRightsizing(workload: Workload) {
|
|
67
|
+
const { embedded = false } = useNavCustomization()
|
|
68
|
+
const { status, source } = useDatadogStatus(workload.kind, workload.namespace, embedded)
|
|
69
|
+
if (status.isLoading) return <p role="status" className="p-3 text-sm text-theme-text-secondary">Checking rightsizing source…</p>
|
|
70
|
+
return rightsizingOverride(workload, source, () => void status.refetch(), status.error) ?? <RightsizingPanel {...workload} />
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function useDatadogWorkloadCharts({ kind, namespace, name }: Workload, range: PrometheusTimeRange, embedded: boolean) {
|
|
74
|
+
const { status, enabled, mapped, source } = useDatadogStatus(kind, namespace, embedded)
|
|
75
|
+
const apiBase = getApiBase()
|
|
76
|
+
const path = [kind, namespace, name].map(encodeURIComponent).join('/')
|
|
77
|
+
const charts = useQuery<WorkloadCharts>({
|
|
78
|
+
queryKey: ['datadog-workload-metrics', apiBase, path, range],
|
|
79
|
+
enabled: mapped,
|
|
80
|
+
staleTime: 30_000,
|
|
81
|
+
retry: false,
|
|
82
|
+
queryFn: ({ signal }) => fetchJSON<WorkloadCharts>(`/metrics/datadog/workloads/${path}?range=${range}`, signal),
|
|
83
|
+
})
|
|
84
|
+
const rightsizing = rightsizingOverride({ kind, namespace, name }, source, () => void status.refetch(), status.error)
|
|
85
|
+
return { charts, rightsizing, setup: enabled && !status.isError ? status.data?.setup : undefined, checking: status.isLoading, configured: mapped && charts.data?.configured !== false }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function DatadogSetupHint({ owner }: { owner: boolean }) {
|
|
89
|
+
const { data: prom, isError } = usePrometheusStatus()
|
|
90
|
+
const { support } = useRadarFeature('datadogAgentPresence')
|
|
91
|
+
const empty = !isError && prom?.connected === false && !prom.discovering && !prom.address
|
|
92
|
+
const presence = useQuery({
|
|
93
|
+
queryKey: ['datadog-agent-presence', getApiBase()],
|
|
94
|
+
enabled: empty && support === 'supported',
|
|
95
|
+
queryFn: ({ signal }) => fetchJSON<{detected: boolean}>('/metrics/datadog/agent', signal),
|
|
96
|
+
staleTime: 60_000, retry: false,
|
|
97
|
+
})
|
|
98
|
+
if (!empty || support !== 'supported' || presence.isError || !presence.data?.detected) return null
|
|
99
|
+
return <div className="p-4 text-center text-sm">
|
|
100
|
+
<p className="font-medium text-theme-text-primary">Datadog Agent detected</p>
|
|
101
|
+
<p className="mt-1 text-theme-text-secondary">{owner ? 'Connect Datadog once for CPU and memory charts across your matched clusters.' : 'An organization owner can connect Datadog for CPU and memory charts.'}</p>
|
|
102
|
+
{owner && <a href="/settings/organization/integrations#datadog-metrics" className="mt-2 inline-block text-accent underline">Connect Datadog</a>}
|
|
103
|
+
</div>
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function DatadogWorkloadCharts({
|
|
107
|
+
charts, error, loading, onRetry,
|
|
108
|
+
}: {
|
|
109
|
+
charts?: Panels
|
|
110
|
+
error?: Error | null
|
|
111
|
+
loading: boolean
|
|
112
|
+
onRetry: () => void
|
|
113
|
+
}) {
|
|
114
|
+
return (
|
|
115
|
+
<section aria-label="Datadog workload totals">
|
|
116
|
+
<h2 className="text-sm font-medium text-theme-text-primary">Datadog <span className="text-theme-text-tertiary">· Beta</span></h2>
|
|
117
|
+
<p className="mb-3 text-xs text-theme-text-secondary">Workload totals across reporting containers, from workload creation</p>
|
|
118
|
+
{loading && <p role="status" className="py-4 text-sm text-theme-text-secondary">Loading Datadog metrics…</p>}
|
|
119
|
+
{error && (
|
|
120
|
+
<div className="py-4 text-sm">
|
|
121
|
+
<p role="alert" className="text-theme-text-secondary">{error.message}</p>
|
|
122
|
+
<button type="button" className="mt-2 text-accent hover:underline" onClick={onRetry}>Retry</button>
|
|
123
|
+
</div>
|
|
124
|
+
)}
|
|
125
|
+
{!error && !loading && charts && (
|
|
126
|
+
<div className="grid gap-3 lg:grid-cols-2">
|
|
127
|
+
{datadogCategories.map((category) => {
|
|
128
|
+
const panel = charts[category.key as keyof Panels]
|
|
129
|
+
if (!panel) return null
|
|
130
|
+
const { unit, series } = panel
|
|
131
|
+
const throttling = category.key === 'throttling'
|
|
132
|
+
return (
|
|
133
|
+
<section key={category.key} className={`min-w-0 rounded-lg border border-theme-border bg-theme-surface p-3${throttling ? ' lg:col-span-2' : ''}`}>
|
|
134
|
+
<header className="mb-2 flex flex-wrap items-center justify-between gap-2">
|
|
135
|
+
<h3 className="text-xs font-medium uppercase tracking-wide text-theme-text-secondary">{category.label}</h3>
|
|
136
|
+
{series.length > 0 && <MetricsSummary series={series} unit={unit} currentColorClass={category.color} />}
|
|
137
|
+
</header>
|
|
138
|
+
{series.length > 0
|
|
139
|
+
? <AreaChart series={series} unit={unit} color={category.chartColor} fillColor={category.fillColor} layout="dashboard" />
|
|
140
|
+
: <p className="py-6 text-center text-xs text-theme-text-secondary">No Datadog samples in this time range.</p>}
|
|
141
|
+
{throttling && <p className="mt-2 text-xs text-theme-text-tertiary">Share of CPU quota periods throttled across reporting containers.</p>}
|
|
142
|
+
</section>
|
|
143
|
+
)
|
|
144
|
+
})}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</section>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
@@ -6,6 +6,7 @@ import { renderToString } from 'react-dom/server'
|
|
|
6
6
|
// pass while the real predicate sent a denial down the silent-hide path, which
|
|
7
7
|
// is the failure this component exists to prevent.
|
|
8
8
|
import { ApiError } from '../../api/client'
|
|
9
|
+
import { PARTIAL_DATA_NOTE } from '@skyhook-io/k8s-ui/components/charts'
|
|
9
10
|
|
|
10
11
|
const forbidden = new ApiError('forbidden', 403)
|
|
11
12
|
let metricsResult: { data?: unknown; error?: unknown } = {}
|
|
@@ -75,3 +76,44 @@ describe('HPACharts — access state', () => {
|
|
|
75
76
|
expect(renderToString(<HPACharts data={hpa} />)).toBe('')
|
|
76
77
|
})
|
|
77
78
|
})
|
|
79
|
+
|
|
80
|
+
describe('HPACharts — cluster scope', () => {
|
|
81
|
+
it('says why the replica history is withheld instead of hiding', () => {
|
|
82
|
+
connected = true
|
|
83
|
+
metricsResult = {
|
|
84
|
+
data: {
|
|
85
|
+
current: { resultType: 'matrix', series: [] },
|
|
86
|
+
desired: { resultType: 'matrix', series: [] },
|
|
87
|
+
clusterScope: { state: 'label_missing', note: 'The HPA series lack this cluster\'s label.' },
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
const html = renderToString(<HPACharts data={hpa} />)
|
|
91
|
+
expect(html).toContain('Activity (last 1h)')
|
|
92
|
+
expect(html).toContain('data-cluster-scope="label_missing"')
|
|
93
|
+
expect(html).not.toContain('Replicas')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('draws a scoped answer and notes a partial one', () => {
|
|
97
|
+
connected = true
|
|
98
|
+
metricsResult = { data: { current: series([2, 3]), desired: series([3, 3]), clusterScope: { state: 'scoped_verified', note: 'Matched.' } } }
|
|
99
|
+
let html = renderToString(<HPACharts data={hpa} />)
|
|
100
|
+
expect(html).toContain('Replicas')
|
|
101
|
+
expect(html).not.toContain('data-cluster-scope')
|
|
102
|
+
expect(html).not.toContain('Partial data')
|
|
103
|
+
metricsResult = { data: { current: series([2, 3]), desired: series([3, 3]), partial: true } }
|
|
104
|
+
html = renderToString(<HPACharts data={hpa} />)
|
|
105
|
+
expect(html).toContain('Partial data')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// A shard that didn't answer may hold all the history, so an empty partial
|
|
109
|
+
// answer says so instead of hiding like an HPA KSM never reported.
|
|
110
|
+
it('notes an empty partial answer instead of hiding', () => {
|
|
111
|
+
connected = true
|
|
112
|
+
metricsResult = { data: { current: { resultType: 'matrix', series: [] }, desired: { resultType: 'matrix', series: [] }, partial: true } }
|
|
113
|
+
const html = renderToString(<HPACharts data={hpa} />)
|
|
114
|
+
expect(html).toContain('Activity (last 1h)')
|
|
115
|
+
expect(html).toContain('No replica history in a partial answer')
|
|
116
|
+
expect(html).toContain(PARTIAL_DATA_NOTE)
|
|
117
|
+
expect(html).not.toContain('Replicas')
|
|
118
|
+
})
|
|
119
|
+
})
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useEffect, useMemo } from 'react'
|
|
2
2
|
import { LineChart, Lock } from 'lucide-react'
|
|
3
3
|
import { AlertBanner } from '@skyhook-io/k8s-ui'
|
|
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 { usePrometheusHPAMetrics, usePrometheusStatus, useAutoPromConnect, isForbiddenError, type PrometheusSeries } from '../../api/client'
|
|
5
8
|
|
|
6
9
|
/**
|
|
@@ -65,7 +68,34 @@ export function HPACharts({ data }: { data: any }) {
|
|
|
65
68
|
)
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
// A withheld chart says why instead of hiding, which would read as "no history".
|
|
72
|
+
if (isClusterScopeWithheld(metrics?.clusterScope)) {
|
|
73
|
+
return (
|
|
74
|
+
<section className="mt-4 rounded-lg border border-theme-border bg-theme-surface/30 p-3">
|
|
75
|
+
<div className="flex items-center gap-2 mb-2 text-sm font-medium text-theme-text-secondary">
|
|
76
|
+
<LineChart className="w-4 h-4 text-theme-text-tertiary" />
|
|
77
|
+
Activity (last 1h)
|
|
78
|
+
</div>
|
|
79
|
+
<ClusterScopeNote scope={metrics?.clusterScope} />
|
|
80
|
+
</section>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!replicasPoints) {
|
|
85
|
+
// A partial answer with no samples is not "no history": the part of the
|
|
86
|
+
// store that didn't answer may hold all of it.
|
|
87
|
+
if (!metrics?.partial) return null
|
|
88
|
+
return (
|
|
89
|
+
<section className="mt-4 rounded-lg border border-theme-border bg-theme-surface/30 p-3">
|
|
90
|
+
<div className="flex items-center gap-2 mb-2 text-sm font-medium text-theme-text-secondary">
|
|
91
|
+
<LineChart className="w-4 h-4 text-theme-text-tertiary" />
|
|
92
|
+
Activity (last 1h)
|
|
93
|
+
</div>
|
|
94
|
+
<p className="text-xs text-theme-text-secondary">No replica history in a partial answer</p>
|
|
95
|
+
<p className="mt-1 text-xs text-theme-text-tertiary">{PARTIAL_DATA_NOTE}</p>
|
|
96
|
+
</section>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
69
99
|
|
|
70
100
|
return (
|
|
71
101
|
<section className="mt-4 rounded-lg border border-theme-border bg-theme-surface/30 p-3">
|
|
@@ -85,6 +115,9 @@ export function HPACharts({ data }: { data: any }) {
|
|
|
85
115
|
]}
|
|
86
116
|
formatY={(v) => v.toFixed(0)}
|
|
87
117
|
/>
|
|
118
|
+
{metrics?.partial && (
|
|
119
|
+
<p className="mt-1.5 text-xs text-theme-text-tertiary">{PARTIAL_DATA_NOTE}</p>
|
|
120
|
+
)}
|
|
88
121
|
</section>
|
|
89
122
|
)
|
|
90
123
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
3
|
+
import { getApiBase } from '../../api/config'
|
|
2
4
|
import { renderToString } from 'react-dom/server'
|
|
3
5
|
import { MemoryRouter } from 'react-router-dom'
|
|
4
6
|
import { NavCustomizationProvider } from '../../context/NavCustomization'
|
|
@@ -9,15 +11,18 @@ let connected = false
|
|
|
9
11
|
const ranges: string[] = []
|
|
10
12
|
const charts: { seriesLabels?: string[]; referenceLines?: unknown[] }[] = []
|
|
11
13
|
let workload: WorkloadMetrics
|
|
14
|
+
const drawnMetrics = { unit: 'cores', result: { series: [{ labels: { pod: 'web-0' }, dataPoints: [{ timestamp: 100, value: 1 }, { timestamp: 160, value: 2 }] }] } }
|
|
15
|
+
let resourceMetrics: Record<string, unknown> = drawnMetrics
|
|
16
|
+
let metricsByCategory: Record<string, Record<string, unknown>> = {}
|
|
12
17
|
|
|
13
18
|
vi.mock('../../api/client', async (importActual) => ({
|
|
14
19
|
...(await importActual<typeof import('../../api/client')>()),
|
|
15
20
|
useAutoPromConnect: () => undefined,
|
|
16
21
|
usePrometheusStatus: () => ({ data: { connected, error: 'Backend query failed' } }),
|
|
17
22
|
usePrometheusConnect: () => ({ mutate: vi.fn(), isPending: false }),
|
|
18
|
-
usePrometheusResourceMetrics: (_kind: string, _ns: string, _name: string,
|
|
19
|
-
ranges.push(range)
|
|
20
|
-
return { data:
|
|
23
|
+
usePrometheusResourceMetrics: (_kind: string, _ns: string, _name: string, category: string, range: string, enabled = true) => {
|
|
24
|
+
if (enabled) ranges.push(range)
|
|
25
|
+
return { data: metricsByCategory[category] ?? resourceMetrics }
|
|
21
26
|
},
|
|
22
27
|
}))
|
|
23
28
|
vi.mock('../../api/workloadMetrics', () => ({ useWorkloadMetrics: () => ({ data: workload }) }))
|
|
@@ -29,6 +34,7 @@ vi.mock('@skyhook-io/k8s-ui/components/charts', async (importActual) => ({
|
|
|
29
34
|
}))
|
|
30
35
|
|
|
31
36
|
const { PrometheusChartsGrid } = await import('./PrometheusChartsGrid')
|
|
37
|
+
const { PARTIAL_DATA_NOTE } = await import('@skyhook-io/k8s-ui/components/charts')
|
|
32
38
|
const resource = { spec: { template: { spec: { containers: [{ resources: { requests: { cpu: '100m' }, limits: { cpu: '200m' } } }] } } } }
|
|
33
39
|
const render = (url = '/workloads/Deployment/demo/web?tab=metrics', embedded = false) => renderToString(
|
|
34
40
|
<MemoryRouter initialEntries={[url]}><NavCustomizationProvider value={embedded ? { embedded: true } : {}}>
|
|
@@ -40,6 +46,8 @@ beforeEach(() => {
|
|
|
40
46
|
connected = false
|
|
41
47
|
ranges.length = 0
|
|
42
48
|
charts.length = 0
|
|
49
|
+
resourceMetrics = drawnMetrics
|
|
50
|
+
metricsByCategory = {}
|
|
43
51
|
workload = { state: 'available', sources: [], pods: 1, podsTotal: 1, start: 100, end: 160, stepSeconds: 60, rateWindowSeconds: 300, history: {}, comparison: {}, panels: {} }
|
|
44
52
|
})
|
|
45
53
|
|
|
@@ -90,6 +98,15 @@ describe('Expanded metrics recovery and scope', () => {
|
|
|
90
98
|
expect(charts.map((chart) => chart.seriesLabels)).toContainEqual(['p50', 'p95'])
|
|
91
99
|
expect(charts.map((chart) => chart.seriesLabels)).toContainEqual(['Workload', 'Maximum Pod'])
|
|
92
100
|
})
|
|
101
|
+
it('notes a partial answer with no samples instead of claiming no data', () => {
|
|
102
|
+
connected = true
|
|
103
|
+
resourceMetrics = { unit: 'cores', result: { series: [] }, partial: true }
|
|
104
|
+
const html = render()
|
|
105
|
+
expect(html).toContain('No samples in a partial answer')
|
|
106
|
+
expect(html).toContain(PARTIAL_DATA_NOTE)
|
|
107
|
+
resourceMetrics = { unit: 'cores', result: { series: [] } }
|
|
108
|
+
expect(render()).not.toContain(PARTIAL_DATA_NOTE)
|
|
109
|
+
})
|
|
93
110
|
it('retains template references on verified current-Pod charts', () => {
|
|
94
111
|
connected = true
|
|
95
112
|
workload.history.cpu = { mode: 'current-pods' }
|
|
@@ -98,3 +115,109 @@ describe('Expanded metrics recovery and scope', () => {
|
|
|
98
115
|
expect(charts.some((chart) => chart.referenceLines?.some((line) => (line as { label: string }).label === 'Template request 100m'))).toBe(true)
|
|
99
116
|
})
|
|
100
117
|
})
|
|
118
|
+
|
|
119
|
+
describe('Mapped workload Metrics tab', () => {
|
|
120
|
+
async function renderMapped(denied = false) {
|
|
121
|
+
const { MetricsTabContent } = await import('../workload/WorkloadView')
|
|
122
|
+
const client = new QueryClient({ defaultOptions: { queries: { retryOnMount: false } } })
|
|
123
|
+
client.setQueryData(['datadog-metrics-status', getApiBase()], { configured: true })
|
|
124
|
+
const queryKey = ['datadog-workload-metrics', getApiBase(), 'Deployment/demo/web', '3h']
|
|
125
|
+
const panel = { unit: 'cores', series: [] }
|
|
126
|
+
client.setQueryData(queryKey, { configured: true, charts: { cpu: panel, memory: { ...panel, unit: 'bytes' } } })
|
|
127
|
+
if (denied) client.getQueryCache().find({ queryKey })!.setState({ status: 'error', error: new Error('Datadog read denied') })
|
|
128
|
+
const html = renderToString(
|
|
129
|
+
<QueryClientProvider client={client}><MemoryRouter initialEntries={['/?tab=metrics&metricsRange=3h']}>
|
|
130
|
+
<NavCustomizationProvider value={{ embedded: true }}>
|
|
131
|
+
<MetricsTabContent kind="Deployment" namespace="demo" name="web" resource={resource} expanded />
|
|
132
|
+
</NavCustomizationProvider>
|
|
133
|
+
</MemoryRouter></QueryClientProvider>,
|
|
134
|
+
)
|
|
135
|
+
client.clear()
|
|
136
|
+
return html
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
it.each([false, true])('retains Prometheus traffic, network and template lines with a Datadog mapping (read denied=%s)', async (denied) => {
|
|
140
|
+
connected = true
|
|
141
|
+
const series = [{ labels: {}, dataPoints: [{ timestamp: 160, value: 1 }] }]
|
|
142
|
+
workload.panels.requests = { state: 'available', unit: 'requests/s', series }
|
|
143
|
+
workload.panels.errors = { state: 'available', unit: 'percent', series }
|
|
144
|
+
workload.panels.p50 = workload.panels.p95 = { state: 'available', unit: 'seconds', series }
|
|
145
|
+
workload.history.cpu = { mode: 'current-pods' }
|
|
146
|
+
workload.panels.cpu = { state: 'available', unit: 'cores', series }
|
|
147
|
+
const html = await renderMapped(denied)
|
|
148
|
+
for (const label of ['Datadog workload totals', 'Requests / sec', 'HTTP 5xx', 'Latency · p50 / p95', 'Network and storage']) expect(html).toContain(label)
|
|
149
|
+
expect(html).toContain(denied ? 'Datadog read denied' : 'No Datadog samples')
|
|
150
|
+
expect(html.match(/aria-label="Metrics time range"/g)).toHaveLength(1)
|
|
151
|
+
expect(ranges.every((range) => range === '3h')).toBe(true)
|
|
152
|
+
expect(charts.flatMap((chart) => chart.referenceLines ?? [])).toEqual(expect.arrayContaining([
|
|
153
|
+
expect.objectContaining({ label: 'Template request 100m' }), expect.objectContaining({ label: 'Template limit 200m' }),
|
|
154
|
+
]))
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('renders Datadog independently when Prometheus is disconnected', async () => {
|
|
158
|
+
const html = await renderMapped()
|
|
159
|
+
expect(html).toContain('Datadog workload totals')
|
|
160
|
+
expect(html).toContain('No Datadog samples')
|
|
161
|
+
expect(html).not.toContain('Network and storage')
|
|
162
|
+
expect(ranges).toHaveLength(0)
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
describe('Name-matched chart captions follow the charts\' cluster scope', () => {
|
|
167
|
+
const ANOTHER_CLUSTER_SECTION = 'matching names in a shared backend may include another cluster'
|
|
168
|
+
const ANOTHER_CLUSTER_GRID = 'Matching names in a shared backend may include another cluster.'
|
|
169
|
+
const scoped = (state: string, note = 'note') => ({ ...drawnMetrics, clusterScope: { state, note } })
|
|
170
|
+
const renderText = () => render().replaceAll('<!-- -->', '')
|
|
171
|
+
beforeEach(() => { connected = true })
|
|
172
|
+
|
|
173
|
+
it.each(['scoped_verified', 'scoped_configured'])('drops the other-cluster caveat when every chart is %s', (state) => {
|
|
174
|
+
resourceMetrics = scoped(state)
|
|
175
|
+
const html = renderText()
|
|
176
|
+
expect(html).toContain('Basic CPU / memory · matched by cluster label')
|
|
177
|
+
expect(html).toContain('Pod-name matched · matched by cluster label')
|
|
178
|
+
expect(html).toContain('kept to this cluster by its cluster labels')
|
|
179
|
+
expect(html).not.toContain('may include another cluster')
|
|
180
|
+
expect(html).not.toContain('identity unverified')
|
|
181
|
+
})
|
|
182
|
+
it('names an operator-declared single-cluster store', () => {
|
|
183
|
+
resourceMetrics = scoped('single_cluster_asserted')
|
|
184
|
+
const html = renderText()
|
|
185
|
+
expect(html).toContain('Basic CPU / memory · operator declared single-cluster')
|
|
186
|
+
expect(html).toContain('Pod-name matched · operator declared single-cluster')
|
|
187
|
+
expect(html).not.toContain('may include another cluster')
|
|
188
|
+
})
|
|
189
|
+
it.each([['absent', drawnMetrics], ['unlabeled', scoped('unlabeled')]])('keeps today\'s caveat when clusterScope is %s', (_label, metrics) => {
|
|
190
|
+
resourceMetrics = metrics
|
|
191
|
+
const html = renderText()
|
|
192
|
+
expect(html).toContain('Basic CPU / memory · identity unverified')
|
|
193
|
+
expect(html).toContain('These charts match current Pod names, not Pod UIDs or historical workload ownership; matching names in a shared backend may include another cluster.')
|
|
194
|
+
expect(html).toContain('Pod-name matched · identity unverified')
|
|
195
|
+
expect(html).toContain(`These charts match current Pod names, independently of the identity-checked charts above. ${ANOTHER_CLUSTER_GRID}`)
|
|
196
|
+
})
|
|
197
|
+
it('keeps the caveat header for withheld charts and defers to their own note', () => {
|
|
198
|
+
resourceMetrics = scoped('label_missing', 'The series lack this cluster\'s label.')
|
|
199
|
+
const html = renderText()
|
|
200
|
+
expect(html).toContain('Basic CPU / memory · identity unverified')
|
|
201
|
+
expect(html).toContain('Pod-name matched · identity unverified')
|
|
202
|
+
expect(html).toContain('say why in place of their data')
|
|
203
|
+
expect(html).toContain('The series lack this cluster's label.')
|
|
204
|
+
expect(html).not.toContain('may include another cluster')
|
|
205
|
+
})
|
|
206
|
+
it('uses the least certain chart when a section disagrees', () => {
|
|
207
|
+
resourceMetrics = scoped('scoped_verified')
|
|
208
|
+
metricsByCategory = { memory: drawnMetrics, filesystem: scoped('unlabeled') }
|
|
209
|
+
const html = renderText()
|
|
210
|
+
expect(html).toContain('Basic CPU / memory · identity unverified')
|
|
211
|
+
expect(html).toContain(ANOTHER_CLUSTER_SECTION)
|
|
212
|
+
expect(html).toContain('Pod-name matched · identity unverified')
|
|
213
|
+
expect(html).toContain(ANOTHER_CLUSTER_GRID)
|
|
214
|
+
})
|
|
215
|
+
it('lets a verified network section drop the caveat while a withheld chart above keeps its header', () => {
|
|
216
|
+
resourceMetrics = scoped('scoped_verified')
|
|
217
|
+
metricsByCategory = { cpu: scoped('several_clusters') }
|
|
218
|
+
const html = renderText()
|
|
219
|
+
expect(html).toContain('Basic CPU / memory · identity unverified')
|
|
220
|
+
expect(html).toContain('Pod-name matched · matched by cluster label')
|
|
221
|
+
expect(html).not.toContain('may include another cluster')
|
|
222
|
+
})
|
|
223
|
+
})
|