@skyhook-io/radar-app 1.21.6 → 1.21.7
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 +1 -1
- package/package.json +7 -7
- package/src/App.tsx +19 -1
- package/src/RadarApp.tsx +8 -2
- package/src/api/client.discoverMetrics.test.tsx +69 -0
- package/src/api/client.issueCorrelation.test.tsx +244 -0
- package/src/api/client.issueRowChanges.test.tsx +129 -0
- package/src/api/client.pendingOwnership.test.tsx +197 -0
- package/src/api/client.prometheusStatus.test.ts +4 -0
- package/src/api/client.restartError.test.ts +36 -1
- package/src/api/client.stopWorkflow.test.tsx +133 -0
- package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
- package/src/api/client.ts +572 -111
- package/src/api/connectionBinding.test.tsx +3 -1
- package/src/api/connectionBinding.ts +14 -2
- package/src/api/gitOpsPermissions.render.test.tsx +155 -0
- package/src/api/gitOpsPermissions.test.ts +90 -0
- package/src/api/gitOpsPermissions.ts +51 -0
- package/src/api/httpErrors.test.ts +30 -1
- package/src/api/httpErrors.ts +17 -0
- package/src/api/openobserveSetup.ts +85 -0
- package/src/api/podDebug.test.tsx +137 -0
- package/src/api/podDebug.ts +82 -0
- package/src/api/prometheusCharts.test.ts +23 -0
- package/src/api/prometheusCharts.ts +25 -0
- package/src/api/radarFeatures.render.test.tsx +43 -2
- package/src/api/radarFeatures.test.ts +18 -1
- package/src/api/radarFeatures.ts +17 -4
- package/src/api/reviewedActionMutation.ts +9 -2
- package/src/api/workloadMetrics.ts +2 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
- package/src/components/applications/ApplicationsView.tsx +56 -31
- package/src/components/cnpg/host.test.tsx +1 -1
- package/src/components/cnpg/host.tsx +0 -2
- package/src/components/dock/BottomDock.tsx +7 -3
- package/src/components/dock/MissingShellDebug.test.tsx +193 -0
- package/src/components/dock/MissingShellDebug.tsx +114 -0
- package/src/components/dock/PodDebugSession.test.tsx +60 -0
- package/src/components/dock/PodDebugSession.tsx +96 -0
- package/src/components/dock/TerminalTab.test.tsx +48 -4
- package/src/components/dock/TerminalTab.tsx +47 -25
- package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
- package/src/components/dock/WorkloadLogsTab.tsx +16 -0
- package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
- package/src/components/execution/BatchExecutionView.tsx +88 -5
- package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
- package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
- package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
- package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
- package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
- package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
- package/src/components/gitops/GitOpsView.tsx +93 -32
- package/src/components/helm/OwnedResources.tsx +1 -0
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/issues/IssuesPane.render.test.tsx +1 -1
- package/src/components/issues/IssuesPane.tsx +11 -0
- package/src/components/issues/useIssueExpansion.ts +91 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
- package/src/components/resource/MetricsNotConnected.tsx +114 -0
- package/src/components/resource/PVCUsageBar.tsx +2 -1
- package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
- package/src/components/resource/PrometheusCharts.tsx +14 -2
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
- package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
- package/src/components/resource/RestartChart.tsx +4 -3
- package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
- package/src/components/resource/RightsizingStrip.tsx +5 -3
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
- package/src/components/resource/nameMatchedScope.ts +9 -3
- package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
- package/src/components/resources/PodDebugAction.test.tsx +157 -0
- package/src/components/resources/PodDebugAction.tsx +207 -0
- package/src/components/resources/PodDebugPermission.tsx +21 -0
- package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
- package/src/components/resources/ResourcesView.tsx +39 -5
- package/src/components/resources/namespaceHint.test.ts +34 -0
- package/src/components/resources/namespaceHint.ts +19 -0
- package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
- package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
- package/src/components/resources/renderers/PodRenderer.tsx +12 -5
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
- package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
- package/src/components/settings/MetricsBackendSwitch.tsx +167 -0
- package/src/components/settings/OpenObserveSetup.test.tsx +343 -0
- package/src/components/settings/OpenObserveSetup.tsx +358 -0
- package/src/components/settings/SettingsDialog.tsx +21 -7
- package/src/components/settings/openobserveStatus.test.ts +34 -0
- package/src/components/settings/openobserveStatus.ts +55 -0
- package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
- package/src/components/timeline/TimelineList.test.ts +18 -0
- package/src/components/timeline/TimelineList.tsx +19 -5
- package/src/components/timeline/TimelineView.tsx +2 -0
- package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
- package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +95 -10
- package/src/context/TimelineNavigation.test.ts +59 -0
- package/src/context/TimelineNavigation.tsx +86 -0
- package/src/contexts/CapabilitiesContext.tsx +3 -1
- package/src/hooks/useResourceCounts.ts +2 -1
- package/src/hooks/useWorkflowStopAction.ts +31 -0
- package/src/index.css +1 -0
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +4 -2
- package/src/k8s-ui-exports.test.ts +10 -0
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
|
|
2
|
+
import { clsx } from 'clsx'
|
|
3
|
+
import {
|
|
4
|
+
getOpenObserveState,
|
|
5
|
+
removeOpenObserveCluster,
|
|
6
|
+
type OpenObserveState,
|
|
7
|
+
} from '../../api/openobserveSetup'
|
|
8
|
+
import { OpenObserveSetup } from './OpenObserveSetup'
|
|
9
|
+
|
|
10
|
+
type Backend = 'prometheus' | 'openobserve'
|
|
11
|
+
|
|
12
|
+
const OPTIONS: { value: Backend; title: string; description: string }[] = [
|
|
13
|
+
{ value: 'prometheus', title: 'Prometheus-compatible', description: 'Prometheus, VictoriaMetrics, Thanos or Grafana Mimir.' },
|
|
14
|
+
{ value: 'openobserve', title: 'OpenObserve', description: 'Read this cluster’s metrics from OpenObserve, filtered to this cluster.' },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
export interface PrometheusViewProps {
|
|
18
|
+
status?: ReactNode
|
|
19
|
+
onDirtyChange: (dirty: boolean) => void
|
|
20
|
+
onBusyChange: (busy: boolean) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function MetricsBackendSwitch({
|
|
24
|
+
locked = false,
|
|
25
|
+
status,
|
|
26
|
+
prometheus,
|
|
27
|
+
onChanged,
|
|
28
|
+
onDirtyChange,
|
|
29
|
+
onBusyChange,
|
|
30
|
+
}: {
|
|
31
|
+
locked?: boolean
|
|
32
|
+
status?: ReactNode
|
|
33
|
+
prometheus: (props: PrometheusViewProps) => ReactNode
|
|
34
|
+
onChanged: () => void
|
|
35
|
+
onDirtyChange?: (dirty: boolean) => void
|
|
36
|
+
onBusyChange?: (busy: boolean) => void
|
|
37
|
+
}) {
|
|
38
|
+
const [data, setData] = useState<OpenObserveState | null>(null)
|
|
39
|
+
const [loadError, setLoadError] = useState('')
|
|
40
|
+
const [retry, setRetry] = useState(0)
|
|
41
|
+
const [picked, setChoice] = useState<Backend | null>(null)
|
|
42
|
+
const [promDirty, setPromDirty] = useState(false)
|
|
43
|
+
const [promBusy, setPromBusy] = useState(false)
|
|
44
|
+
const [ooDirty, setOoDirty] = useState(false)
|
|
45
|
+
const [ooBusy, setOoBusy] = useState(false)
|
|
46
|
+
const [releasing, setReleasing] = useState(false)
|
|
47
|
+
const [releaseError, setReleaseError] = useState('')
|
|
48
|
+
const busy = promBusy || ooBusy || releasing
|
|
49
|
+
const choice: Backend | null = picked ?? (loadError ? 'prometheus' : null)
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const controller = new AbortController()
|
|
53
|
+
getOpenObserveState(controller.signal)
|
|
54
|
+
.then((next) => {
|
|
55
|
+
if (controller.signal.aborted) return
|
|
56
|
+
setData(next)
|
|
57
|
+
setLoadError('')
|
|
58
|
+
setChoice((current) => current ?? (next.cluster.match ? 'openobserve' : 'prometheus'))
|
|
59
|
+
})
|
|
60
|
+
.catch((error: unknown) => {
|
|
61
|
+
if (controller.signal.aborted) return
|
|
62
|
+
setLoadError(error instanceof Error ? error.message : String(error))
|
|
63
|
+
})
|
|
64
|
+
return () => controller.abort()
|
|
65
|
+
}, [retry])
|
|
66
|
+
|
|
67
|
+
useEffect(() => onDirtyChange?.(promDirty || ooDirty), [promDirty, ooDirty, onDirtyChange])
|
|
68
|
+
useEffect(() => onBusyChange?.(busy), [busy, onBusyChange])
|
|
69
|
+
|
|
70
|
+
// The Prometheus form restores focus in the same commit it reports idle, so
|
|
71
|
+
// the dialog must hear it then: a parent still marked busy keeps the pane inert.
|
|
72
|
+
const reported = useRef({ promDirty: false, ooDirty: false, promBusy: false, ooBusy: false, releasing: false })
|
|
73
|
+
reported.current = { promDirty, ooDirty, promBusy, ooBusy, releasing }
|
|
74
|
+
const promDirtyChange = useCallback((dirty: boolean) => {
|
|
75
|
+
setPromDirty(dirty)
|
|
76
|
+
onDirtyChange?.(dirty || reported.current.ooDirty)
|
|
77
|
+
}, [onDirtyChange])
|
|
78
|
+
const promBusyChange = useCallback((next: boolean) => {
|
|
79
|
+
setPromBusy(next)
|
|
80
|
+
onBusyChange?.(next || reported.current.ooBusy || reported.current.releasing)
|
|
81
|
+
}, [onBusyChange])
|
|
82
|
+
|
|
83
|
+
const releaseCluster = useCallback(async () => {
|
|
84
|
+
const next = await removeOpenObserveCluster(data?.cluster.uid)
|
|
85
|
+
setData(next)
|
|
86
|
+
setChoice('prometheus')
|
|
87
|
+
onChanged()
|
|
88
|
+
}, [data?.cluster.uid, onChanged])
|
|
89
|
+
|
|
90
|
+
const releaseFromPrometheusView = async () => {
|
|
91
|
+
setReleasing(true)
|
|
92
|
+
setReleaseError('')
|
|
93
|
+
try {
|
|
94
|
+
await releaseCluster()
|
|
95
|
+
} catch (error) {
|
|
96
|
+
setReleaseError(error instanceof Error ? error.message : String(error))
|
|
97
|
+
} finally {
|
|
98
|
+
setReleasing(false)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const statusRow = status ? <div className="flex flex-wrap items-center gap-x-3 gap-y-1">{status}</div> : null
|
|
103
|
+
const matched = !!data?.cluster.match
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className="space-y-4">
|
|
107
|
+
<div role="radiogroup" aria-label="Metrics backend" className="grid gap-2 sm:grid-cols-2">
|
|
108
|
+
{OPTIONS.map((option) => {
|
|
109
|
+
const selected = choice === option.value
|
|
110
|
+
return (
|
|
111
|
+
<button
|
|
112
|
+
key={option.value}
|
|
113
|
+
type="button"
|
|
114
|
+
role="radio"
|
|
115
|
+
aria-checked={selected}
|
|
116
|
+
disabled={locked || busy || !choice}
|
|
117
|
+
onClick={() => setChoice(option.value)}
|
|
118
|
+
className={clsx(
|
|
119
|
+
'rounded-lg border px-3 py-2 text-left transition-colors',
|
|
120
|
+
selected ? 'border-accent bg-accent-muted' : 'border-theme-border',
|
|
121
|
+
!selected && !locked && !busy && 'hover:bg-theme-hover',
|
|
122
|
+
(locked || busy) && 'cursor-not-allowed'
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
<span className="block text-sm font-medium text-theme-text-primary">{option.title}</span>
|
|
126
|
+
<span className="mt-0.5 block text-xs text-theme-text-tertiary">{option.description}</span>
|
|
127
|
+
</button>
|
|
128
|
+
)
|
|
129
|
+
})}
|
|
130
|
+
</div>
|
|
131
|
+
{!choice && <p role="status" className="text-xs text-theme-text-tertiary">Checking the metrics backend…</p>}
|
|
132
|
+
<div className={clsx('space-y-4', choice !== 'prometheus' && 'hidden')} inert={choice !== 'prometheus' || undefined}>
|
|
133
|
+
{matched && !locked && (
|
|
134
|
+
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs">
|
|
135
|
+
<span className="text-warning-text">This cluster still reads from OpenObserve.</span>
|
|
136
|
+
<button type="button" disabled={busy} onClick={() => void releaseFromPrometheusView()} className="font-medium text-accent-text hover:underline">
|
|
137
|
+
{releasing ? 'Switching…' : 'Use Prometheus for this cluster'}
|
|
138
|
+
</button>
|
|
139
|
+
{releaseError && <span role="alert" className="basis-full text-semantic-error">{releaseError}</span>}
|
|
140
|
+
</div>
|
|
141
|
+
)}
|
|
142
|
+
{locked
|
|
143
|
+
? choice === 'prometheus' && statusRow
|
|
144
|
+
: prometheus({ status: choice === 'prometheus' ? status : undefined, onDirtyChange: promDirtyChange, onBusyChange: promBusyChange })}
|
|
145
|
+
</div>
|
|
146
|
+
<div className={clsx(choice !== 'openobserve' && 'hidden')} inert={choice !== 'openobserve' || undefined}>
|
|
147
|
+
{data ? (
|
|
148
|
+
<OpenObserveSetup
|
|
149
|
+
state={data}
|
|
150
|
+
locked={locked}
|
|
151
|
+
status={choice === 'openobserve' ? status : undefined}
|
|
152
|
+
onStateChange={setData}
|
|
153
|
+
onChanged={onChanged}
|
|
154
|
+
onUsePrometheus={releaseCluster}
|
|
155
|
+
onDirtyChange={setOoDirty}
|
|
156
|
+
onBusyChange={setOoBusy}
|
|
157
|
+
/>
|
|
158
|
+
) : loadError ? (
|
|
159
|
+
<p role="alert" className="text-xs text-warning-text">
|
|
160
|
+
Couldn’t load OpenObserve settings: {loadError}{' '}
|
|
161
|
+
<button type="button" className="underline" onClick={() => setRetry((n) => n + 1)}>Retry</button>
|
|
162
|
+
</p>
|
|
163
|
+
) : null}
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import type { OpenObserveConnection, OpenObserveState } from '../../api/openobserveSetup'
|
|
6
|
+
import { MetricsBackendSwitch } from './MetricsBackendSwitch'
|
|
7
|
+
|
|
8
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
9
|
+
|
|
10
|
+
type Reply = { status?: number; body: unknown }
|
|
11
|
+
interface Call { method: string; path: string; body?: Record<string, unknown> }
|
|
12
|
+
|
|
13
|
+
let container: HTMLDivElement
|
|
14
|
+
let root: Root
|
|
15
|
+
let calls: Call[]
|
|
16
|
+
let replies: Record<string, Reply[]>
|
|
17
|
+
|
|
18
|
+
const connection = (changes: Partial<OpenObserveConnection> = {}): OpenObserveConnection => ({
|
|
19
|
+
baseUrl: 'https://oo.example.com',
|
|
20
|
+
org: 'default',
|
|
21
|
+
user: 'radar@example.com',
|
|
22
|
+
tokenSource: 'saved',
|
|
23
|
+
clusters: [{ context: 'kind-oo-b', by: 'id' }],
|
|
24
|
+
...changes,
|
|
25
|
+
})
|
|
26
|
+
const unmatched: OpenObserveState = { connection: null, cluster: { uid: 'uid-123' } }
|
|
27
|
+
const matched = (changes: Partial<OpenObserveConnection> = {}): OpenObserveState => ({
|
|
28
|
+
connection: connection(changes),
|
|
29
|
+
cluster: { uid: 'uid-123', match: { label: 'k8s_cluster_uid', value: 'uid-123', by: 'id' } },
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const reply = (key: string, ...items: Reply[]) => {
|
|
33
|
+
replies[key] = [...(replies[key] ?? []), ...items]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
calls = []
|
|
38
|
+
replies = {}
|
|
39
|
+
vi.stubGlobal('fetch', vi.fn(async (url: string, init?: RequestInit) => {
|
|
40
|
+
const method = init?.method ?? 'GET'
|
|
41
|
+
const path = url.replace(/^.*\/api/, '')
|
|
42
|
+
calls.push({ method, path, body: init?.body ? JSON.parse(String(init.body)) : undefined })
|
|
43
|
+
const queue = replies[`${method} ${path}`]
|
|
44
|
+
const next = queue && queue.length > 1 ? queue.shift()! : queue?.[0]
|
|
45
|
+
if (!next) throw new Error(`unexpected ${method} ${path}`)
|
|
46
|
+
return new Response(JSON.stringify(next.body), { status: next.status ?? 200 })
|
|
47
|
+
}))
|
|
48
|
+
container = document.createElement('div')
|
|
49
|
+
document.body.appendChild(container)
|
|
50
|
+
root = createRoot(container)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
act(() => root.unmount())
|
|
55
|
+
container.remove()
|
|
56
|
+
document.body.innerHTML = ''
|
|
57
|
+
vi.unstubAllGlobals()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const flush = () => act(async () => { for (let i = 0; i < 5; i++) await new Promise((r) => setTimeout(r, 0)) })
|
|
61
|
+
|
|
62
|
+
async function mount(state: OpenObserveState, props: { locked?: boolean; onChanged?: () => void; onDirtyChange?: (dirty: boolean) => void } = {}) {
|
|
63
|
+
reply('GET /integrations/openobserve', { body: state })
|
|
64
|
+
act(() => root.render(
|
|
65
|
+
<MetricsBackendSwitch
|
|
66
|
+
locked={props.locked}
|
|
67
|
+
onChanged={props.onChanged ?? vi.fn()}
|
|
68
|
+
onDirtyChange={props.onDirtyChange}
|
|
69
|
+
status={<span>Status block</span>}
|
|
70
|
+
prometheus={({ status }) => <div data-testid="prometheus-form">Prometheus form {status}</div>}
|
|
71
|
+
/>
|
|
72
|
+
))
|
|
73
|
+
await flush()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const radio = (name: string) =>
|
|
77
|
+
Array.from(container.querySelectorAll<HTMLButtonElement>('[role="radio"]')).find((b) => b.textContent?.includes(name))!
|
|
78
|
+
const button = (text: string) =>
|
|
79
|
+
Array.from(document.querySelectorAll<HTMLButtonElement>('button')).find((b) => b.textContent?.trim() === text && !b.closest('.hidden'))
|
|
80
|
+
const field = (label: string) => {
|
|
81
|
+
const element = Array.from(container.querySelectorAll('label')).find((l) => l.textContent === label)!
|
|
82
|
+
return document.getElementById(element.htmlFor) as HTMLInputElement
|
|
83
|
+
}
|
|
84
|
+
const type = (input: HTMLInputElement, value: string) => act(() => {
|
|
85
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, value)
|
|
86
|
+
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
87
|
+
})
|
|
88
|
+
const click = async (element: HTMLElement | undefined) => {
|
|
89
|
+
expect(element).toBeTruthy()
|
|
90
|
+
act(() => element!.click())
|
|
91
|
+
await flush()
|
|
92
|
+
}
|
|
93
|
+
const visibleText = () => Array.from(container.children).map((el) => (el as HTMLElement).innerText ?? el.textContent).join(' ')
|
|
94
|
+
const posts = () => calls.filter((c) => c.method === 'POST')
|
|
95
|
+
|
|
96
|
+
describe('Metrics backend choice', () => {
|
|
97
|
+
it('starts on OpenObserve when this cluster has a match, else on Prometheus-compatible', async () => {
|
|
98
|
+
await mount(matched())
|
|
99
|
+
expect(radio('OpenObserve').getAttribute('aria-checked')).toBe('true')
|
|
100
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('false')
|
|
101
|
+
expect(container.textContent).toContain('Prometheus, VictoriaMetrics, Thanos or Grafana Mimir.')
|
|
102
|
+
expect(container.textContent).toContain('Read this cluster’s metrics from OpenObserve, filtered to this cluster.')
|
|
103
|
+
act(() => root.unmount())
|
|
104
|
+
root = createRoot(container)
|
|
105
|
+
replies = {}
|
|
106
|
+
await mount(unmatched)
|
|
107
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('true')
|
|
108
|
+
expect(container.querySelector('[data-testid="prometheus-form"]')?.closest('.hidden')).toBeNull()
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('switches views without saving, and offers to release a matched cluster from the Prometheus view', async () => {
|
|
112
|
+
const onChanged = vi.fn()
|
|
113
|
+
await mount(matched(), { onChanged })
|
|
114
|
+
await click(radio('Prometheus-compatible'))
|
|
115
|
+
expect(calls.filter((c) => c.method !== 'GET')).toHaveLength(0)
|
|
116
|
+
expect(container.textContent).toContain('This cluster still reads from OpenObserve.')
|
|
117
|
+
reply('DELETE /integrations/openobserve/cluster?clusterUid=uid-123', { body: { connection: connection(), cluster: { uid: 'uid-123' } } })
|
|
118
|
+
await click(button('Use Prometheus for this cluster'))
|
|
119
|
+
expect(calls.at(-1)).toMatchObject({ method: 'DELETE', path: '/integrations/openobserve/cluster?clusterUid=uid-123' })
|
|
120
|
+
expect(onChanged).toHaveBeenCalled()
|
|
121
|
+
expect(container.textContent).not.toContain('This cluster still reads from OpenObserve.')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('falls back to Prometheus on a failed load, then follows the cluster match once Retry succeeds', async () => {
|
|
125
|
+
replies['GET /integrations/openobserve'] = [{ status: 500, body: { error: 'Radar is restarting' } }, { body: matched() }]
|
|
126
|
+
act(() => root.render(
|
|
127
|
+
<MetricsBackendSwitch onChanged={vi.fn()} status={<span>Status block</span>}
|
|
128
|
+
prometheus={() => <div data-testid="prometheus-form">Prometheus form</div>} />
|
|
129
|
+
))
|
|
130
|
+
await flush()
|
|
131
|
+
expect(container.textContent).toContain('Radar is restarting')
|
|
132
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('true')
|
|
133
|
+
await click(Array.from(container.querySelectorAll<HTMLButtonElement>('button')).find((b) => b.textContent === 'Retry'))
|
|
134
|
+
expect(radio('OpenObserve').getAttribute('aria-checked')).toBe('true')
|
|
135
|
+
expect(container.textContent).toContain('Matched by cluster ID (k8s_cluster_uid=uid-123)')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('shows the choice and status read-only when locked', async () => {
|
|
139
|
+
await mount(matched({ clusters: [{ context: 'a', by: 'id' }, { context: 'b', by: 'name' }] }), { locked: true })
|
|
140
|
+
expect(container.querySelectorAll('input, textarea, select')).toHaveLength(0)
|
|
141
|
+
const buttons = Array.from(container.querySelectorAll('button'))
|
|
142
|
+
expect(buttons.length).toBeGreaterThan(0)
|
|
143
|
+
expect(buttons.every((b) => b.disabled)).toBe(true)
|
|
144
|
+
expect(container.textContent).toContain('Status block')
|
|
145
|
+
expect(container.textContent).toContain('Matched by cluster ID (k8s_cluster_uid=uid-123)')
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('OpenObserve setup', () => {
|
|
150
|
+
it('tests and saves a first connection, then shows the match and notes', async () => {
|
|
151
|
+
const onChanged = vi.fn()
|
|
152
|
+
const onDirtyChange = vi.fn()
|
|
153
|
+
await mount(unmatched, { onChanged, onDirtyChange })
|
|
154
|
+
await click(radio('OpenObserve'))
|
|
155
|
+
expect(container.textContent).toContain('Saved in ~/.radar/config.json, readable only by you.')
|
|
156
|
+
const link = Array.from(container.querySelectorAll('a')).find((a) => a.textContent?.includes('Create a service account in OpenObserve'))!
|
|
157
|
+
expect(link.target).toBe('_blank')
|
|
158
|
+
expect(link.rel).toContain('noopener')
|
|
159
|
+
expect(field('Organization').value).toBe('default')
|
|
160
|
+
type(field('Address'), 'https://oo.example.com')
|
|
161
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
162
|
+
type(field('Token'), 'secret')
|
|
163
|
+
expect(field('Token').type).toBe('password')
|
|
164
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(true)
|
|
165
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', clusterUid: 'uid-123', notes: { collector: true, missing: ['cpu', 'hpa'] } } })
|
|
166
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
167
|
+
await click(button('Test and save'))
|
|
168
|
+
expect(posts()[0].body).toEqual({
|
|
169
|
+
baseUrl: 'https://oo.example.com', org: 'default', user: 'radar@example.com', token: 'secret', caCertFile: '', clusterLabel: '', clusterUid: 'uid-123',
|
|
170
|
+
})
|
|
171
|
+
expect(onChanged).toHaveBeenCalled()
|
|
172
|
+
expect(container.textContent).toContain('Data comes from the OpenObserve collector.')
|
|
173
|
+
// The status block carries coverage once the match settles; not repeated here.
|
|
174
|
+
expect(container.textContent).not.toContain('No data in OpenObserve for:')
|
|
175
|
+
expect(container.textContent).toContain('Matched by cluster ID (k8s_cluster_uid=uid-123)')
|
|
176
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(false)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('asks to confirm a name match and resends the same fields with the confirmation', async () => {
|
|
180
|
+
await mount(unmatched)
|
|
181
|
+
await click(radio('OpenObserve'))
|
|
182
|
+
type(field('Address'), 'https://oo.example.com')
|
|
183
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
184
|
+
type(field('Token'), 'secret')
|
|
185
|
+
reply('POST /integrations/openobserve/setup',
|
|
186
|
+
{ body: { outcome: 'confirm', reason: 'Found only by name.', suggestion: { label: 'k8s_cluster', value: 'prod' }, clusterUid: 'uid-123' } },
|
|
187
|
+
{ body: { outcome: 'saved', clusterUid: 'uid-123', notes: {} } })
|
|
188
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
189
|
+
await click(button('Test and save'))
|
|
190
|
+
expect(container.textContent).toContain('Found only by name.')
|
|
191
|
+
await click(button("Confirm 'prod' and save"))
|
|
192
|
+
expect(posts()).toHaveLength(2)
|
|
193
|
+
expect(posts()[1].body).toEqual({ ...posts()[0].body, confirm: { label: 'k8s_cluster', value: 'prod' } })
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('explains a cluster that was not found and saves nothing', async () => {
|
|
197
|
+
const onChanged = vi.fn()
|
|
198
|
+
await mount(unmatched, { onChanged })
|
|
199
|
+
await click(radio('OpenObserve'))
|
|
200
|
+
type(field('Address'), 'https://oo.example.com')
|
|
201
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
202
|
+
type(field('Token'), 'secret')
|
|
203
|
+
reply('POST /integrations/openobserve/setup', { body: {
|
|
204
|
+
outcome: 'not_found', reason: 'No metrics for this cluster.', clusterUid: 'uid-123',
|
|
205
|
+
clusterNames: [{ label: 'k8s_cluster', value: 'staging' }, { label: 'k8s_cluster', value: 'dev' }],
|
|
206
|
+
} })
|
|
207
|
+
await click(button('Test and save'))
|
|
208
|
+
const text = container.textContent!
|
|
209
|
+
expect(text).toContain('No metrics for this cluster.')
|
|
210
|
+
expect(text).toContain('OpenObserve has metrics for: k8s_cluster=staging, k8s_cluster=dev.')
|
|
211
|
+
expect(text).toContain('If OpenObserve names clusters with another label, set it under Advanced.')
|
|
212
|
+
expect(text).toContain('radar_cluster_uid=uid-123')
|
|
213
|
+
expect(text).not.toContain('Matched by')
|
|
214
|
+
expect(button('Test and save')).toBeTruthy()
|
|
215
|
+
expect(field('Token').value).toBe('secret')
|
|
216
|
+
expect(onChanged).not.toHaveBeenCalled()
|
|
217
|
+
expect(calls.map((c) => c.method)).toEqual(['GET', 'POST'])
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('does not claim OpenObserve is empty when the reason says what it found', async () => {
|
|
221
|
+
await mount(unmatched)
|
|
222
|
+
await click(radio('OpenObserve'))
|
|
223
|
+
type(field('Address'), 'https://oo.example.com')
|
|
224
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
225
|
+
type(field('Token'), 'secret')
|
|
226
|
+
reply('POST /integrations/openobserve/setup', { body: {
|
|
227
|
+
outcome: 'not_found', clusterUid: 'uid-123', clusterNames: [],
|
|
228
|
+
reason: '3 sampled Pods from namespace demo are in OpenObserve, but carry none of the cluster labels cluster.',
|
|
229
|
+
} })
|
|
230
|
+
await click(button('Test and save'))
|
|
231
|
+
const text = container.textContent!
|
|
232
|
+
expect(text).toContain('carry none of the cluster labels')
|
|
233
|
+
expect(text).not.toContain('OpenObserve has no cluster metrics yet.')
|
|
234
|
+
expect(text).toContain('radar_cluster_uid=uid-123')
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('says OpenObserve has no cluster metrics when there is no reason', async () => {
|
|
238
|
+
await mount(unmatched)
|
|
239
|
+
await click(radio('OpenObserve'))
|
|
240
|
+
type(field('Address'), 'https://oo.example.com')
|
|
241
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
242
|
+
type(field('Token'), 'secret')
|
|
243
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'not_found', clusterUid: 'uid-123', clusterNames: [] } })
|
|
244
|
+
await click(button('Test and save'))
|
|
245
|
+
expect(container.textContent).toContain('OpenObserve has no cluster metrics yet.')
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('shows an HTTP error and keeps the fields', async () => {
|
|
249
|
+
await mount(unmatched)
|
|
250
|
+
await click(radio('OpenObserve'))
|
|
251
|
+
type(field('Address'), 'https://oo.example.com')
|
|
252
|
+
reply('POST /integrations/openobserve/setup', { status: 400, body: { error: 'Login failed: 401 Unauthorized' } })
|
|
253
|
+
await click(button('Test and save'))
|
|
254
|
+
expect(container.querySelector('[role="alert"]')?.textContent).toBe('Login failed: 401 Unauthorized')
|
|
255
|
+
expect(field('Address').value).toBe('https://oo.example.com')
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it('notes a connection shared by several clusters', async () => {
|
|
259
|
+
await mount(matched({ clusters: [{ context: 'kind-oo-b', by: 'id' }, { context: 'kind-oo-c', by: 'name' }] }))
|
|
260
|
+
expect(visibleText()).toContain('Shared by 2 clusters. Changes apply to all of them.')
|
|
261
|
+
act(() => root.unmount())
|
|
262
|
+
root = createRoot(container)
|
|
263
|
+
replies = {}
|
|
264
|
+
await mount(matched())
|
|
265
|
+
expect(container.textContent).not.toContain('Shared by')
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('offers the saved connection to an unmatched cluster', async () => {
|
|
269
|
+
await mount({ connection: connection(), cluster: { uid: 'uid-123' } })
|
|
270
|
+
await click(radio('OpenObserve'))
|
|
271
|
+
expect(container.textContent).toContain('Use the saved OpenObserve connection (https://oo.example.com, user radar@example.com)')
|
|
272
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
273
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
274
|
+
await click(button('Test and save'))
|
|
275
|
+
expect(posts()[0].body).toEqual({ useSaved: true, clusterUid: 'uid-123' })
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
it('uses Prometheus for this cluster without a confirmation', async () => {
|
|
279
|
+
await mount(matched())
|
|
280
|
+
reply('DELETE /integrations/openobserve/cluster?clusterUid=uid-123', { body: { connection: connection(), cluster: { uid: 'uid-123' } } })
|
|
281
|
+
await click(button('Use Prometheus for this cluster'))
|
|
282
|
+
expect(calls.at(-1)).toMatchObject({ method: 'DELETE', path: '/integrations/openobserve/cluster?clusterUid=uid-123' })
|
|
283
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('true')
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it('asks before removing the saved connection, listing the clusters that use it', async () => {
|
|
287
|
+
await mount(matched({ clusters: [{ context: 'kind-oo-b', by: 'id' }, { context: 'kind-oo-c', by: 'name' }] }))
|
|
288
|
+
await click(button('Remove saved OpenObserve connection'))
|
|
289
|
+
expect(calls.some((c) => c.method === 'DELETE')).toBe(false)
|
|
290
|
+
const dialog = document.body.textContent!
|
|
291
|
+
expect(dialog).toContain('Remove the saved OpenObserve connection?')
|
|
292
|
+
expect(dialog).toContain('These clusters go back to their own Prometheus: kind-oo-b, kind-oo-c.')
|
|
293
|
+
reply('DELETE /integrations/openobserve', { body: unmatched })
|
|
294
|
+
await click(button('Remove'))
|
|
295
|
+
expect(calls.at(-1)).toMatchObject({ method: 'DELETE', path: '/integrations/openobserve' })
|
|
296
|
+
expect(field('Address').value).toBe('')
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
it('shows an environment token read-only and never sends a token for it', async () => {
|
|
300
|
+
await mount({ connection: connection({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }), cluster: { uid: 'uid-123' } })
|
|
301
|
+
await click(radio('OpenObserve'))
|
|
302
|
+
await click(button('Edit connection'))
|
|
303
|
+
expect(container.textContent).toContain('Token from $RADAR_OO_TOKEN')
|
|
304
|
+
expect(container.querySelector('input[type="password"]')).toBeNull()
|
|
305
|
+
expect(field('Address').value).toBe('https://oo.example.com')
|
|
306
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
307
|
+
replies['GET /integrations/openobserve'] = [{ body: matched({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }) }]
|
|
308
|
+
await click(button('Test and save'))
|
|
309
|
+
expect(posts()[0].body).not.toHaveProperty('token')
|
|
310
|
+
expect(posts()[0].body).toMatchObject({ baseUrl: 'https://oo.example.com', user: 'radar@example.com' })
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
it('asks for a new token when an environment-token connection points at another user', async () => {
|
|
314
|
+
await mount({ connection: connection({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }), cluster: { uid: 'uid-123' } })
|
|
315
|
+
await click(radio('OpenObserve'))
|
|
316
|
+
await click(button('Edit connection'))
|
|
317
|
+
type(field('User or service account email'), 'other@example.com')
|
|
318
|
+
expect(container.textContent).not.toContain('Token from $RADAR_OO_TOKEN')
|
|
319
|
+
expect(container.textContent).toContain('A new address, organization or user needs its own token.')
|
|
320
|
+
type(field('Token'), 'new-secret')
|
|
321
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
322
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
323
|
+
await click(button('Test and save'))
|
|
324
|
+
expect(posts()[0].body).toMatchObject({ user: 'other@example.com', token: 'new-secret', clusterUid: 'uid-123' })
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it('keeps "Saved" when the page cannot reload after a save', async () => {
|
|
328
|
+
await mount({ connection: connection(), cluster: { uid: 'uid-123' } })
|
|
329
|
+
await click(radio('OpenObserve'))
|
|
330
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
331
|
+
replies['GET /integrations/openobserve'] = [{ status: 500, body: { error: 'boom' } }]
|
|
332
|
+
await click(button('Test and save'))
|
|
333
|
+
expect(container.textContent).toContain("Saved, but Radar couldn't reload this page.")
|
|
334
|
+
expect(container.textContent).not.toContain('boom')
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
it('keeps a saved token when editing without typing one', async () => {
|
|
338
|
+
await mount(matched())
|
|
339
|
+
await click(button('Edit connection'))
|
|
340
|
+
expect(field('Token').placeholder).toBe('Saved — leave empty to keep')
|
|
341
|
+
expect(field('Token').value).toBe('')
|
|
342
|
+
})
|
|
343
|
+
})
|