@skyhook-io/radar-app 1.21.7 → 1.21.8
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 +2 -2
- package/src/App.tsx +12 -3
- package/src/api/client.ts +10 -3
- package/src/components/NamespaceSwitcher.tsx +6 -2
- package/src/components/applications/ApplicationsView.identity.test.ts +35 -7
- package/src/components/applications/ApplicationsView.tsx +71 -142
- package/src/components/cnpg/CNPGOperatorConditions.test.tsx +3 -0
- package/src/components/cnpg/CNPGOperatorConditions.tsx +4 -14
- package/src/components/home/HomeView.tsx +9 -1
- package/src/components/home/ProblemsPanel.investigate.test.tsx +12 -2
- package/src/components/issues/IssuesPane.render.test.tsx +78 -2
- package/src/components/issues/IssuesPane.tsx +38 -6
- package/src/components/settings/FormSaveActions.tsx +6 -2
- package/src/components/settings/MetricsBackendSwitch.tsx +13 -15
- package/src/components/settings/OpenObserveSetup.test.tsx +68 -27
- package/src/components/settings/OpenObserveSetup.tsx +93 -123
- package/src/components/workload/WorkloadView.tsx +8 -6
- package/src/components/workspace/WorkspaceConditions.tsx +56 -0
- package/src/components/workspace/layout.test.tsx +20 -0
- package/src/components/workspace/layout.tsx +1 -1
- package/src/contexts/CapabilitiesContext.tsx +2 -0
- package/src/utils/page-links.ts +15 -1
|
@@ -1,19 +1,26 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
1
4
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
5
|
import { renderToString } from 'react-dom/server'
|
|
3
|
-
import { MemoryRouter } from 'react-router-dom'
|
|
6
|
+
import { createMemoryRouter, MemoryRouter, RouterProvider } from 'react-router-dom'
|
|
7
|
+
import type { IssueAppInventoryRow } from '@skyhook-io/k8s-ui/components/issues'
|
|
4
8
|
import type { IssuesResponse, SubjectIssuesResponse } from '../../api/client'
|
|
5
9
|
import { IssuesPane } from './IssuesPane'
|
|
6
10
|
|
|
7
11
|
const state = vi.hoisted(() => ({
|
|
12
|
+
applications: vi.fn<() => { data?: { applications: IssueAppInventoryRow[] } }>(() => ({})),
|
|
8
13
|
fleet: { data: undefined as IssuesResponse | undefined, isLoading: false, error: null as Error | null, dataUpdatedAt: 0, refetch: vi.fn() },
|
|
9
14
|
subject: { data: undefined as SubjectIssuesResponse | undefined, isLoading: false, error: null as Error | null, dataUpdatedAt: 0, refetch: vi.fn() },
|
|
10
15
|
}))
|
|
11
|
-
vi.mock('../../api/client', () => ({ useIssues: () => state.fleet, useSubjectIssues: () => state.subject, useIssueCorrelation: () => ({ data: undefined, error: null, isFetching: false, dataUpdatedAt: 0, refetch: vi.fn() }), useIssueRowChanges: () => undefined }))
|
|
16
|
+
vi.mock('../../api/client', () => ({ useApplications: state.applications, useIssues: () => state.fleet, useSubjectIssues: () => state.subject, useIssueCorrelation: () => ({ data: undefined, error: null, isFetching: false, dataUpdatedAt: 0, refetch: vi.fn() }), useIssueRowChanges: () => undefined }))
|
|
12
17
|
vi.mock('../../api/apiResources', () => ({ useAPIResources: () => ({ data: undefined }), karpenterCapacityAvailable: () => false }))
|
|
13
18
|
vi.mock('../../contexts/CapabilitiesContext', () => ({ useCapabilitiesContext: () => ({}) }))
|
|
14
19
|
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { state: 'connected' } }) }))
|
|
15
20
|
vi.mock('../diagnose/LocalDiagnoseAction', () => ({ IssueDiagnoseButton: () => null }))
|
|
16
21
|
|
|
22
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
23
|
+
|
|
17
24
|
const subjectUrl = '/issues?kind=Pod&resource=db%2Fpg-1'
|
|
18
25
|
const issue = {
|
|
19
26
|
id: 'pod-failed', severity: 'critical' as const, source: 'problem', category: 'workload', category_group: 'workload', grouping_scope: 'resource',
|
|
@@ -25,11 +32,80 @@ function render(url = subjectUrl, namespaces: string[] = []) {
|
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
beforeEach(() => {
|
|
35
|
+
state.applications.mockClear()
|
|
28
36
|
state.fleet = { data: undefined, isLoading: false, error: null, dataUpdatedAt: 0, refetch: vi.fn() }
|
|
29
37
|
state.subject = { data: { issues: [issue], coverage: 'ok' }, isLoading: false, error: null, dataUpdatedAt: 0, refetch: vi.fn() }
|
|
30
38
|
})
|
|
31
39
|
|
|
32
40
|
describe('Issues page query ownership', () => {
|
|
41
|
+
it('only requests scoped application inventory for lists that can group', () => {
|
|
42
|
+
state.fleet.data = { issues: [issue] }
|
|
43
|
+
render('/issues', ['db'])
|
|
44
|
+
expect(state.applications).toHaveBeenLastCalledWith(['db'], { enabled: false })
|
|
45
|
+
state.fleet.data.issues.push({ ...issue, id: 'other' })
|
|
46
|
+
render('/issues', ['db'])
|
|
47
|
+
expect(state.applications).toHaveBeenLastCalledWith(['db'], { enabled: true })
|
|
48
|
+
render(subjectUrl, ['db'])
|
|
49
|
+
expect(state.applications).toHaveBeenLastCalledWith(['db'], { enabled: false })
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('links the panel to its exact application within the selected namespaces', () => {
|
|
53
|
+
const key = 'helm/db/checkout+api'
|
|
54
|
+
const workload = { kind: 'Deployment', name: 'checkout-api', namespace: 'db', group: 'apps' }
|
|
55
|
+
state.applications.mockReturnValueOnce({ data: { applications: [{ key, name: 'checkout', workloads: [workload] }] } })
|
|
56
|
+
const first = { ...issue, ...workload, grouping_scope: 'workload' }
|
|
57
|
+
state.fleet.data = { issues: [first, { ...first, id: 'other' }] }
|
|
58
|
+
|
|
59
|
+
const container = document.createElement('div')
|
|
60
|
+
container.innerHTML = render('/issues?issue=other', ['db', 'test'])
|
|
61
|
+
const link = container.querySelector<HTMLAnchorElement>('h2 a')!
|
|
62
|
+
expect(link.textContent).toBe('Open checkout application')
|
|
63
|
+
const url = new URL(link.href)
|
|
64
|
+
expect(url.pathname).toBe('/applications')
|
|
65
|
+
expect(Object.fromEntries(url.searchParams)).toEqual({ app: key, namespaces: 'db,test' })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('replaces a link when triaging and reveals the next linked issue through an active filter', async () => {
|
|
69
|
+
state.fleet.data = { issues: [issue, { ...issue, id: 'replicas', severity: 'warning', reason: 'Unavailable' }] }
|
|
70
|
+
const router = createMemoryRouter([
|
|
71
|
+
{ path: '/', element: <div>Home</div> },
|
|
72
|
+
{ path: '/issues', element: <IssuesPane namespaces={['db']} onNavigateToResource={() => {}} /> },
|
|
73
|
+
], { initialEntries: ['/', '/issues?namespaces=db&issue=pod-failed'], initialIndex: 1 })
|
|
74
|
+
const container = document.createElement('div')
|
|
75
|
+
const root = createRoot(container)
|
|
76
|
+
const row = (id: string) => container.querySelector(`[data-app-issue-row=":${id}"]`)
|
|
77
|
+
const toggle = (id: string) => row(id)!.querySelector<HTMLElement>('[role=button][aria-expanded]')!
|
|
78
|
+
try {
|
|
79
|
+
await act(async () => { root.render(<RouterProvider router={router} />) })
|
|
80
|
+
expect(toggle('pod-failed').getAttribute('aria-expanded')).toBe('true')
|
|
81
|
+
await act(async () => { toggle('replicas').click() })
|
|
82
|
+
expect(router.state.location.search).toBe('?namespaces=db')
|
|
83
|
+
expect(toggle('replicas').getAttribute('aria-expanded')).toBe('true')
|
|
84
|
+
await act(async () => { await router.navigate(-1) })
|
|
85
|
+
expect(router.state.location.pathname).toBe('/')
|
|
86
|
+
|
|
87
|
+
await act(async () => { await router.navigate('/issues?namespaces=db&issue=replicas') })
|
|
88
|
+
const critical = [...container.querySelectorAll('button')].find(button => button.textContent === '1Critical')!
|
|
89
|
+
await act(async () => { critical.click() })
|
|
90
|
+
expect(row('replicas')).toBeNull()
|
|
91
|
+
expect(router.state.location.search).toBe('?namespaces=db')
|
|
92
|
+
await act(async () => { await router.navigate('/issues?namespaces=db&issue=replicas') })
|
|
93
|
+
expect(toggle('replicas').getAttribute('aria-expanded')).toBe('true')
|
|
94
|
+
expect(row('pod-failed')).toBeTruthy()
|
|
95
|
+
} finally {
|
|
96
|
+
await act(async () => { root.unmount() })
|
|
97
|
+
router.dispose()
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('explains a missing issue link while keeping the current issues visible', () => {
|
|
102
|
+
state.fleet.data = { issues: [issue] }
|
|
103
|
+
const html = render('/issues?issue=absent')
|
|
104
|
+
expect(html).toContain('The linked issue is outside the current results.')
|
|
105
|
+
expect(html).toContain(issue.message)
|
|
106
|
+
expect(render('/issues?issue=pod-failed')).not.toContain('outside the current results')
|
|
107
|
+
})
|
|
108
|
+
|
|
33
109
|
it.each(['loading', 'failed'] as const)('renders subject results while the fleet query is %s', (fleetState) => {
|
|
34
110
|
state.fleet.isLoading = fleetState === 'loading'
|
|
35
111
|
state.fleet.error = fleetState === 'failed' ? new Error('Fleet unavailable') : null
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
|
-
import { useNavigate, useSearchParams } from "react-router-dom";
|
|
3
|
-
import { useIssues, useSubjectIssues, type SubjectIssuesResponse } from "../../api/client";
|
|
2
|
+
import { Link, useNavigate, useSearchParams } from "react-router-dom";
|
|
3
|
+
import { useApplications, useIssues, useSubjectIssues, type SubjectIssuesResponse } from "../../api/client";
|
|
4
4
|
import {
|
|
5
5
|
useAPIResources,
|
|
6
6
|
karpenterCapacityAvailable,
|
|
@@ -22,12 +22,14 @@ import {
|
|
|
22
22
|
type IssueSeverity,
|
|
23
23
|
type SummaryTone,
|
|
24
24
|
} from "@skyhook-io/k8s-ui";
|
|
25
|
+
import { buildIssueAppIndex } from "@skyhook-io/k8s-ui/components/issues";
|
|
25
26
|
import { builtinGroupForKind } from "@skyhook-io/k8s-ui/utils/api-resources";
|
|
26
27
|
import { AlertTriangle } from "lucide-react";
|
|
27
28
|
import { IssueDiagnoseButton } from "../diagnose/LocalDiagnoseAction";
|
|
28
29
|
import { recordUsageEvent } from "../../api/usage-data";
|
|
29
30
|
import { uncheckedSourceLines, uncheckedSubjectWhy } from "./uncheckedSources";
|
|
30
31
|
import { UncheckedSourceHelp } from "./UncheckedSourceHelp";
|
|
32
|
+
import { useClearLinkedIssue } from "../../utils/page-links";
|
|
31
33
|
import { useIssueExpansion, useIssueRowNotes } from "./useIssueExpansion";
|
|
32
34
|
|
|
33
35
|
// A capacity-relevant issue links to its Karpenter diagnosis. Karpenter is
|
|
@@ -185,9 +187,16 @@ export function IssuesPane({
|
|
|
185
187
|
showNamespace,
|
|
186
188
|
}: IssuesPaneProps) {
|
|
187
189
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
190
|
+
const clearLinkedIssue = useClearLinkedIssue();
|
|
191
|
+
const linkedIssueId = searchParams.get("issue") || undefined;
|
|
188
192
|
const subject = useMemo(() => issueSubjectFromParams(searchParams), [searchParams]);
|
|
189
193
|
const { data, isLoading, isFetching, error, dataUpdatedAt, refetch } =
|
|
190
194
|
useIssues(namespaces, !subject);
|
|
195
|
+
const canGroup = !subject && (data?.issues.length ?? 0) > 1;
|
|
196
|
+
const { data: inventory } = useApplications(namespaces, { enabled: canGroup });
|
|
197
|
+
const appForIssue = useMemo(() => canGroup && inventory
|
|
198
|
+
? buildIssueAppIndex(inventory.applications, { complete: namespaces.length === 0 && inventory.access?.restricted === false })
|
|
199
|
+
: undefined, [canGroup, inventory, namespaces.length]);
|
|
191
200
|
const { connection } = useConnection();
|
|
192
201
|
const navigate = useNavigate();
|
|
193
202
|
const apiResources = useAPIResources();
|
|
@@ -199,6 +208,14 @@ export function IssuesPane({
|
|
|
199
208
|
new Set(),
|
|
200
209
|
);
|
|
201
210
|
|
|
211
|
+
// A new link reveals its target even if the last view filtered its severity.
|
|
212
|
+
// Removing the link after a click keeps the user's new choice intact.
|
|
213
|
+
const [previousLink, setPreviousLink] = useState(linkedIssueId);
|
|
214
|
+
if (previousLink !== linkedIssueId) {
|
|
215
|
+
setPreviousLink(linkedIssueId);
|
|
216
|
+
if (linkedIssueId && severityFilter.size) setSeverityFilter(new Set());
|
|
217
|
+
}
|
|
218
|
+
|
|
202
219
|
const subjectHidden =
|
|
203
220
|
!!subject?.namespace && namespaces.length > 0 && !namespaces.includes(subject.namespace);
|
|
204
221
|
const related = useSubjectIssues(subject, !subjectHidden);
|
|
@@ -228,6 +245,7 @@ export function IssuesPane({
|
|
|
228
245
|
setSearchParams(
|
|
229
246
|
(prev) => {
|
|
230
247
|
const next = new URLSearchParams(prev);
|
|
248
|
+
next.delete("issue");
|
|
231
249
|
next.delete("kind");
|
|
232
250
|
next.delete("apiGroup");
|
|
233
251
|
next.delete("resource");
|
|
@@ -236,13 +254,15 @@ export function IssuesPane({
|
|
|
236
254
|
{ replace: true },
|
|
237
255
|
);
|
|
238
256
|
|
|
239
|
-
const toggleSeverity = (s: IssueSeverity) =>
|
|
257
|
+
const toggleSeverity = (s: IssueSeverity) => {
|
|
258
|
+
clearLinkedIssue();
|
|
240
259
|
setSeverityFilter((prev) => {
|
|
241
260
|
const next = new Set(prev);
|
|
242
261
|
if (next.has(s)) next.delete(s);
|
|
243
262
|
else next.add(s);
|
|
244
263
|
return next;
|
|
245
264
|
});
|
|
265
|
+
};
|
|
246
266
|
|
|
247
267
|
const onResourceClick = (ref: IssueResourceRef) => {
|
|
248
268
|
recordUsageEvent({ type: "ui", name: "issue_action:open" });
|
|
@@ -271,7 +291,7 @@ export function IssuesPane({
|
|
|
271
291
|
<PageHeader
|
|
272
292
|
icon={AlertTriangle}
|
|
273
293
|
title="Issues"
|
|
274
|
-
description="Live cluster problems
|
|
294
|
+
description="Live cluster problems, with critical issues first."
|
|
275
295
|
actions={
|
|
276
296
|
<>
|
|
277
297
|
{subjectHidden ? null : <FreshnessControl
|
|
@@ -307,6 +327,10 @@ export function IssuesPane({
|
|
|
307
327
|
}
|
|
308
328
|
/>
|
|
309
329
|
|
|
330
|
+
{!subject && linkedIssueId && data && !pageIssues.some((issue) => issue.id === linkedIssueId) && (
|
|
331
|
+
<p className="text-sm text-theme-text-secondary">The linked issue is outside the current results.</p>
|
|
332
|
+
)}
|
|
333
|
+
|
|
310
334
|
{!subject && error && (
|
|
311
335
|
<div className="flex items-start gap-2 rounded-lg border border-theme-border bg-theme-elevated px-3 py-2 text-xs text-theme-text-secondary">
|
|
312
336
|
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-amber-500" aria-hidden />
|
|
@@ -363,7 +387,7 @@ export function IssuesPane({
|
|
|
363
387
|
{showNamespace && (
|
|
364
388
|
<button
|
|
365
389
|
type="button"
|
|
366
|
-
onClick={() => showNamespace.show(subject.namespace)}
|
|
390
|
+
onClick={() => { clearLinkedIssue(); showNamespace.show(subject.namespace); }}
|
|
367
391
|
className="text-accent-text hover:underline"
|
|
368
392
|
>
|
|
369
393
|
{showNamespace.mode === "add" ? "Add" : "Switch to"}{" "}
|
|
@@ -402,7 +426,7 @@ export function IssuesPane({
|
|
|
402
426
|
<p>No issues match the selected severity.</p>
|
|
403
427
|
<button
|
|
404
428
|
type="button"
|
|
405
|
-
onClick={() => setSeverityFilter(new Set())}
|
|
429
|
+
onClick={() => { clearLinkedIssue(); setSeverityFilter(new Set()); }}
|
|
406
430
|
className="text-xs text-skyhook-600 hover:text-skyhook-500 dark:text-skyhook-400"
|
|
407
431
|
>
|
|
408
432
|
Clear filter
|
|
@@ -428,6 +452,14 @@ export function IssuesPane({
|
|
|
428
452
|
list then means "nothing broken" rather than "not connected". */
|
|
429
453
|
<IssuesView
|
|
430
454
|
issues={shown}
|
|
455
|
+
appForIssue={appForIssue}
|
|
456
|
+
renderAppLink={(key, label) => {
|
|
457
|
+
const params = new URLSearchParams({ app: key });
|
|
458
|
+
if (namespaces.length) params.set("namespaces", namespaces.join(","));
|
|
459
|
+
return <Link to={{ pathname: "/applications", search: params.toString() }}>{label}</Link>;
|
|
460
|
+
}}
|
|
461
|
+
linkedIssueId={linkedIssueId}
|
|
462
|
+
onManualIssueToggle={clearLinkedIssue}
|
|
431
463
|
anyData={subject ? !!related.data : !!data}
|
|
432
464
|
onResourceClick={onResourceClick}
|
|
433
465
|
onOpenIssueChange={expansion.onOpenIssueChange}
|
|
@@ -13,6 +13,8 @@ export function FormSaveActions({
|
|
|
13
13
|
onDiscard,
|
|
14
14
|
feedback,
|
|
15
15
|
error,
|
|
16
|
+
saveLabel = "Save changes",
|
|
17
|
+
canSave = dirty,
|
|
16
18
|
}: {
|
|
17
19
|
dirty: boolean;
|
|
18
20
|
busy: boolean;
|
|
@@ -20,6 +22,8 @@ export function FormSaveActions({
|
|
|
20
22
|
onDiscard: () => void;
|
|
21
23
|
feedback?: FormFeedback;
|
|
22
24
|
error?: string;
|
|
25
|
+
saveLabel?: string;
|
|
26
|
+
canSave?: boolean;
|
|
23
27
|
}) {
|
|
24
28
|
const success = !dirty && !busy && !error && feedback?.tone === "success";
|
|
25
29
|
const detail =
|
|
@@ -29,11 +33,11 @@ export function FormSaveActions({
|
|
|
29
33
|
<div className="flex min-h-8 flex-wrap items-center gap-3">
|
|
30
34
|
<button
|
|
31
35
|
type="button"
|
|
32
|
-
disabled={!
|
|
36
|
+
disabled={!canSave || busy}
|
|
33
37
|
onClick={onSave}
|
|
34
38
|
className="btn-brand min-w-28 px-3 py-2 text-xs"
|
|
35
39
|
>
|
|
36
|
-
{busy ? "Saving…" :
|
|
40
|
+
{busy ? "Saving…" : saveLabel}
|
|
37
41
|
</button>
|
|
38
42
|
{success && (
|
|
39
43
|
<span
|
|
@@ -80,18 +80,12 @@ export function MetricsBackendSwitch({
|
|
|
80
80
|
onBusyChange?.(next || reported.current.ooBusy || reported.current.releasing)
|
|
81
81
|
}, [onBusyChange])
|
|
82
82
|
|
|
83
|
-
const releaseCluster =
|
|
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 () => {
|
|
83
|
+
const releaseCluster = async () => {
|
|
91
84
|
setReleasing(true)
|
|
92
85
|
setReleaseError('')
|
|
93
86
|
try {
|
|
94
|
-
await
|
|
87
|
+
setData(await removeOpenObserveCluster(data?.cluster.uid))
|
|
88
|
+
onChanged()
|
|
95
89
|
} catch (error) {
|
|
96
90
|
setReleaseError(error instanceof Error ? error.message : String(error))
|
|
97
91
|
} finally {
|
|
@@ -101,6 +95,8 @@ export function MetricsBackendSwitch({
|
|
|
101
95
|
|
|
102
96
|
const statusRow = status ? <div className="flex flex-wrap items-center gap-x-3 gap-y-1">{status}</div> : null
|
|
103
97
|
const matched = !!data?.cluster.match
|
|
98
|
+
// The status describes where metrics come from now, whichever view is open.
|
|
99
|
+
const active: Backend = matched ? 'openobserve' : 'prometheus'
|
|
104
100
|
|
|
105
101
|
return (
|
|
106
102
|
<div className="space-y-4">
|
|
@@ -133,25 +129,27 @@ export function MetricsBackendSwitch({
|
|
|
133
129
|
{matched && !locked && (
|
|
134
130
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs">
|
|
135
131
|
<span className="text-warning-text">This cluster still reads from OpenObserve.</span>
|
|
136
|
-
<button type="button" disabled={busy} onClick={() => void
|
|
132
|
+
<button type="button" disabled={busy} onClick={() => void releaseCluster()} className="text-accent-text hover:underline">
|
|
137
133
|
{releasing ? 'Switching…' : 'Use Prometheus for this cluster'}
|
|
138
134
|
</button>
|
|
139
135
|
{releaseError && <span role="alert" className="basis-full text-semantic-error">{releaseError}</span>}
|
|
140
136
|
</div>
|
|
141
137
|
)}
|
|
142
138
|
{locked
|
|
143
|
-
?
|
|
144
|
-
: prometheus({ status:
|
|
139
|
+
? active === 'prometheus' && statusRow
|
|
140
|
+
: prometheus({ status: active === 'prometheus' ? status : undefined, onDirtyChange: promDirtyChange, onBusyChange: promBusyChange })}
|
|
145
141
|
</div>
|
|
146
142
|
<div className={clsx(choice !== 'openobserve' && 'hidden')} inert={choice !== 'openobserve' || undefined}>
|
|
147
143
|
{data ? (
|
|
148
144
|
<OpenObserveSetup
|
|
149
145
|
state={data}
|
|
150
146
|
locked={locked}
|
|
151
|
-
status={
|
|
152
|
-
onStateChange={
|
|
147
|
+
status={active === 'openobserve' ? status : undefined}
|
|
148
|
+
onStateChange={(next) => {
|
|
149
|
+
setData(next)
|
|
150
|
+
if (!next.connection) setChoice('prometheus')
|
|
151
|
+
}}
|
|
153
152
|
onChanged={onChanged}
|
|
154
|
-
onUsePrometheus={releaseCluster}
|
|
155
153
|
onDirtyChange={setOoDirty}
|
|
156
154
|
onBusyChange={setOoBusy}
|
|
157
155
|
/>
|
|
@@ -108,9 +108,10 @@ describe('Metrics backend choice', () => {
|
|
|
108
108
|
expect(container.querySelector('[data-testid="prometheus-form"]')?.closest('.hidden')).toBeNull()
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
-
it('switches views without saving, and
|
|
111
|
+
it('switches views without saving, and releases a matched cluster from the Prometheus view without a confirmation', async () => {
|
|
112
112
|
const onChanged = vi.fn()
|
|
113
113
|
await mount(matched(), { onChanged })
|
|
114
|
+
expect(button('Use Prometheus for this cluster')).toBeUndefined()
|
|
114
115
|
await click(radio('Prometheus-compatible'))
|
|
115
116
|
expect(calls.filter((c) => c.method !== 'GET')).toHaveLength(0)
|
|
116
117
|
expect(container.textContent).toContain('This cluster still reads from OpenObserve.')
|
|
@@ -118,6 +119,7 @@ describe('Metrics backend choice', () => {
|
|
|
118
119
|
await click(button('Use Prometheus for this cluster'))
|
|
119
120
|
expect(calls.at(-1)).toMatchObject({ method: 'DELETE', path: '/integrations/openobserve/cluster?clusterUid=uid-123' })
|
|
120
121
|
expect(onChanged).toHaveBeenCalled()
|
|
122
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('true')
|
|
121
123
|
expect(container.textContent).not.toContain('This cluster still reads from OpenObserve.')
|
|
122
124
|
})
|
|
123
125
|
|
|
@@ -156,7 +158,9 @@ describe('OpenObserve setup', () => {
|
|
|
156
158
|
const link = Array.from(container.querySelectorAll('a')).find((a) => a.textContent?.includes('Create a service account in OpenObserve'))!
|
|
157
159
|
expect(link.target).toBe('_blank')
|
|
158
160
|
expect(link.rel).toContain('noopener')
|
|
159
|
-
expect(field('Organization').value).toBe('
|
|
161
|
+
expect(field('Organization').value).toBe('')
|
|
162
|
+
expect(field('Organization').placeholder).toBe('2Zp8kQ1vXcR7mN4tLwYb9HsA3eD')
|
|
163
|
+
type(field('Organization'), 'team')
|
|
160
164
|
type(field('Address'), 'https://oo.example.com')
|
|
161
165
|
type(field('User or service account email'), 'radar@example.com')
|
|
162
166
|
type(field('Token'), 'secret')
|
|
@@ -164,9 +168,9 @@ describe('OpenObserve setup', () => {
|
|
|
164
168
|
expect(onDirtyChange).toHaveBeenLastCalledWith(true)
|
|
165
169
|
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', clusterUid: 'uid-123', notes: { collector: true, missing: ['cpu', 'hpa'] } } })
|
|
166
170
|
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
167
|
-
await click(button('
|
|
171
|
+
await click(button('Save changes'))
|
|
168
172
|
expect(posts()[0].body).toEqual({
|
|
169
|
-
baseUrl: 'https://oo.example.com', org: '
|
|
173
|
+
baseUrl: 'https://oo.example.com', org: 'team', user: 'radar@example.com', token: 'secret', caCertFile: '', clusterLabel: '', clusterUid: 'uid-123',
|
|
170
174
|
})
|
|
171
175
|
expect(onChanged).toHaveBeenCalled()
|
|
172
176
|
expect(container.textContent).toContain('Data comes from the OpenObserve collector.')
|
|
@@ -186,7 +190,7 @@ describe('OpenObserve setup', () => {
|
|
|
186
190
|
{ body: { outcome: 'confirm', reason: 'Found only by name.', suggestion: { label: 'k8s_cluster', value: 'prod' }, clusterUid: 'uid-123' } },
|
|
187
191
|
{ body: { outcome: 'saved', clusterUid: 'uid-123', notes: {} } })
|
|
188
192
|
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
189
|
-
await click(button('
|
|
193
|
+
await click(button('Save changes'))
|
|
190
194
|
expect(container.textContent).toContain('Found only by name.')
|
|
191
195
|
await click(button("Confirm 'prod' and save"))
|
|
192
196
|
expect(posts()).toHaveLength(2)
|
|
@@ -204,14 +208,14 @@ describe('OpenObserve setup', () => {
|
|
|
204
208
|
outcome: 'not_found', reason: 'No metrics for this cluster.', clusterUid: 'uid-123',
|
|
205
209
|
clusterNames: [{ label: 'k8s_cluster', value: 'staging' }, { label: 'k8s_cluster', value: 'dev' }],
|
|
206
210
|
} })
|
|
207
|
-
await click(button('
|
|
211
|
+
await click(button('Save changes'))
|
|
208
212
|
const text = container.textContent!
|
|
209
213
|
expect(text).toContain('No metrics for this cluster.')
|
|
210
214
|
expect(text).toContain('OpenObserve has metrics for: k8s_cluster=staging, k8s_cluster=dev.')
|
|
211
215
|
expect(text).toContain('If OpenObserve names clusters with another label, set it under Advanced.')
|
|
212
216
|
expect(text).toContain('radar_cluster_uid=uid-123')
|
|
213
217
|
expect(text).not.toContain('Matched by')
|
|
214
|
-
expect(button('
|
|
218
|
+
expect(button('Save changes')).toBeTruthy()
|
|
215
219
|
expect(field('Token').value).toBe('secret')
|
|
216
220
|
expect(onChanged).not.toHaveBeenCalled()
|
|
217
221
|
expect(calls.map((c) => c.method)).toEqual(['GET', 'POST'])
|
|
@@ -227,7 +231,7 @@ describe('OpenObserve setup', () => {
|
|
|
227
231
|
outcome: 'not_found', clusterUid: 'uid-123', clusterNames: [],
|
|
228
232
|
reason: '3 sampled Pods from namespace demo are in OpenObserve, but carry none of the cluster labels cluster.',
|
|
229
233
|
} })
|
|
230
|
-
await click(button('
|
|
234
|
+
await click(button('Save changes'))
|
|
231
235
|
const text = container.textContent!
|
|
232
236
|
expect(text).toContain('carry none of the cluster labels')
|
|
233
237
|
expect(text).not.toContain('OpenObserve has no cluster metrics yet.')
|
|
@@ -241,7 +245,7 @@ describe('OpenObserve setup', () => {
|
|
|
241
245
|
type(field('User or service account email'), 'radar@example.com')
|
|
242
246
|
type(field('Token'), 'secret')
|
|
243
247
|
reply('POST /integrations/openobserve/setup', { body: { outcome: 'not_found', clusterUid: 'uid-123', clusterNames: [] } })
|
|
244
|
-
await click(button('
|
|
248
|
+
await click(button('Save changes'))
|
|
245
249
|
expect(container.textContent).toContain('OpenObserve has no cluster metrics yet.')
|
|
246
250
|
})
|
|
247
251
|
|
|
@@ -250,7 +254,7 @@ describe('OpenObserve setup', () => {
|
|
|
250
254
|
await click(radio('OpenObserve'))
|
|
251
255
|
type(field('Address'), 'https://oo.example.com')
|
|
252
256
|
reply('POST /integrations/openobserve/setup', { status: 400, body: { error: 'Login failed: 401 Unauthorized' } })
|
|
253
|
-
await click(button('
|
|
257
|
+
await click(button('Save changes'))
|
|
254
258
|
expect(container.querySelector('[role="alert"]')?.textContent).toBe('Login failed: 401 Unauthorized')
|
|
255
259
|
expect(field('Address').value).toBe('https://oo.example.com')
|
|
256
260
|
})
|
|
@@ -268,59 +272,80 @@ describe('OpenObserve setup', () => {
|
|
|
268
272
|
it('offers the saved connection to an unmatched cluster', async () => {
|
|
269
273
|
await mount({ connection: connection(), cluster: { uid: 'uid-123' } })
|
|
270
274
|
await click(radio('OpenObserve'))
|
|
271
|
-
expect(
|
|
275
|
+
expect(field('Address').value).toBe('https://oo.example.com')
|
|
272
276
|
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
273
277
|
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
274
|
-
await click(button('
|
|
278
|
+
await click(button('Use for this cluster'))
|
|
275
279
|
expect(posts()[0].body).toEqual({ useSaved: true, clusterUid: 'uid-123' })
|
|
276
280
|
})
|
|
277
281
|
|
|
278
|
-
it('
|
|
279
|
-
await mount(
|
|
282
|
+
it('drops the Saved note once this cluster switches back to Prometheus', async () => {
|
|
283
|
+
await mount({ connection: connection(), cluster: { uid: 'uid-123' } })
|
|
284
|
+
await click(radio('OpenObserve'))
|
|
285
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: { collector: true } } })
|
|
286
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
287
|
+
await click(button('Use for this cluster'))
|
|
288
|
+
expect(container.textContent).toContain('Data comes from the OpenObserve collector.')
|
|
289
|
+
await click(radio('Prometheus-compatible'))
|
|
280
290
|
reply('DELETE /integrations/openobserve/cluster?clusterUid=uid-123', { body: { connection: connection(), cluster: { uid: 'uid-123' } } })
|
|
281
291
|
await click(button('Use Prometheus for this cluster'))
|
|
282
|
-
|
|
283
|
-
expect(
|
|
292
|
+
await click(radio('OpenObserve'))
|
|
293
|
+
expect(container.textContent).not.toContain('Data comes from the OpenObserve collector.')
|
|
294
|
+
expect(Array.from(container.querySelectorAll('[role="status"]')).some((el) => el.textContent?.trim() === 'Saved')).toBe(false)
|
|
284
295
|
})
|
|
285
296
|
|
|
286
297
|
it('asks before removing the saved connection, listing the clusters that use it', async () => {
|
|
287
298
|
await mount(matched({ clusters: [{ context: 'kind-oo-b', by: 'id' }, { context: 'kind-oo-c', by: 'name' }] }))
|
|
288
|
-
await click(button('Remove
|
|
299
|
+
await click(button('Remove OpenObserve connection'))
|
|
289
300
|
expect(calls.some((c) => c.method === 'DELETE')).toBe(false)
|
|
290
301
|
const dialog = document.body.textContent!
|
|
291
302
|
expect(dialog).toContain('Remove the saved OpenObserve connection?')
|
|
292
|
-
expect(dialog).toContain('These clusters go back to their
|
|
303
|
+
expect(dialog).toContain('These clusters go back to their Prometheus settings: kind-oo-b, kind-oo-c. Nothing is deleted in OpenObserve or Kubernetes.')
|
|
293
304
|
reply('DELETE /integrations/openobserve', { body: unmatched })
|
|
294
|
-
await click(button('Remove'))
|
|
305
|
+
await click(button('Remove connection'))
|
|
295
306
|
expect(calls.at(-1)).toMatchObject({ method: 'DELETE', path: '/integrations/openobserve' })
|
|
296
307
|
expect(field('Address').value).toBe('')
|
|
308
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('true')
|
|
309
|
+
expect(container.querySelector('[data-testid="prometheus-form"]')?.textContent).toContain('Status block')
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('shows the live status only with the source metrics come from', async () => {
|
|
313
|
+
await mount(unmatched)
|
|
314
|
+
await click(radio('OpenObserve'))
|
|
315
|
+
expect(container.querySelector('fieldset[aria-label="OpenObserve connection settings"]')?.textContent).not.toContain('Status block')
|
|
316
|
+
expect(container.querySelector('[data-testid="prometheus-form"]')?.textContent).toContain('Status block')
|
|
317
|
+
act(() => root.unmount())
|
|
318
|
+
root = createRoot(container)
|
|
319
|
+
replies = {}
|
|
320
|
+
await mount(matched())
|
|
321
|
+
await click(radio('Prometheus-compatible'))
|
|
322
|
+
expect(container.querySelector('[data-testid="prometheus-form"]')?.textContent).not.toContain('Status block')
|
|
323
|
+
expect(container.querySelector('fieldset[aria-label="OpenObserve connection settings"]')?.textContent).toContain('Status block')
|
|
297
324
|
})
|
|
298
325
|
|
|
299
326
|
it('shows an environment token read-only and never sends a token for it', async () => {
|
|
300
327
|
await mount({ connection: connection({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }), cluster: { uid: 'uid-123' } })
|
|
301
328
|
await click(radio('OpenObserve'))
|
|
302
|
-
await click(button('Edit connection'))
|
|
303
329
|
expect(container.textContent).toContain('Token from $RADAR_OO_TOKEN')
|
|
304
330
|
expect(container.querySelector('input[type="password"]')).toBeNull()
|
|
305
|
-
|
|
331
|
+
type(field('Organization'), 'team')
|
|
306
332
|
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
307
333
|
replies['GET /integrations/openobserve'] = [{ body: matched({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }) }]
|
|
308
|
-
await click(button('
|
|
334
|
+
await click(button('Save changes'))
|
|
309
335
|
expect(posts()[0].body).not.toHaveProperty('token')
|
|
310
|
-
expect(posts()[0].body).toMatchObject({ baseUrl: 'https://oo.example.com', user: 'radar@example.com' })
|
|
336
|
+
expect(posts()[0].body).toMatchObject({ baseUrl: 'https://oo.example.com', org: 'team', user: 'radar@example.com' })
|
|
311
337
|
})
|
|
312
338
|
|
|
313
339
|
it('asks for a new token when an environment-token connection points at another user', async () => {
|
|
314
340
|
await mount({ connection: connection({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }), cluster: { uid: 'uid-123' } })
|
|
315
341
|
await click(radio('OpenObserve'))
|
|
316
|
-
await click(button('Edit connection'))
|
|
317
342
|
type(field('User or service account email'), 'other@example.com')
|
|
318
343
|
expect(container.textContent).not.toContain('Token from $RADAR_OO_TOKEN')
|
|
319
344
|
expect(container.textContent).toContain('A new address, organization or user needs its own token.')
|
|
320
345
|
type(field('Token'), 'new-secret')
|
|
321
346
|
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
322
347
|
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
323
|
-
await click(button('
|
|
348
|
+
await click(button('Save changes'))
|
|
324
349
|
expect(posts()[0].body).toMatchObject({ user: 'other@example.com', token: 'new-secret', clusterUid: 'uid-123' })
|
|
325
350
|
})
|
|
326
351
|
|
|
@@ -329,15 +354,31 @@ describe('OpenObserve setup', () => {
|
|
|
329
354
|
await click(radio('OpenObserve'))
|
|
330
355
|
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
331
356
|
replies['GET /integrations/openobserve'] = [{ status: 500, body: { error: 'boom' } }]
|
|
332
|
-
await click(button('
|
|
357
|
+
await click(button('Use for this cluster'))
|
|
333
358
|
expect(container.textContent).toContain("Saved, but Radar couldn't reload this page.")
|
|
334
359
|
expect(container.textContent).not.toContain('boom')
|
|
335
360
|
})
|
|
336
361
|
|
|
337
362
|
it('keeps a saved token when editing without typing one', async () => {
|
|
338
363
|
await mount(matched())
|
|
339
|
-
await click(button('Edit connection'))
|
|
340
364
|
expect(field('Token').placeholder).toBe('Saved — leave empty to keep')
|
|
341
365
|
expect(field('Token').value).toBe('')
|
|
342
366
|
})
|
|
367
|
+
it('shows a saved connection filled in, saving only after a change, and discards back to it', async () => {
|
|
368
|
+
const onDirtyChange = vi.fn()
|
|
369
|
+
await mount(matched(), { onDirtyChange })
|
|
370
|
+
expect(field('Address').value).toBe('https://oo.example.com')
|
|
371
|
+
expect(field('User or service account email').value).toBe('radar@example.com')
|
|
372
|
+
expect(button('Edit connection')).toBeUndefined()
|
|
373
|
+
expect(button('Save changes')!.disabled).toBe(true)
|
|
374
|
+
expect(button('Discard')).toBeUndefined()
|
|
375
|
+
type(field('Address'), 'https://oo2.example.com')
|
|
376
|
+
expect(button('Save changes')!.disabled).toBe(false)
|
|
377
|
+
expect(container.textContent).toContain('Unsaved changes')
|
|
378
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(true)
|
|
379
|
+
await click(button('Discard'))
|
|
380
|
+
expect(field('Address').value).toBe('https://oo.example.com')
|
|
381
|
+
expect(button('Save changes')!.disabled).toBe(true)
|
|
382
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(false)
|
|
383
|
+
})
|
|
343
384
|
})
|