@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,328 @@
|
|
|
1
|
+
import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
2
|
+
import { Collapse, ConfirmDialog, Disclosure, Input } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { ExternalLink } from 'lucide-react'
|
|
4
|
+
import {
|
|
5
|
+
getOpenObserveState,
|
|
6
|
+
removeOpenObserveConnection,
|
|
7
|
+
setupOpenObserve,
|
|
8
|
+
type OpenObserveConnection,
|
|
9
|
+
type OpenObserveLabelValue,
|
|
10
|
+
type OpenObserveMatch,
|
|
11
|
+
type OpenObserveSetupNotes,
|
|
12
|
+
type OpenObserveSetupRequest,
|
|
13
|
+
type OpenObserveState,
|
|
14
|
+
} from '../../api/openobserveSetup'
|
|
15
|
+
import { missingFamiliesNote } from './openobserveStatus'
|
|
16
|
+
import { FormSaveActions } from './FormSaveActions'
|
|
17
|
+
|
|
18
|
+
const SERVICE_ACCOUNT_DOCS = 'https://openobserve.ai/docs/user-guide/account-administration/identity-and-access-management/service-accounts/'
|
|
19
|
+
const inputClass = 'block w-full min-w-0 px-3 py-2 text-sm bg-theme-elevated border border-theme-border rounded-md text-theme-text-primary placeholder:text-theme-text-tertiary focus:outline-none focus:border-skyhook-500'
|
|
20
|
+
|
|
21
|
+
interface Draft {
|
|
22
|
+
baseUrl: string
|
|
23
|
+
org: string
|
|
24
|
+
user: string
|
|
25
|
+
token: string
|
|
26
|
+
caCertFile: string
|
|
27
|
+
clusterLabel: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const draftFrom = (connection: OpenObserveConnection | null): Draft => ({
|
|
31
|
+
baseUrl: connection?.baseUrl ?? '',
|
|
32
|
+
org: connection?.org ?? '',
|
|
33
|
+
user: connection?.user ?? '',
|
|
34
|
+
token: '',
|
|
35
|
+
caCertFile: connection?.caCertFile ?? '',
|
|
36
|
+
clusterLabel: connection?.clusterLabel ?? '',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const sameTarget = (a: Draft, b: Draft) =>
|
|
40
|
+
a.baseUrl.trim() === b.baseUrl.trim() && a.org.trim() === b.org.trim() && a.user.trim() === b.user.trim()
|
|
41
|
+
|
|
42
|
+
const sameDraft = (a: Draft, b: Draft) =>
|
|
43
|
+
(Object.keys(a) as (keyof Draft)[]).every((key) => a[key] === b[key])
|
|
44
|
+
|
|
45
|
+
type Result =
|
|
46
|
+
| { kind: 'saved'; notes?: OpenObserveSetupNotes; reloadFailed?: boolean }
|
|
47
|
+
| { kind: 'confirm'; reason?: string; suggestion: OpenObserveLabelValue; body: OpenObserveSetupRequest }
|
|
48
|
+
| { kind: 'not_found'; reason?: string; names: OpenObserveLabelValue[]; uid?: string }
|
|
49
|
+
| { kind: 'error'; message: string }
|
|
50
|
+
|
|
51
|
+
const pair = (value: OpenObserveLabelValue) => `${value.label}=${value.value}`
|
|
52
|
+
|
|
53
|
+
export const matchSummary = (match: OpenObserveMatch) =>
|
|
54
|
+
`Matched by ${match.by === 'id' ? 'cluster ID' : 'confirmed name'} (${pair(match)})`
|
|
55
|
+
|
|
56
|
+
const connectionLine = (connection: OpenObserveConnection) =>
|
|
57
|
+
`${connection.baseUrl} · organization ${connection.org} · user ${connection.user}`
|
|
58
|
+
|
|
59
|
+
export function OpenObserveSetup({
|
|
60
|
+
state,
|
|
61
|
+
locked = false,
|
|
62
|
+
status,
|
|
63
|
+
onStateChange,
|
|
64
|
+
onChanged,
|
|
65
|
+
onDirtyChange,
|
|
66
|
+
onBusyChange,
|
|
67
|
+
}: {
|
|
68
|
+
state: OpenObserveState
|
|
69
|
+
locked?: boolean
|
|
70
|
+
status?: ReactNode
|
|
71
|
+
onStateChange: (state: OpenObserveState) => void
|
|
72
|
+
onChanged: () => void
|
|
73
|
+
onDirtyChange?: (dirty: boolean) => void
|
|
74
|
+
onBusyChange?: (busy: boolean) => void
|
|
75
|
+
}) {
|
|
76
|
+
const id = useId()
|
|
77
|
+
const { connection, cluster } = state
|
|
78
|
+
const match = cluster.match
|
|
79
|
+
const baseline = useMemo(() => draftFrom(connection), [connection])
|
|
80
|
+
const [draft, setDraft] = useState<Draft>(baseline)
|
|
81
|
+
const [busy, setBusy] = useState(false)
|
|
82
|
+
const [result, setResult] = useState<Result | null>(null)
|
|
83
|
+
const [confirmingRemove, setConfirmingRemove] = useState(false)
|
|
84
|
+
const mounted = useRef(true)
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
mounted.current = true
|
|
87
|
+
return () => { mounted.current = false }
|
|
88
|
+
}, [])
|
|
89
|
+
|
|
90
|
+
// A token from an environment variable is kept only for the same address,
|
|
91
|
+
// organization and user; the server never sends a saved secret elsewhere.
|
|
92
|
+
const envToken = !!connection && connection.tokenSource === 'env' && sameTarget(draft, baseline)
|
|
93
|
+
const dirty = !locked && !sameDraft(draft, baseline)
|
|
94
|
+
useEffect(() => onDirtyChange?.(dirty), [dirty, onDirtyChange])
|
|
95
|
+
useEffect(() => onBusyChange?.(busy), [busy, onBusyChange])
|
|
96
|
+
useEffect(() => () => {
|
|
97
|
+
onDirtyChange?.(false)
|
|
98
|
+
onBusyChange?.(false)
|
|
99
|
+
}, [onDirtyChange, onBusyChange])
|
|
100
|
+
|
|
101
|
+
// Switching this cluster back to Prometheus happens outside this form.
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!match) setResult((current) => current?.kind === 'saved' ? null : current)
|
|
104
|
+
}, [match])
|
|
105
|
+
|
|
106
|
+
// Switching this cluster back to Prometheus happens outside this form.
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (!match) setResult((current) => current?.kind === 'saved' ? null : current)
|
|
109
|
+
}, [match])
|
|
110
|
+
|
|
111
|
+
const update = (changes: Partial<Draft>) => {
|
|
112
|
+
setDraft((value) => ({ ...value, ...changes }))
|
|
113
|
+
if (result?.kind === 'confirm') setResult(null)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const run = async (action: () => Promise<void>) => {
|
|
117
|
+
setBusy(true)
|
|
118
|
+
try {
|
|
119
|
+
await action()
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (mounted.current) setResult({ kind: 'error', message: error instanceof Error ? error.message : String(error) })
|
|
122
|
+
} finally {
|
|
123
|
+
if (mounted.current) setBusy(false)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const formBody = (): OpenObserveSetupRequest => ({
|
|
128
|
+
baseUrl: draft.baseUrl.trim(),
|
|
129
|
+
org: draft.org.trim(),
|
|
130
|
+
user: draft.user.trim(),
|
|
131
|
+
caCertFile: draft.caCertFile.trim(),
|
|
132
|
+
clusterLabel: draft.clusterLabel.trim(),
|
|
133
|
+
...(draft.token && !envToken ? { token: draft.token } : {}),
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const submit = (body: OpenObserveSetupRequest) => run(async () => {
|
|
137
|
+
setResult(null)
|
|
138
|
+
const response = await setupOpenObserve(cluster.uid ? { ...body, clusterUid: cluster.uid } : body)
|
|
139
|
+
if (!mounted.current) return
|
|
140
|
+
if (response.outcome === 'saved') {
|
|
141
|
+
setResult({ kind: 'saved', notes: response.notes })
|
|
142
|
+
onChanged()
|
|
143
|
+
let next: OpenObserveState
|
|
144
|
+
try {
|
|
145
|
+
next = await getOpenObserveState()
|
|
146
|
+
} catch {
|
|
147
|
+
if (mounted.current) setResult({ kind: 'saved', notes: response.notes, reloadFailed: true })
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
if (!mounted.current) return
|
|
151
|
+
setDraft(draftFrom(next.connection))
|
|
152
|
+
onStateChange(next)
|
|
153
|
+
} else if (response.outcome === 'confirm' && response.suggestion) {
|
|
154
|
+
setResult({ kind: 'confirm', reason: response.reason, suggestion: response.suggestion, body })
|
|
155
|
+
} else {
|
|
156
|
+
setResult({ kind: 'not_found', reason: response.reason, names: response.clusterNames ?? [], uid: response.clusterUid ?? cluster.uid })
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
const testAndSave = () => {
|
|
161
|
+
if (result?.kind === 'confirm') void submit({ ...result.body, confirm: result.suggestion })
|
|
162
|
+
else void submit(dirty || !connection ? formBody() : { useSaved: true })
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const removeAll = () => {
|
|
166
|
+
setConfirmingRemove(false)
|
|
167
|
+
void run(async () => {
|
|
168
|
+
setResult(null)
|
|
169
|
+
const next = await removeOpenObserveConnection()
|
|
170
|
+
if (!mounted.current) return
|
|
171
|
+
setDraft(draftFrom(next.connection))
|
|
172
|
+
onStateChange(next)
|
|
173
|
+
onChanged()
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const discard = () => {
|
|
178
|
+
setDraft(baseline)
|
|
179
|
+
setResult(null)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const shared = connection && connection.clusters.length > 1
|
|
183
|
+
? <p className="text-xs text-theme-text-secondary">Shared by {connection.clusters.length} clusters. Changes apply to all of them.</p>
|
|
184
|
+
: null
|
|
185
|
+
const contexts = connection?.clusters.map((c) => c.context).filter(Boolean) ?? []
|
|
186
|
+
|
|
187
|
+
const statusRow = status ? <div className="flex flex-wrap items-center gap-x-3 gap-y-1">{status}</div> : null
|
|
188
|
+
|
|
189
|
+
if (locked) {
|
|
190
|
+
return (
|
|
191
|
+
<div className="space-y-2 text-sm">
|
|
192
|
+
{statusRow}
|
|
193
|
+
{match && <p className="text-theme-text-primary">{matchSummary(match)}</p>}
|
|
194
|
+
{connection
|
|
195
|
+
? <p className="break-words text-xs text-theme-text-secondary">{connectionLine(connection)}</p>
|
|
196
|
+
: <p className="text-xs text-theme-text-secondary">No OpenObserve connection saved.</p>}
|
|
197
|
+
</div>
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const notes = result?.kind === 'saved' ? [
|
|
202
|
+
result.notes?.collector && 'Data comes from the OpenObserve collector.',
|
|
203
|
+
// The live status line repeats the warning, version and coverage notes
|
|
204
|
+
// once the match settles; only say them here when that line isn't shown.
|
|
205
|
+
!status && result.notes?.missing?.length && missingFamiliesNote(result.notes.missing),
|
|
206
|
+
!status && result.notes?.warning,
|
|
207
|
+
!status && result.notes?.versionWarning,
|
|
208
|
+
result.reloadFailed && "Saved, but Radar couldn't reload this page. Reopen Settings to see the match.",
|
|
209
|
+
].filter((note): note is string => !!note) : []
|
|
210
|
+
|
|
211
|
+
const outcome = result && result.kind !== 'saved' && result.kind !== 'error' ? (
|
|
212
|
+
result.kind === 'confirm' ? (
|
|
213
|
+
<p role="status" className="text-xs text-warning-text">
|
|
214
|
+
{result.reason ?? `OpenObserve has metrics for ${pair(result.suggestion)}, matched only by name.`}
|
|
215
|
+
</p>
|
|
216
|
+
) : (
|
|
217
|
+
<div role="status" className="space-y-1 text-xs text-theme-text-secondary">
|
|
218
|
+
{result.reason && <p className="text-warning-text">{result.reason}</p>}
|
|
219
|
+
{result.names.length
|
|
220
|
+
? <p>{`OpenObserve has metrics for: ${result.names.map(pair).join(', ')}.`}</p>
|
|
221
|
+
// The reason already says what the Pod sample found in OpenObserve.
|
|
222
|
+
: !result.reason && <p>OpenObserve has no cluster metrics yet.</p>}
|
|
223
|
+
<p>If OpenObserve names clusters with another label, set it under Advanced.</p>
|
|
224
|
+
{result.uid && <p>To match by ID, add the label radar_cluster_uid={result.uid} to this cluster’s metrics.</p>}
|
|
225
|
+
</div>
|
|
226
|
+
)
|
|
227
|
+
) : null
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<fieldset disabled={busy} aria-label="OpenObserve connection settings" className="min-w-0 space-y-4">
|
|
231
|
+
{statusRow}
|
|
232
|
+
{cluster.error && <p className="text-xs text-warning-text">{cluster.error}</p>}
|
|
233
|
+
{match && <p className="text-sm text-theme-text-primary">{matchSummary(match)}</p>}
|
|
234
|
+
{shared}
|
|
235
|
+
<div className="space-y-4">
|
|
236
|
+
<div className="space-y-1">
|
|
237
|
+
<label htmlFor={`${id}-url`} className="block text-sm font-medium text-theme-text-primary">Address</label>
|
|
238
|
+
<Input id={`${id}-url`} value={draft.baseUrl} onChange={(e) => update({ baseUrl: e.target.value })} placeholder="https://openobserve.example.com" spellCheck={false} className={inputClass} />
|
|
239
|
+
</div>
|
|
240
|
+
<div className="space-y-1">
|
|
241
|
+
<label htmlFor={`${id}-org`} className="block text-sm font-medium text-theme-text-primary">Organization</label>
|
|
242
|
+
<Input id={`${id}-org`} value={draft.org} onChange={(e) => update({ org: e.target.value })} placeholder="2Zp8kQ1vXcR7mN4tLwYb9HsA3eD" spellCheck={false} className={inputClass} />
|
|
243
|
+
<p className="text-xs text-theme-text-tertiary">The organization ID from OpenObserve. Leave empty for default.</p>
|
|
244
|
+
</div>
|
|
245
|
+
<div className="space-y-1">
|
|
246
|
+
<label htmlFor={`${id}-user`} className="block text-sm font-medium text-theme-text-primary">User or service account email</label>
|
|
247
|
+
<Input id={`${id}-user`} value={draft.user} onChange={(e) => update({ user: e.target.value })} autoComplete="off" spellCheck={false} className={inputClass} />
|
|
248
|
+
<a href={SERVICE_ACCOUNT_DOCS} target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-1 text-xs text-accent-text hover:underline">
|
|
249
|
+
Create a service account in OpenObserve
|
|
250
|
+
<ExternalLink aria-hidden="true" className="h-3 w-3" />
|
|
251
|
+
</a>
|
|
252
|
+
</div>
|
|
253
|
+
<div className="space-y-1">
|
|
254
|
+
<label htmlFor={`${id}-token`} className="block text-sm font-medium text-theme-text-primary">Token</label>
|
|
255
|
+
{envToken ? (
|
|
256
|
+
<p id={`${id}-token`} className="text-sm text-theme-text-secondary">Token from ${connection.tokenEnv}</p>
|
|
257
|
+
) : (
|
|
258
|
+
<Input
|
|
259
|
+
id={`${id}-token`}
|
|
260
|
+
type="password"
|
|
261
|
+
autoComplete="new-password"
|
|
262
|
+
spellCheck={false}
|
|
263
|
+
value={draft.token}
|
|
264
|
+
onChange={(e) => update({ token: e.target.value })}
|
|
265
|
+
placeholder={connection?.tokenSource === 'saved' && sameTarget(draft, baseline) ? 'Saved — leave empty to keep' : undefined}
|
|
266
|
+
className={inputClass}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
{connection && connection.tokenSource !== 'none' && !sameTarget(draft, baseline) && (
|
|
270
|
+
<p className="text-xs text-theme-text-secondary">A new address, organization or user needs its own token.</p>
|
|
271
|
+
)}
|
|
272
|
+
<p className="text-xs text-theme-text-tertiary">Saved in ~/.radar/config.json, readable only by you.</p>
|
|
273
|
+
</div>
|
|
274
|
+
<Disclosure
|
|
275
|
+
summary="Advanced"
|
|
276
|
+
summaryClassName="text-sm font-medium text-theme-text-secondary"
|
|
277
|
+
defaultOpen={!!(baseline.caCertFile || baseline.clusterLabel)}
|
|
278
|
+
>
|
|
279
|
+
<div className="space-y-4 pt-3">
|
|
280
|
+
<div className="space-y-1">
|
|
281
|
+
<label htmlFor={`${id}-ca`} className="block text-sm font-medium text-theme-text-primary">CA certificate file</label>
|
|
282
|
+
<Input id={`${id}-ca`} value={draft.caCertFile} onChange={(e) => update({ caCertFile: e.target.value })} placeholder="/path/to/ca.pem" spellCheck={false} className={inputClass} />
|
|
283
|
+
</div>
|
|
284
|
+
<div className="space-y-1">
|
|
285
|
+
<label htmlFor={`${id}-label`} className="block text-sm font-medium text-theme-text-primary">Cluster label</label>
|
|
286
|
+
<p className="text-xs text-theme-text-tertiary">Only when OpenObserve names clusters with a label Radar doesn’t know.</p>
|
|
287
|
+
<Input id={`${id}-label`} value={draft.clusterLabel} onChange={(e) => update({ clusterLabel: e.target.value })} spellCheck={false} className={inputClass} />
|
|
288
|
+
</div>
|
|
289
|
+
</div>
|
|
290
|
+
</Disclosure>
|
|
291
|
+
</div>
|
|
292
|
+
<div>
|
|
293
|
+
<FormSaveActions
|
|
294
|
+
dirty={dirty}
|
|
295
|
+
busy={busy}
|
|
296
|
+
canSave={dirty || result?.kind === 'confirm' || (!!connection && !match)}
|
|
297
|
+
saveLabel={result?.kind === 'confirm' ? `Confirm '${result.suggestion.value}' and save` : !dirty && connection && !match ? 'Use for this cluster' : 'Save changes'}
|
|
298
|
+
onSave={testAndSave}
|
|
299
|
+
onDiscard={discard}
|
|
300
|
+
feedback={result?.kind === 'saved' ? { tone: 'success', message: 'Saved' } : undefined}
|
|
301
|
+
error={result?.kind === 'error' ? result.message : undefined}
|
|
302
|
+
/>
|
|
303
|
+
<Collapse open={notes.length > 0}>
|
|
304
|
+
<ul className="space-y-0.5 pt-2 text-xs text-theme-text-secondary">
|
|
305
|
+
{notes.map((note) => <li key={note}>{note}</li>)}
|
|
306
|
+
</ul>
|
|
307
|
+
</Collapse>
|
|
308
|
+
<Collapse open={!!outcome}><div className="pt-2">{outcome}</div></Collapse>
|
|
309
|
+
{connection && (
|
|
310
|
+
<button type="button" onClick={() => setConfirmingRemove(true)} className="mt-3 text-xs text-accent-text hover:underline">
|
|
311
|
+
Remove OpenObserve connection
|
|
312
|
+
</button>
|
|
313
|
+
)}
|
|
314
|
+
</div>
|
|
315
|
+
<ConfirmDialog
|
|
316
|
+
open={confirmingRemove}
|
|
317
|
+
onClose={() => setConfirmingRemove(false)}
|
|
318
|
+
onConfirm={removeAll}
|
|
319
|
+
title="Remove the saved OpenObserve connection?"
|
|
320
|
+
message={`${contexts.length
|
|
321
|
+
? `These clusters go back to their Prometheus settings: ${contexts.join(', ')}.`
|
|
322
|
+
: 'No cluster reads from it yet.'} Nothing is deleted in OpenObserve or Kubernetes.`}
|
|
323
|
+
confirmLabel="Remove connection"
|
|
324
|
+
showWarning={false}
|
|
325
|
+
/>
|
|
326
|
+
</fieldset>
|
|
327
|
+
)
|
|
328
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasPrometheusCharts, metricsConnectionLabel, metricsSourceUnavailable } from '../../api/prometheusCharts'
|
|
1
2
|
import { useState, useEffect, useRef, useCallback, type ReactNode } from 'react'
|
|
2
3
|
import { createPortal } from 'react-dom'
|
|
3
4
|
import {
|
|
@@ -38,6 +39,7 @@ import { costSourceApplyLabel, pendingSectionLabels, pendingSections, shouldShow
|
|
|
38
39
|
import { PrometheusConfigField } from './PrometheusConfigField'
|
|
39
40
|
import { LocalConnectionSettings, type IntegrationProfiles, type IntegrationKind } from './LocalConnectionSettings'
|
|
40
41
|
import { LocalIntegrationStatus } from './LocalIntegrationStatus'
|
|
42
|
+
import { MetricsBackendSwitch } from './MetricsBackendSwitch'
|
|
41
43
|
import { LocalConfigurationDetails, SavedClusterConnections, PreviousIntegrationSettingsNotice } from './LocalConfigurationDetails'
|
|
42
44
|
import { useContextSwitch } from '../../context/ContextSwitchContext'
|
|
43
45
|
import { previousIntegrationSettingsKey, type IntegrationSettingsResponse } from '../../hooks/usePreviousIntegrationSettings'
|
|
@@ -183,6 +185,10 @@ export function SettingsDialog({
|
|
|
183
185
|
void queryClient.resetQueries({ queryKey: [previousIntegrationSettingsKey] })
|
|
184
186
|
void queryClient.invalidateQueries({ predicate: query => typeof query.queryKey[0] === 'string' && /^(prometheus|opencost|gitops|argo)/.test(query.queryKey[0]) })
|
|
185
187
|
}, [queryClient])
|
|
188
|
+
const openObserveChanged = useCallback(() => {
|
|
189
|
+
setConnectionsChangedAt(Date.now())
|
|
190
|
+
void queryClient.invalidateQueries({ predicate: query => typeof query.queryKey[0] === 'string' && /^(prometheus|opencost)/.test(query.queryKey[0]) })
|
|
191
|
+
}, [queryClient])
|
|
186
192
|
|
|
187
193
|
const [configData, setConfigData] = useState<ConfigResponse | null>(null)
|
|
188
194
|
const operatorManaged = configData?.management === 'operator'
|
|
@@ -267,6 +273,10 @@ export function SettingsDialog({
|
|
|
267
273
|
const settingsScope = `${settingsApiBase}:${settingsCluster?.context}`
|
|
268
274
|
const targetChangedWithDraft = open && metricsDraft.current.open && metricsDraft.current.dirty && (isSwitching || metricsDraft.current.scope !== settingsScope)
|
|
269
275
|
const showLocalStatus = open && !draftFrozen && !targetChangedWithDraft && !isSwitching
|
|
276
|
+
const metricsProfile = configData?.integrationProfiles?.metrics
|
|
277
|
+
const metricsStatus = metricsProfile && showLocalStatus && section === 'prometheus' && !['error', 'target_changed'].includes(metricsProfile.state)
|
|
278
|
+
? <LocalIntegrationStatus kind="metrics" profile={metricsProfile} argo={argoStatusQuery} busy={integrationBusy} changedAt={connectionsChangedAt} />
|
|
279
|
+
: undefined
|
|
270
280
|
useEffect(() => {
|
|
271
281
|
if (!open) {
|
|
272
282
|
setDraftFrozen(false)
|
|
@@ -761,9 +771,11 @@ export function SettingsDialog({
|
|
|
761
771
|
caption={configData?.integrationProfiles ? localIntegrationCaption : 'Connect and manage your metrics backend.'}
|
|
762
772
|
live
|
|
763
773
|
locked={!canEditConfig}
|
|
774
|
+
lockedContent={configData?.integrationProfiles ? <MetricsBackendSwitch key={`${discardGeneration}:${JSON.stringify(configData.integrationProfiles.metrics.target)}`} locked onChanged={openObserveChanged} status={metricsStatus} prometheus={() => null} /> : undefined}
|
|
764
775
|
>
|
|
765
|
-
{configData?.integrationProfiles ? <
|
|
766
|
-
status={
|
|
776
|
+
{configData?.integrationProfiles ? <MetricsBackendSwitch key={`${discardGeneration}:${JSON.stringify(configData.integrationProfiles.metrics.target)}`} onChanged={openObserveChanged} onDirtyChange={metricsDirtyChange} onBusyChange={metricsBusyChange}
|
|
777
|
+
status={metricsStatus}
|
|
778
|
+
prometheus={({ status, onDirtyChange, onBusyChange }) => <LocalConnectionSettings kind="metrics" profiles={configData.integrationProfiles!} onChange={connectionsChanged} onDirtyChange={onDirtyChange} onBusyChange={onBusyChange} status={status} />} /> : <PrometheusConfigField
|
|
767
779
|
key={`${settingsApiBase}:${discardGeneration}`}
|
|
768
780
|
onBusyChange={metricsBusyChange}
|
|
769
781
|
onDirtyChange={setPrometheusCredentialDirty}
|
|
@@ -1155,6 +1167,7 @@ function SectionPane({
|
|
|
1155
1167
|
caption,
|
|
1156
1168
|
live,
|
|
1157
1169
|
locked,
|
|
1170
|
+
lockedContent,
|
|
1158
1171
|
managed,
|
|
1159
1172
|
children,
|
|
1160
1173
|
}: {
|
|
@@ -1164,6 +1177,7 @@ function SectionPane({
|
|
|
1164
1177
|
caption?: string
|
|
1165
1178
|
live?: boolean
|
|
1166
1179
|
locked?: boolean
|
|
1180
|
+
lockedContent?: ReactNode
|
|
1167
1181
|
managed?: ReactNode
|
|
1168
1182
|
children: ReactNode
|
|
1169
1183
|
}) {
|
|
@@ -1173,7 +1187,7 @@ function SectionPane({
|
|
|
1173
1187
|
<h3 className="text-base font-semibold text-theme-text-primary">{title}</h3>
|
|
1174
1188
|
{!locked && caption && <SectionCaption live={live}>{caption}</SectionCaption>}
|
|
1175
1189
|
</div>
|
|
1176
|
-
{managed ?? (locked ? <LockWall /> : <div className="space-y-4">{children}</div>)}
|
|
1190
|
+
{managed ?? (locked ? <div className="space-y-4"><LockWall />{lockedContent}</div> : <div className="space-y-4">{children}</div>)}
|
|
1177
1191
|
</div>
|
|
1178
1192
|
)
|
|
1179
1193
|
}
|
|
@@ -1207,7 +1221,7 @@ function OperatorSettingsSummary({ section, config }: { section: SettingsSection
|
|
|
1207
1221
|
break
|
|
1208
1222
|
case 'prometheus':
|
|
1209
1223
|
rows = [
|
|
1210
|
-
['Status', promError ? 'Status unavailable' :
|
|
1224
|
+
['Status', promError ? 'Status unavailable' : metricsConnectionLabel(prom)],
|
|
1211
1225
|
['Endpoint', prom?.address || c.prometheusUrl || 'Auto-discovery'],
|
|
1212
1226
|
['Headers', config.prometheusHeaderKeys?.join(', ') || 'None configured'],
|
|
1213
1227
|
]
|
|
@@ -1326,9 +1340,9 @@ function OverviewPanel({ active, onNavigate }: { active: boolean; onNavigate: (s
|
|
|
1326
1340
|
},
|
|
1327
1341
|
{
|
|
1328
1342
|
id: 'prometheus', icon: Activity, label: 'Metrics',
|
|
1329
|
-
tone: prom
|
|
1330
|
-
value: prom
|
|
1331
|
-
detail: prom?.connected ? prom.address : prom?.discovering ? undefined : prom?.error ? 'Open Metrics for connection details.' : undefined,
|
|
1343
|
+
tone: hasPrometheusCharts(prom) ? 'ok' : metricsSourceUnavailable(prom) ? 'warn' : prom?.discovering ? 'unknown' : prom?.error ? 'warn' : 'off',
|
|
1344
|
+
value: prom ? metricsConnectionLabel(prom) : 'Not connected',
|
|
1345
|
+
detail: hasPrometheusCharts(prom) && prom?.connected ? prom.address : prom?.gkeSystemMetrics || prom?.discovering ? undefined : prom?.error || metricsSourceUnavailable(prom) ? 'Open Metrics for connection details.' : undefined,
|
|
1332
1346
|
},
|
|
1333
1347
|
{
|
|
1334
1348
|
id: costConfigurationAction(cost?.reason).section, icon: Coins, label: 'Cost',
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { metricsSourceLine, sourceNote } from './openobserveStatus'
|
|
3
|
+
|
|
4
|
+
describe('metricsSourceLine', () => {
|
|
5
|
+
it('names an ID match on the shared local connection', () => {
|
|
6
|
+
expect(metricsSourceLine({ kind: 'openobserve', via: 'local', matchedBy: 'id' })).toEqual({
|
|
7
|
+
status: 'OpenObserve · shared connection · matched by cluster ID', detail: undefined, tone: 'success',
|
|
8
|
+
})
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('keeps the standing warning, version warning and missing families for a name match', () => {
|
|
12
|
+
const line = metricsSourceLine({ kind: 'openobserve', via: 'local', matchedBy: 'name', versionWarning: 'Upgrade.', missingFamilies: ['throttling', 'hpa'] })
|
|
13
|
+
expect(line?.status).toBe('OpenObserve · shared connection · matched by confirmed name')
|
|
14
|
+
expect(line?.detail).toBe("Add the cluster ID label so this match can't break. Upgrade. No data in OpenObserve for: CPU throttling, HPA.")
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('shows the standing warning of an active match after saving', () => {
|
|
18
|
+
const warning = 'This cluster\'s OpenObserve collector sends the default cluster name "cluster1". Radar refuses its kube-state metrics.'
|
|
19
|
+
expect(metricsSourceLine({ kind: 'openobserve', via: 'local', matchedBy: 'id', warning })?.detail).toBe(warning)
|
|
20
|
+
expect(metricsSourceLine({ kind: 'openobserve', via: 'local', matchedBy: 'name', warning: 'Matched by cluster name.' })?.detail).toBe('Matched by cluster name.')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('reports unavailable without claiming a connection', () => {
|
|
24
|
+
expect(metricsSourceLine({ kind: 'openobserve', via: 'local', matchedBy: 'id', unavailable: true, error: 'OpenObserve unavailable: refused' }))
|
|
25
|
+
.toEqual({ status: 'OpenObserve unavailable', detail: 'refused', tone: 'warning' })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('leaves the Prometheus line for an unmatched context and explains why', () => {
|
|
29
|
+
const src = { kind: 'openobserve' as const, via: 'local' as const, error: "This context isn't matched in OpenObserve." }
|
|
30
|
+
expect(metricsSourceLine(src)).toBeUndefined()
|
|
31
|
+
expect(sourceNote(src)).toBe("This context isn't matched in OpenObserve.")
|
|
32
|
+
expect(metricsSourceLine(undefined)).toBeUndefined()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { MetricsSource } from '../../api/client'
|
|
2
|
+
|
|
3
|
+
export interface MetricsSourceLine {
|
|
4
|
+
status: string
|
|
5
|
+
detail?: string
|
|
6
|
+
tone: 'success' | 'warning' | 'neutral'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// The one set of metric family names Radar shows (mirrored by FamilyLabel in
|
|
10
|
+
// pkg/prom/openobserve for the CLI). Each starts with a capital, even mid-list.
|
|
11
|
+
const FAMILY_LABELS: Record<string, string> = {
|
|
12
|
+
cpu: 'CPU', memory: 'Memory', throttling: 'CPU throttling', network: 'Network',
|
|
13
|
+
filesystem: 'Disk I/O', restarts: 'Restarts', volumes: 'Volumes', nodes: 'Nodes', hpa: 'HPA',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const familyLabel = (family: string) => FAMILY_LABELS[family] ?? family
|
|
17
|
+
|
|
18
|
+
/** The one phrase for metric families OpenObserve holds no data for. */
|
|
19
|
+
export const missingFamiliesNote = (families: string[]) => `No data in OpenObserve for: ${families.map(familyLabel).join(', ')}.`
|
|
20
|
+
|
|
21
|
+
/** An unavailable source's error without the "OpenObserve unavailable" its heading already says. */
|
|
22
|
+
export const unavailableReason = (error: string | undefined) => error?.replace(/^OpenObserve unavailable: /, '')
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The status line for a metrics source, or undefined when the source is not
|
|
26
|
+
* serving this context (the Prometheus line applies; see `sourceNote`).
|
|
27
|
+
*/
|
|
28
|
+
export function metricsSourceLine(source: MetricsSource | undefined): MetricsSourceLine | undefined {
|
|
29
|
+
if (!source || source.kind !== 'openobserve') return undefined
|
|
30
|
+
const shared = source.via === 'local' ? ' · shared connection' : ''
|
|
31
|
+
if (source.unavailable) {
|
|
32
|
+
return { status: 'OpenObserve unavailable', detail: unavailableReason(source.error), tone: 'warning' }
|
|
33
|
+
}
|
|
34
|
+
if (!source.matchedBy) return undefined
|
|
35
|
+
const details: string[] = []
|
|
36
|
+
// The backend's standing warning (name match, refused collector metrics)
|
|
37
|
+
// says why and what to fix; the short hint stands in only without one.
|
|
38
|
+
if (source.warning) details.push(source.warning)
|
|
39
|
+
else if (source.matchedBy === 'name') details.push("Add the cluster ID label so this match can't break.")
|
|
40
|
+
if (source.versionWarning) details.push(source.versionWarning)
|
|
41
|
+
if (source.missingFamilies?.length) {
|
|
42
|
+
details.push(missingFamiliesNote(source.missingFamilies))
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
status: `OpenObserve${shared} · matched by ${source.matchedBy === 'id' ? 'cluster ID' : 'confirmed name'}`,
|
|
46
|
+
detail: details.length ? details.join(' ') : undefined,
|
|
47
|
+
tone: 'success',
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Why a configured source isn't serving this context, if it says. */
|
|
52
|
+
export function sourceNote(source: MetricsSource | undefined): string | undefined {
|
|
53
|
+
if (!source || source.unavailable || source.matchedBy) return undefined
|
|
54
|
+
return source.error ?? source.warning
|
|
55
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import type { TimelineEvent } from '../../types'
|
|
6
|
+
|
|
7
|
+
const event = (id: string, minutesAgo: number): TimelineEvent => ({
|
|
8
|
+
id, timestamp: new Date(Date.now() - minutesAgo * 60_000).toISOString(), source: 'informer', kind: 'ConfigMap', apiVersion: 'v1',
|
|
9
|
+
namespace: 'shop', name: `cfg-${id}`, eventType: 'update', reason: 'update', message: `${id} changed`,
|
|
10
|
+
} as TimelineEvent)
|
|
11
|
+
const events = [event('ev-a', 5), event('ev-b', 9), event('ev-c', 14)]
|
|
12
|
+
|
|
13
|
+
vi.mock('../../context/TimelineSource', () => ({
|
|
14
|
+
useTimelineSource: () => ({ useEvents: () => ({ data: events, isLoading: false, isFetching: false, isError: false, error: null, refetch: vi.fn() }) }),
|
|
15
|
+
}))
|
|
16
|
+
vi.mock('../../contexts/CapabilitiesContext', () => ({ useHasLimitedAccess: () => false }))
|
|
17
|
+
vi.mock('./TimelineRetentionNote', () => ({ TimelineRetentionBanner: () => null }))
|
|
18
|
+
|
|
19
|
+
const { TimelineList } = await import('./TimelineList')
|
|
20
|
+
|
|
21
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
22
|
+
const roots: ReturnType<typeof createRoot>[] = []
|
|
23
|
+
afterEach(() => { roots.splice(0).forEach((root) => act(() => root.unmount())) })
|
|
24
|
+
|
|
25
|
+
describe('the Timeline list with an event selected', () => {
|
|
26
|
+
it('marks the selected event, so a link to it lands on it in list view too', async () => {
|
|
27
|
+
const host = document.createElement('div')
|
|
28
|
+
document.body.append(host)
|
|
29
|
+
const root = createRoot(host)
|
|
30
|
+
roots.push(root)
|
|
31
|
+
await act(async () => {
|
|
32
|
+
root.render(<TimelineList namespaces={['shop']} showDeleted onShowDeletedChange={() => {}} showRoutine={false} onShowRoutineChange={() => {}}
|
|
33
|
+
search="" onSearchChange={() => {}} activityFilter={[]} onActivityFilterChange={() => {}} kindFilter={[]} onKindFilterChange={() => {}}
|
|
34
|
+
selectedEventId="ev-b" onSelectEvent={() => {}} />)
|
|
35
|
+
})
|
|
36
|
+
const selected = [...host.querySelectorAll('[class*="ring-skyhook-500/60"]')]
|
|
37
|
+
expect(selected).toHaveLength(1)
|
|
38
|
+
expect(selected[0].textContent).toContain('cfg-ev-b')
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -72,3 +72,21 @@ describe('splitRoutineActivity', () => {
|
|
|
72
72
|
expect(routineTruncated).toBe(true)
|
|
73
73
|
})
|
|
74
74
|
})
|
|
75
|
+
|
|
76
|
+
describe('a linked event behind the list cap', () => {
|
|
77
|
+
it('keeps the selected event in the list even when newer rows fill the cap', () => {
|
|
78
|
+
const target = ev({ id: 'linked', kind: 'ConfigMap' })
|
|
79
|
+
const newer = Array.from({ length: 5 }, (_, i) => ev({ id: `newer-${i}`, kind: 'Deployment' }))
|
|
80
|
+
const rows = [...newer].reverse().concat(target)
|
|
81
|
+
const capped = splitRoutineActivity(rows, 3, 'linked')
|
|
82
|
+
expect(capped.withoutRoutine.map((e) => e.id)).toContain('linked')
|
|
83
|
+
expect(capped.withRoutine.map((e) => e.id)).toContain('linked')
|
|
84
|
+
expect(capped.truncated).toBe(true)
|
|
85
|
+
expect(splitRoutineActivity(rows, 3).withoutRoutine.map((e) => e.id)).not.toContain('linked')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('shows a linked routine child row with routine activity hidden', () => {
|
|
89
|
+
const routineRow = ev({ id: 'rs-linked', kind: 'ReplicaSet', owner: { kind: 'Deployment', name: 'web' } })
|
|
90
|
+
expect(splitRoutineActivity([routineRow], 10, 'rs-linked').withoutRoutine.map((e) => e.id)).toEqual(['rs-linked'])
|
|
91
|
+
})
|
|
92
|
+
})
|
|
@@ -39,7 +39,9 @@ const byNewest = (a: TimelineEvent, b: TimelineEvent) => new Date(b.timestamp).g
|
|
|
39
39
|
// and routine child activity, each newest first under its own `limit`. Separate
|
|
40
40
|
// budgets keep the promises the toggle makes: a burst of owner rows can't crowd
|
|
41
41
|
// out child problems, and showing routine activity only ever adds rows.
|
|
42
|
-
|
|
42
|
+
// `keepId` is the event a link opened (?event=): it always stays, past the cap
|
|
43
|
+
// and with routine activity hidden, so the link lands on it.
|
|
44
|
+
export function splitRoutineActivity(allRows: TimelineEvent[], limit: number, keepId?: string | null) {
|
|
43
45
|
const owners: TimelineEvent[] = []
|
|
44
46
|
const childProblems: TimelineEvent[] = []
|
|
45
47
|
const routine: TimelineEvent[] = []
|
|
@@ -47,8 +49,15 @@ export function splitRoutineActivity(allRows: TimelineEvent[], limit: number) {
|
|
|
47
49
|
const bucket = !isManagedTimelineEvent(e) ? owners : isTimelineProblem(e) ? childProblems : routine
|
|
48
50
|
bucket.push(e)
|
|
49
51
|
}
|
|
50
|
-
const base = [...owners.slice(0, limit), ...childProblems.slice(0, limit)]
|
|
52
|
+
const base = [...owners.slice(0, limit), ...childProblems.slice(0, limit)]
|
|
51
53
|
const shownRoutine = routine.slice(0, limit)
|
|
54
|
+
const kept = keepId ? allRows.find((e) => e.id === keepId) : undefined
|
|
55
|
+
if (kept && !base.includes(kept)) base.push(kept)
|
|
56
|
+
base.sort(byNewest)
|
|
57
|
+
if (kept) {
|
|
58
|
+
const at = shownRoutine.indexOf(kept)
|
|
59
|
+
if (at >= 0) shownRoutine.splice(at, 1)
|
|
60
|
+
}
|
|
52
61
|
return {
|
|
53
62
|
withoutRoutine: base,
|
|
54
63
|
withRoutine: [...base, ...shownRoutine].sort(byNewest),
|
|
@@ -95,9 +104,12 @@ interface TimelineListProps {
|
|
|
95
104
|
topology?: Topology
|
|
96
105
|
appScopeLoading?: boolean
|
|
97
106
|
onOpenDiagnostics?: () => void
|
|
107
|
+
// The selected event (the URL's ?event=): marked and scrolled into view.
|
|
108
|
+
selectedEventId?: string | null
|
|
109
|
+
onSelectEvent?: (id: string | null) => void
|
|
98
110
|
}
|
|
99
111
|
|
|
100
|
-
export function TimelineList({ namespaces, onViewChange, currentView, onResourceClick, initialFilter, initialTimeRange, showDeleted, onShowDeletedChange, showRoutine, onShowRoutineChange, search, onSearchChange, activityFilter, onActivityFilterChange, kindFilter, onKindFilterChange, selectionWindow, onVisibleWindowChange, scrollToMs, focusedAppIndex, appScoped = false, topology, appScopeLoading = false, onOpenDiagnostics }: TimelineListProps) {
|
|
112
|
+
export function TimelineList({ namespaces, onViewChange, currentView, onResourceClick, initialFilter, initialTimeRange, showDeleted, onShowDeletedChange, showRoutine, onShowRoutineChange, search, onSearchChange, activityFilter, onActivityFilterChange, kindFilter, onKindFilterChange, selectionWindow, onVisibleWindowChange, scrollToMs, focusedAppIndex, appScoped = false, topology, appScopeLoading = false, onOpenDiagnostics, selectedEventId, onSelectEvent }: TimelineListProps) {
|
|
101
113
|
const hasLimitedAccess = useHasLimitedAccess()
|
|
102
114
|
const timelineSource = useTimelineSource()
|
|
103
115
|
const [queryParams, setQueryParams] = useState<{ timeRange: TimeRange; kinds: string[] }>({
|
|
@@ -127,8 +139,8 @@ export function TimelineList({ namespaces, onViewChange, currentView, onResource
|
|
|
127
139
|
})
|
|
128
140
|
const loadError = useStickyError(error, fetchedEvents != null)
|
|
129
141
|
const split = useMemo(
|
|
130
|
-
() => (splitRows && fetchedEvents ? splitRoutineActivity(fetchedEvents, fetchLimit) : undefined),
|
|
131
|
-
[splitRows, fetchedEvents, fetchLimit],
|
|
142
|
+
() => (splitRows && fetchedEvents ? splitRoutineActivity(fetchedEvents, fetchLimit, selectedEventId) : undefined),
|
|
143
|
+
[splitRows, fetchedEvents, fetchLimit, selectedEventId],
|
|
132
144
|
)
|
|
133
145
|
const events = useMemo(() => {
|
|
134
146
|
const unscoped = split ? (showRoutine ? split.withRoutine : split.withoutRoutine) : fetchedEvents ?? []
|
|
@@ -204,6 +216,8 @@ export function TimelineList({ namespaces, onViewChange, currentView, onResource
|
|
|
204
216
|
onKindFilterChange={onKindFilterChange}
|
|
205
217
|
onVisibleWindowChange={onVisibleWindowChange}
|
|
206
218
|
scrollToMs={scrollToMs}
|
|
219
|
+
selectedEventId={selectedEventId}
|
|
220
|
+
onSelectEvent={onSelectEvent}
|
|
207
221
|
truncatedAt={fetchLimit}
|
|
208
222
|
isTruncated={sourceTruncated}
|
|
209
223
|
truncationMessage={appScoped && sourceTruncated
|
|
@@ -1060,6 +1060,8 @@ export function TimelineView({ namespaces, onResourceClick, initialViewMode, ini
|
|
|
1060
1060
|
topology={stableTopology}
|
|
1061
1061
|
appScopeLoading={focusedAppLoading}
|
|
1062
1062
|
onOpenDiagnostics={onOpenDiagnostics}
|
|
1063
|
+
selectedEventId={selectedEventId}
|
|
1064
|
+
onSelectEvent={setSelectedEventId}
|
|
1063
1065
|
/>
|
|
1064
1066
|
)
|
|
1065
1067
|
}
|