@skyhook-io/radar-app 1.21.6 → 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 +7 -7
- package/src/App.tsx +31 -4
- 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 +582 -114
- 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/NamespaceSwitcher.tsx +6 -2
- package/src/components/applications/ApplicationsView.identity.test.ts +35 -7
- package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
- package/src/components/applications/ApplicationsView.tsx +127 -173
- package/src/components/cnpg/CNPGOperatorConditions.test.tsx +3 -0
- package/src/components/cnpg/CNPGOperatorConditions.tsx +4 -14
- 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/HomeView.tsx +9 -1
- package/src/components/home/ProblemsPanel.investigate.test.tsx +12 -2
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/issues/IssuesPane.render.test.tsx +78 -2
- package/src/components/issues/IssuesPane.tsx +49 -6
- 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/FormSaveActions.tsx +6 -2
- package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
- package/src/components/settings/MetricsBackendSwitch.tsx +165 -0
- package/src/components/settings/OpenObserveSetup.test.tsx +384 -0
- package/src/components/settings/OpenObserveSetup.tsx +328 -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 +103 -16
- 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/context/TimelineNavigation.test.ts +59 -0
- package/src/context/TimelineNavigation.tsx +86 -0
- package/src/contexts/CapabilitiesContext.tsx +5 -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/utils/page-links.ts +15 -1
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
|
@@ -0,0 +1,384 @@
|
|
|
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 releases a matched cluster from the Prometheus view without a confirmation', async () => {
|
|
112
|
+
const onChanged = vi.fn()
|
|
113
|
+
await mount(matched(), { onChanged })
|
|
114
|
+
expect(button('Use Prometheus for this cluster')).toBeUndefined()
|
|
115
|
+
await click(radio('Prometheus-compatible'))
|
|
116
|
+
expect(calls.filter((c) => c.method !== 'GET')).toHaveLength(0)
|
|
117
|
+
expect(container.textContent).toContain('This cluster still reads from OpenObserve.')
|
|
118
|
+
reply('DELETE /integrations/openobserve/cluster?clusterUid=uid-123', { body: { connection: connection(), cluster: { uid: 'uid-123' } } })
|
|
119
|
+
await click(button('Use Prometheus for this cluster'))
|
|
120
|
+
expect(calls.at(-1)).toMatchObject({ method: 'DELETE', path: '/integrations/openobserve/cluster?clusterUid=uid-123' })
|
|
121
|
+
expect(onChanged).toHaveBeenCalled()
|
|
122
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('true')
|
|
123
|
+
expect(container.textContent).not.toContain('This cluster still reads from OpenObserve.')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('falls back to Prometheus on a failed load, then follows the cluster match once Retry succeeds', async () => {
|
|
127
|
+
replies['GET /integrations/openobserve'] = [{ status: 500, body: { error: 'Radar is restarting' } }, { body: matched() }]
|
|
128
|
+
act(() => root.render(
|
|
129
|
+
<MetricsBackendSwitch onChanged={vi.fn()} status={<span>Status block</span>}
|
|
130
|
+
prometheus={() => <div data-testid="prometheus-form">Prometheus form</div>} />
|
|
131
|
+
))
|
|
132
|
+
await flush()
|
|
133
|
+
expect(container.textContent).toContain('Radar is restarting')
|
|
134
|
+
expect(radio('Prometheus-compatible').getAttribute('aria-checked')).toBe('true')
|
|
135
|
+
await click(Array.from(container.querySelectorAll<HTMLButtonElement>('button')).find((b) => b.textContent === 'Retry'))
|
|
136
|
+
expect(radio('OpenObserve').getAttribute('aria-checked')).toBe('true')
|
|
137
|
+
expect(container.textContent).toContain('Matched by cluster ID (k8s_cluster_uid=uid-123)')
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('shows the choice and status read-only when locked', async () => {
|
|
141
|
+
await mount(matched({ clusters: [{ context: 'a', by: 'id' }, { context: 'b', by: 'name' }] }), { locked: true })
|
|
142
|
+
expect(container.querySelectorAll('input, textarea, select')).toHaveLength(0)
|
|
143
|
+
const buttons = Array.from(container.querySelectorAll('button'))
|
|
144
|
+
expect(buttons.length).toBeGreaterThan(0)
|
|
145
|
+
expect(buttons.every((b) => b.disabled)).toBe(true)
|
|
146
|
+
expect(container.textContent).toContain('Status block')
|
|
147
|
+
expect(container.textContent).toContain('Matched by cluster ID (k8s_cluster_uid=uid-123)')
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
describe('OpenObserve setup', () => {
|
|
152
|
+
it('tests and saves a first connection, then shows the match and notes', async () => {
|
|
153
|
+
const onChanged = vi.fn()
|
|
154
|
+
const onDirtyChange = vi.fn()
|
|
155
|
+
await mount(unmatched, { onChanged, onDirtyChange })
|
|
156
|
+
await click(radio('OpenObserve'))
|
|
157
|
+
expect(container.textContent).toContain('Saved in ~/.radar/config.json, readable only by you.')
|
|
158
|
+
const link = Array.from(container.querySelectorAll('a')).find((a) => a.textContent?.includes('Create a service account in OpenObserve'))!
|
|
159
|
+
expect(link.target).toBe('_blank')
|
|
160
|
+
expect(link.rel).toContain('noopener')
|
|
161
|
+
expect(field('Organization').value).toBe('')
|
|
162
|
+
expect(field('Organization').placeholder).toBe('2Zp8kQ1vXcR7mN4tLwYb9HsA3eD')
|
|
163
|
+
type(field('Organization'), 'team')
|
|
164
|
+
type(field('Address'), 'https://oo.example.com')
|
|
165
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
166
|
+
type(field('Token'), 'secret')
|
|
167
|
+
expect(field('Token').type).toBe('password')
|
|
168
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(true)
|
|
169
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', clusterUid: 'uid-123', notes: { collector: true, missing: ['cpu', 'hpa'] } } })
|
|
170
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
171
|
+
await click(button('Save changes'))
|
|
172
|
+
expect(posts()[0].body).toEqual({
|
|
173
|
+
baseUrl: 'https://oo.example.com', org: 'team', user: 'radar@example.com', token: 'secret', caCertFile: '', clusterLabel: '', clusterUid: 'uid-123',
|
|
174
|
+
})
|
|
175
|
+
expect(onChanged).toHaveBeenCalled()
|
|
176
|
+
expect(container.textContent).toContain('Data comes from the OpenObserve collector.')
|
|
177
|
+
// The status block carries coverage once the match settles; not repeated here.
|
|
178
|
+
expect(container.textContent).not.toContain('No data in OpenObserve for:')
|
|
179
|
+
expect(container.textContent).toContain('Matched by cluster ID (k8s_cluster_uid=uid-123)')
|
|
180
|
+
expect(onDirtyChange).toHaveBeenLastCalledWith(false)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('asks to confirm a name match and resends the same fields with the confirmation', async () => {
|
|
184
|
+
await mount(unmatched)
|
|
185
|
+
await click(radio('OpenObserve'))
|
|
186
|
+
type(field('Address'), 'https://oo.example.com')
|
|
187
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
188
|
+
type(field('Token'), 'secret')
|
|
189
|
+
reply('POST /integrations/openobserve/setup',
|
|
190
|
+
{ body: { outcome: 'confirm', reason: 'Found only by name.', suggestion: { label: 'k8s_cluster', value: 'prod' }, clusterUid: 'uid-123' } },
|
|
191
|
+
{ body: { outcome: 'saved', clusterUid: 'uid-123', notes: {} } })
|
|
192
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
193
|
+
await click(button('Save changes'))
|
|
194
|
+
expect(container.textContent).toContain('Found only by name.')
|
|
195
|
+
await click(button("Confirm 'prod' and save"))
|
|
196
|
+
expect(posts()).toHaveLength(2)
|
|
197
|
+
expect(posts()[1].body).toEqual({ ...posts()[0].body, confirm: { label: 'k8s_cluster', value: 'prod' } })
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('explains a cluster that was not found and saves nothing', async () => {
|
|
201
|
+
const onChanged = vi.fn()
|
|
202
|
+
await mount(unmatched, { onChanged })
|
|
203
|
+
await click(radio('OpenObserve'))
|
|
204
|
+
type(field('Address'), 'https://oo.example.com')
|
|
205
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
206
|
+
type(field('Token'), 'secret')
|
|
207
|
+
reply('POST /integrations/openobserve/setup', { body: {
|
|
208
|
+
outcome: 'not_found', reason: 'No metrics for this cluster.', clusterUid: 'uid-123',
|
|
209
|
+
clusterNames: [{ label: 'k8s_cluster', value: 'staging' }, { label: 'k8s_cluster', value: 'dev' }],
|
|
210
|
+
} })
|
|
211
|
+
await click(button('Save changes'))
|
|
212
|
+
const text = container.textContent!
|
|
213
|
+
expect(text).toContain('No metrics for this cluster.')
|
|
214
|
+
expect(text).toContain('OpenObserve has metrics for: k8s_cluster=staging, k8s_cluster=dev.')
|
|
215
|
+
expect(text).toContain('If OpenObserve names clusters with another label, set it under Advanced.')
|
|
216
|
+
expect(text).toContain('radar_cluster_uid=uid-123')
|
|
217
|
+
expect(text).not.toContain('Matched by')
|
|
218
|
+
expect(button('Save changes')).toBeTruthy()
|
|
219
|
+
expect(field('Token').value).toBe('secret')
|
|
220
|
+
expect(onChanged).not.toHaveBeenCalled()
|
|
221
|
+
expect(calls.map((c) => c.method)).toEqual(['GET', 'POST'])
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('does not claim OpenObserve is empty when the reason says what it found', async () => {
|
|
225
|
+
await mount(unmatched)
|
|
226
|
+
await click(radio('OpenObserve'))
|
|
227
|
+
type(field('Address'), 'https://oo.example.com')
|
|
228
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
229
|
+
type(field('Token'), 'secret')
|
|
230
|
+
reply('POST /integrations/openobserve/setup', { body: {
|
|
231
|
+
outcome: 'not_found', clusterUid: 'uid-123', clusterNames: [],
|
|
232
|
+
reason: '3 sampled Pods from namespace demo are in OpenObserve, but carry none of the cluster labels cluster.',
|
|
233
|
+
} })
|
|
234
|
+
await click(button('Save changes'))
|
|
235
|
+
const text = container.textContent!
|
|
236
|
+
expect(text).toContain('carry none of the cluster labels')
|
|
237
|
+
expect(text).not.toContain('OpenObserve has no cluster metrics yet.')
|
|
238
|
+
expect(text).toContain('radar_cluster_uid=uid-123')
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
it('says OpenObserve has no cluster metrics when there is no reason', async () => {
|
|
242
|
+
await mount(unmatched)
|
|
243
|
+
await click(radio('OpenObserve'))
|
|
244
|
+
type(field('Address'), 'https://oo.example.com')
|
|
245
|
+
type(field('User or service account email'), 'radar@example.com')
|
|
246
|
+
type(field('Token'), 'secret')
|
|
247
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'not_found', clusterUid: 'uid-123', clusterNames: [] } })
|
|
248
|
+
await click(button('Save changes'))
|
|
249
|
+
expect(container.textContent).toContain('OpenObserve has no cluster metrics yet.')
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('shows an HTTP error and keeps the fields', async () => {
|
|
253
|
+
await mount(unmatched)
|
|
254
|
+
await click(radio('OpenObserve'))
|
|
255
|
+
type(field('Address'), 'https://oo.example.com')
|
|
256
|
+
reply('POST /integrations/openobserve/setup', { status: 400, body: { error: 'Login failed: 401 Unauthorized' } })
|
|
257
|
+
await click(button('Save changes'))
|
|
258
|
+
expect(container.querySelector('[role="alert"]')?.textContent).toBe('Login failed: 401 Unauthorized')
|
|
259
|
+
expect(field('Address').value).toBe('https://oo.example.com')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('notes a connection shared by several clusters', async () => {
|
|
263
|
+
await mount(matched({ clusters: [{ context: 'kind-oo-b', by: 'id' }, { context: 'kind-oo-c', by: 'name' }] }))
|
|
264
|
+
expect(visibleText()).toContain('Shared by 2 clusters. Changes apply to all of them.')
|
|
265
|
+
act(() => root.unmount())
|
|
266
|
+
root = createRoot(container)
|
|
267
|
+
replies = {}
|
|
268
|
+
await mount(matched())
|
|
269
|
+
expect(container.textContent).not.toContain('Shared by')
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it('offers the saved connection to an unmatched cluster', async () => {
|
|
273
|
+
await mount({ connection: connection(), cluster: { uid: 'uid-123' } })
|
|
274
|
+
await click(radio('OpenObserve'))
|
|
275
|
+
expect(field('Address').value).toBe('https://oo.example.com')
|
|
276
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
277
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
278
|
+
await click(button('Use for this cluster'))
|
|
279
|
+
expect(posts()[0].body).toEqual({ useSaved: true, clusterUid: 'uid-123' })
|
|
280
|
+
})
|
|
281
|
+
|
|
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'))
|
|
290
|
+
reply('DELETE /integrations/openobserve/cluster?clusterUid=uid-123', { body: { connection: connection(), cluster: { uid: 'uid-123' } } })
|
|
291
|
+
await click(button('Use Prometheus for this cluster'))
|
|
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)
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
it('asks before removing the saved connection, listing the clusters that use it', async () => {
|
|
298
|
+
await mount(matched({ clusters: [{ context: 'kind-oo-b', by: 'id' }, { context: 'kind-oo-c', by: 'name' }] }))
|
|
299
|
+
await click(button('Remove OpenObserve connection'))
|
|
300
|
+
expect(calls.some((c) => c.method === 'DELETE')).toBe(false)
|
|
301
|
+
const dialog = document.body.textContent!
|
|
302
|
+
expect(dialog).toContain('Remove the saved OpenObserve connection?')
|
|
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.')
|
|
304
|
+
reply('DELETE /integrations/openobserve', { body: unmatched })
|
|
305
|
+
await click(button('Remove connection'))
|
|
306
|
+
expect(calls.at(-1)).toMatchObject({ method: 'DELETE', path: '/integrations/openobserve' })
|
|
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')
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
it('shows an environment token read-only and never sends a token for it', async () => {
|
|
327
|
+
await mount({ connection: connection({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }), cluster: { uid: 'uid-123' } })
|
|
328
|
+
await click(radio('OpenObserve'))
|
|
329
|
+
expect(container.textContent).toContain('Token from $RADAR_OO_TOKEN')
|
|
330
|
+
expect(container.querySelector('input[type="password"]')).toBeNull()
|
|
331
|
+
type(field('Organization'), 'team')
|
|
332
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
333
|
+
replies['GET /integrations/openobserve'] = [{ body: matched({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }) }]
|
|
334
|
+
await click(button('Save changes'))
|
|
335
|
+
expect(posts()[0].body).not.toHaveProperty('token')
|
|
336
|
+
expect(posts()[0].body).toMatchObject({ baseUrl: 'https://oo.example.com', org: 'team', user: 'radar@example.com' })
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
it('asks for a new token when an environment-token connection points at another user', async () => {
|
|
340
|
+
await mount({ connection: connection({ tokenSource: 'env', tokenEnv: 'RADAR_OO_TOKEN' }), cluster: { uid: 'uid-123' } })
|
|
341
|
+
await click(radio('OpenObserve'))
|
|
342
|
+
type(field('User or service account email'), 'other@example.com')
|
|
343
|
+
expect(container.textContent).not.toContain('Token from $RADAR_OO_TOKEN')
|
|
344
|
+
expect(container.textContent).toContain('A new address, organization or user needs its own token.')
|
|
345
|
+
type(field('Token'), 'new-secret')
|
|
346
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
347
|
+
replies['GET /integrations/openobserve'] = [{ body: matched() }]
|
|
348
|
+
await click(button('Save changes'))
|
|
349
|
+
expect(posts()[0].body).toMatchObject({ user: 'other@example.com', token: 'new-secret', clusterUid: 'uid-123' })
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it('keeps "Saved" when the page cannot reload after a save', async () => {
|
|
353
|
+
await mount({ connection: connection(), cluster: { uid: 'uid-123' } })
|
|
354
|
+
await click(radio('OpenObserve'))
|
|
355
|
+
reply('POST /integrations/openobserve/setup', { body: { outcome: 'saved', notes: {} } })
|
|
356
|
+
replies['GET /integrations/openobserve'] = [{ status: 500, body: { error: 'boom' } }]
|
|
357
|
+
await click(button('Use for this cluster'))
|
|
358
|
+
expect(container.textContent).toContain("Saved, but Radar couldn't reload this page.")
|
|
359
|
+
expect(container.textContent).not.toContain('boom')
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
it('keeps a saved token when editing without typing one', async () => {
|
|
363
|
+
await mount(matched())
|
|
364
|
+
expect(field('Token').placeholder).toBe('Saved — leave empty to keep')
|
|
365
|
+
expect(field('Token').value).toBe('')
|
|
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
|
+
})
|
|
384
|
+
})
|