@skyhook-io/radar-app 1.18.2 → 1.20.0
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 -6
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +285 -55
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.test.ts +33 -2
- package/src/api/diagnose.ts +97 -3
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +41 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/diagnose/AIMarkdown.tsx +4 -1
- package/src/components/diagnose/ActivityTurn.tsx +34 -14
- package/src/components/diagnose/AgentControls.tsx +53 -6
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
- package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
- package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
- package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
- package/src/components/diagnose/AnalysisStory.tsx +17 -4
- package/src/components/diagnose/AssessmentCard.tsx +39 -8
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
- package/src/components/diagnose/DiagnoseContext.tsx +272 -10
- package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
- package/src/components/diagnose/EvidenceCard.tsx +67 -14
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +208 -5
- package/src/components/diagnose/Home.tsx +187 -36
- package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
- package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
- package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
- package/src/components/diagnose/InvestigationView.tsx +249 -54
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
- package/src/components/diagnose/QuestionComposer.tsx +495 -0
- package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
- package/src/components/diagnose/QuestionFocus.tsx +123 -0
- package/src/components/diagnose/ResourcePicker.tsx +206 -0
- package/src/components/diagnose/StoryExcerpt.tsx +12 -3
- package/src/components/diagnose/assessmentCopy.ts +5 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
- package/src/components/diagnose/investigationCase.test.tsx +9 -1
- package/src/components/diagnose/investigationCase.ts +33 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
- package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
- package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
- package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
- package/src/components/diagnose/investigationEvidence/index.ts +1 -1
- package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +7 -0
- package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
- package/src/components/diagnose/investigationFocus.test.ts +271 -0
- package/src/components/diagnose/investigationFocus.ts +132 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/parts.test.tsx +20 -0
- package/src/components/diagnose/questionSuggestions.test.ts +111 -0
- package/src/components/diagnose/questionSuggestions.ts +150 -0
- package/src/components/diagnose/storyParts.test.tsx +13 -0
- package/src/components/diagnose/target.test.ts +143 -2
- package/src/components/diagnose/target.ts +109 -7
- package/src/components/diagnose/testdata/story-runs.json +474 -0
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/diagnose/verdictText.test.tsx +87 -0
- package/src/components/diagnose/verdictText.ts +68 -0
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/home/ClusterHealthCard.tsx +13 -39
- package/src/components/home/HomeAgentBlock.test.tsx +141 -0
- package/src/components/home/HomeAgentBlock.tsx +103 -0
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +86 -47
- package/src/components/home/MCPSetupDialog.test.tsx +95 -5
- package/src/components/home/MCPSetupDialog.tsx +30 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/RadarVersionLine.test.tsx +0 -14
- package/src/components/home/RadarVersionLine.tsx +3 -28
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +23 -10
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +20 -1
- package/src/components/issues/uncheckedSources.ts +18 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
- package/src/components/ui/Omnibar.tsx +47 -3
- package/src/components/ui/RadarOmnibar.test.tsx +1 -0
- package/src/components/ui/RadarOmnibar.tsx +11 -0
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
- package/src/components/whats-new/releaseNotes.ts +136 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +6 -4
- package/src/hooks/useAgentSignin.test.tsx +190 -0
- package/src/hooks/useAgentSignin.ts +160 -0
- package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
- package/src/hooks/useElementSize.ts +30 -0
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +12 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -1,26 +1,63 @@
|
|
|
1
|
+
import { KueuePendingPosition } from '../../kueue/KueuePendingPosition'
|
|
1
2
|
import { Boxes } from 'lucide-react'
|
|
2
3
|
import { KueueWorkloadRenderer as BaseRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/KueueWorkloadRenderer'
|
|
3
|
-
import { getProvisioningRequestStatus, getProvisioningRequestMessage } from '@skyhook-io/k8s-ui/components/resources/resource-utils-kueue'
|
|
4
|
-
import { Badge, ResourceLink, Section, type ResourceRef } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { getProvisioningRequestStatus, getProvisioningRequestMessage, isKueueWorkloadEligibleForPendingPosition } from '@skyhook-io/k8s-ui/components/resources/resource-utils-kueue'
|
|
5
|
+
import { Badge, ResourceLink, Section, type Relationships, type ResourceRef } from '@skyhook-io/k8s-ui'
|
|
6
|
+
import { needsNamespaceLabels } from '@skyhook-io/k8s-ui/components/kueue/eligibility'
|
|
7
|
+
import { KUEUE_GROUP } from '@skyhook-io/k8s-ui/components/kueue/constants'
|
|
5
8
|
import { useKueueProvisioning } from '../../../api/client'
|
|
9
|
+
import { relatedReadKey, useRelatedObjects, useRelatedReads } from '../../kueue/useRelatedReads'
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
// Reads the Workload's admission path as the viewer: its LocalQueue, the
|
|
12
|
+
// ClusterQueue that LocalQueue names, the ClusterQueue holding a reservation
|
|
13
|
+
// when that differs, and the namespace's labels only when a selector needs them.
|
|
14
|
+
function useAdmissionPathReads(data: any) {
|
|
15
|
+
const namespace: string = data.metadata?.namespace ?? ''
|
|
16
|
+
const queueName: string = data.spec?.queueName ?? ''
|
|
17
|
+
const reserved: string = data.status?.admission?.clusterQueue ?? ''
|
|
18
|
+
const flavorNames = [...new Set<string>((data.status?.admission?.podSetAssignments ?? []).flatMap((assignment: any) => Object.values(assignment?.flavors ?? {}).map(String)))]
|
|
19
|
+
const key = relatedReadKey(data, [queueName, reserved, ...flavorNames], ['QuotaReserved', 'Admitted', 'Finished'])
|
|
20
|
+
const localQueue = useRelatedObjects('localqueues', KUEUE_GROUP, namespace, [queueName], !!queueName && !!namespace, key).byName[queueName]
|
|
21
|
+
const configured: string = localQueue?.state === 'found' ? localQueue.object?.spec?.clusterQueue ?? '' : ''
|
|
22
|
+
const names = [...new Set([configured, reserved].filter(Boolean))]
|
|
23
|
+
const queues = useRelatedObjects('clusterqueues', KUEUE_GROUP, undefined, names, names.length > 0, key)
|
|
24
|
+
const flavors = useRelatedObjects('resourceflavors', KUEUE_GROUP, undefined, flavorNames, flavorNames.length > 0, key)
|
|
25
|
+
const configuredRead = configured ? queues.byName[configured] : undefined
|
|
26
|
+
// Eligibility is shown only while unreserved, so a reserved Workload skips the Namespace read.
|
|
27
|
+
const needsLabels = !reserved && configuredRead?.state === 'found' && needsNamespaceLabels(configuredRead.object?.spec?.namespaceSelector)
|
|
28
|
+
const namespaceState = JSON.stringify([key, configured, needsLabels, configuredRead?.state === 'found' ? configuredRead.object?.spec?.namespaceSelector : null])
|
|
29
|
+
const [namespaceRead] = useRelatedReads([{ kind: 'namespaces', name: namespace }], needsLabels && !!namespace, namespaceState)
|
|
30
|
+
return {
|
|
31
|
+
localQueue: queueName ? localQueue : undefined,
|
|
32
|
+
clusterQueues: queues.byName,
|
|
33
|
+
flavors: flavors.byName,
|
|
34
|
+
namespace: needsLabels ? namespaceRead : undefined,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Keyed by UID so moving the drawer to another Workload starts its reads (and their mount time) afresh.
|
|
39
|
+
export function KueueWorkloadRenderer(props: { data: any; onNavigate?: (ref: ResourceRef) => void; relationships?: Relationships }) {
|
|
40
|
+
return <KueueWorkloadReads key={props.data.metadata?.uid} {...props} />
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function KueueWorkloadReads({ data, onNavigate, relationships }: { data: any; onNavigate?: (ref: ResourceRef) => void; relationships?: Relationships }) {
|
|
44
|
+
const reads = useAdmissionPathReads(data)
|
|
8
45
|
const namespace = data.metadata?.namespace ?? ''
|
|
9
46
|
const uid = data.metadata?.uid
|
|
10
47
|
const hasChecks = (data.status?.admissionChecks?.length ?? 0) > 0
|
|
11
48
|
const requests = useKueueProvisioning(namespace, data.metadata?.name ?? '', uid, hasChecks)
|
|
12
49
|
const current = requests.data?.uid === uid ? requests.data : undefined
|
|
13
|
-
const provisioning = hasChecks ? <Section title="Provisioning Requests" icon={Boxes} defaultExpanded>
|
|
50
|
+
const provisioning = hasChecks ? <Section variant="card" title="Provisioning Requests" icon={Boxes} defaultExpanded>
|
|
14
51
|
{requests.error ? <p className="text-sm text-warning-text">Could not observe provisioning requests: {requests.error.message}</p>
|
|
15
52
|
: !current ? <p className="text-sm text-theme-text-tertiary">Looking for provisioning requests…</p>
|
|
16
53
|
: !current.installed ? <p className="text-sm text-theme-text-tertiary">The ProvisioningRequest API is not served by this cluster.</p>
|
|
17
54
|
: current.requests.length === 0 ? <p className="text-sm text-theme-text-tertiary">No retained provisioning requests found on this cluster. A request may not be needed or may have been cleaned up. Check results above retain the controller’s explanation; requests on a MultiKueue worker cluster are not included.</p>
|
|
18
|
-
: <div className="space-y-
|
|
55
|
+
: <div className="space-y-3">
|
|
19
56
|
<p className="text-xs text-theme-text-tertiary">Currently retained requests owned by this Workload, not a retry history. Requests may be removed after completion or eviction.</p>
|
|
20
57
|
{current.requests.map(request => {
|
|
21
58
|
const status = getProvisioningRequestStatus(request)
|
|
22
59
|
const message = getProvisioningRequestMessage(request)
|
|
23
|
-
return <div key={request.metadata.uid} className="
|
|
60
|
+
return <div key={request.metadata.uid} className="border-t border-theme-border pt-3">
|
|
24
61
|
<div className="flex flex-wrap items-center gap-2 break-all [&_button]:text-left">
|
|
25
62
|
<ResourceLink kind="provisioningrequests" group="autoscaling.x-k8s.io" namespace={namespace} name={request.metadata.name} onNavigate={onNavigate} />
|
|
26
63
|
<Badge colorClass={status.color} size="sm">{status.text}</Badge>
|
|
@@ -33,5 +70,8 @@ export function KueueWorkloadRenderer({ data, onNavigate }: { data: any; onNavig
|
|
|
33
70
|
{current.truncated && <p className="text-xs text-theme-text-tertiary">Showing {current.requests.length} of {current.total} retained requests, newest first.</p>}
|
|
34
71
|
</div>}
|
|
35
72
|
</Section> : undefined
|
|
36
|
-
|
|
73
|
+
const pendingPosition = isKueueWorkloadEligibleForPendingPosition(data)
|
|
74
|
+
? <KueuePendingPosition namespace={namespace} name={data.metadata?.name ?? ''} uid={uid} queueName={data.spec?.queueName} requeueAt={data.status?.requeueState?.requeueAt} />
|
|
75
|
+
: undefined
|
|
76
|
+
return <BaseRenderer pendingPosition={pendingPosition} data={data} onNavigate={onNavigate} provisioning={provisioning} relationships={relationships} reads={reads} />
|
|
37
77
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { beforeEach, expect, it, vi } from 'vitest'
|
|
3
|
+
import { OpenTelemetryCollectorRenderer } from './OpenTelemetryCollectorRenderer'
|
|
4
|
+
|
|
5
|
+
const read = vi.hoisted(() => vi.fn())
|
|
6
|
+
vi.mock('../../../api/client', () => ({ useResource: read }))
|
|
7
|
+
const root = { apiVersion: 'opentelemetry.io/v1beta1', kind: 'OpenTelemetryCollector', metadata: { name: 'collector', namespace: 'observe', uid: 'root' }, spec: { mode: 'deployment', config: {} } }
|
|
8
|
+
const reference = { group: 'apps', kind: 'Deployment', namespace: 'observe', name: 'runtime' }
|
|
9
|
+
const workload = { apiVersion: 'apps/v1', kind: 'Deployment', metadata: { namespace: 'observe', ownerReferences: [{ apiVersion: 'opentelemetry.io/v1beta1', kind: 'OpenTelemetryCollector', name: 'collector', uid: 'root', controller: true }] }, spec: { replicas: 0 }, status: {} }
|
|
10
|
+
|
|
11
|
+
beforeEach(() => read.mockReset())
|
|
12
|
+
|
|
13
|
+
it('separates current scaled-to-zero workload state from operator readiness', () => {
|
|
14
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: true } } } } : { data: workload })
|
|
15
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
16
|
+
expect(html).toContain('Current Workloads')
|
|
17
|
+
expect(html).toContain('Deployment / runtime')
|
|
18
|
+
expect(html).toContain('Scaled to 0')
|
|
19
|
+
expect(html).not.toContain('Not currently controlled')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('does not attribute a replaced workload to the current Collector', () => {
|
|
23
|
+
const replaced = structuredClone(workload)
|
|
24
|
+
replaced.metadata.ownerReferences[0].uid = 'old-root'
|
|
25
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: true } } } } : { data: replaced })
|
|
26
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
27
|
+
expect(html).toContain('Not currently controlled')
|
|
28
|
+
expect(html).not.toContain('Scaled to 0')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('keeps unknown evidence and sidecar emptiness neutral and explicit', () => {
|
|
32
|
+
read.mockReturnValue({})
|
|
33
|
+
expect(renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)).toContain('Owned-workload evidence is unavailable')
|
|
34
|
+
read.mockReturnValue({ relationships: { children: [], ownership: { children: { complete: true, narrowed: true } } } })
|
|
35
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={{ ...root, spec: { ...root.spec, mode: 'sidecar' } }} />)
|
|
36
|
+
expect(html).toContain('Sidecar mode runs inside annotated application Pods')
|
|
37
|
+
expect(html).toContain('Only resources you can read are shown')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('bounds automatic workload reads while leaving additional objects followable', () => {
|
|
41
|
+
const children = Array.from({ length: 30 }, (_, index) => ({ ...reference, name: `runtime-${index}` }))
|
|
42
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children, ownership: { children: { complete: true } } } } : { data: workload })
|
|
43
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
44
|
+
expect(read).toHaveBeenCalledTimes(4)
|
|
45
|
+
expect(html).toContain('This workload preview is incomplete')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('does not warn about workload coverage because unrelated CRD kinds are uncollected', () => {
|
|
49
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: false, notChecked: [{ group: 'example.io', kind: 'Widget', reason: 'radar_kind_not_collected' }] } } } } : { data: workload })
|
|
50
|
+
const html = renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)
|
|
51
|
+
expect(html).toContain('Scaled to 0')
|
|
52
|
+
expect(html).not.toContain('preview is incomplete')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('shows an explicit partial workload preview when an apps inventory is unavailable', () => {
|
|
56
|
+
read.mockReturnValue({ relationships: { children: [], ownership: { children: { complete: false, notChecked: [{ group: 'apps', kind: 'DaemonSet', reason: 'kind_sync_pending' }] } } } })
|
|
57
|
+
expect(renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)).toContain('This workload preview is incomplete')
|
|
58
|
+
read.mockReturnValue({ isLoading: true })
|
|
59
|
+
expect(renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} />)).toContain('Reading owned workloads')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('pauses root and child reads while the resource view is inactive', () => {
|
|
63
|
+
read.mockImplementation((kind: string) => kind === 'opentelemetrycollectors' ? { relationships: { children: [reference], ownership: { children: { complete: true } } } } : { data: workload })
|
|
64
|
+
renderToStaticMarkup(<OpenTelemetryCollectorRenderer data={root} active={false} />)
|
|
65
|
+
expect(read).toHaveBeenCalledTimes(2)
|
|
66
|
+
for (const call of read.mock.calls) expect(call[4]).toMatchObject({ enabled: false, refetchInterval: false })
|
|
67
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OpenTelemetryCollectorRenderer as BaseRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/OpenTelemetryRenderers'
|
|
2
|
+
import { getWorkloadStatus } from '@skyhook-io/k8s-ui/components/resources/resource-utils'
|
|
3
|
+
import { Badge } from '@skyhook-io/k8s-ui/components/ui/Badge'
|
|
4
|
+
import { healthToSeverity } from '@skyhook-io/k8s-ui/utils/badge-colors'
|
|
5
|
+
import { Property, PropertyList, ResourceLink, Section } from '@skyhook-io/k8s-ui/components/ui/drawer-components'
|
|
6
|
+
import { apiVersionToGroup } from '@skyhook-io/k8s-ui/utils/navigation'
|
|
7
|
+
import type { ResourceRef } from '@skyhook-io/k8s-ui'
|
|
8
|
+
import { useResource } from '../../../api/client'
|
|
9
|
+
|
|
10
|
+
function OwnedWorkload({ root, reference, onNavigate, active }: { root: any; reference: ResourceRef; onNavigate?: (ref: ResourceRef) => void; active: boolean }) {
|
|
11
|
+
const kind = `${reference.kind.toLowerCase()}s`
|
|
12
|
+
const query = useResource<any>(kind, reference.namespace, reference.name, reference.group, { enabled: active, refetchInterval: active ? 30000 : false })
|
|
13
|
+
const workload = query.data
|
|
14
|
+
const owned = root.metadata.uid && workload?.metadata?.namespace === root.metadata.namespace && workload.metadata.ownerReferences?.some((owner: any) => owner.controller === true && apiVersionToGroup(owner.apiVersion) === 'opentelemetry.io' && owner.kind === 'OpenTelemetryCollector' && owner.name === root.metadata.name && owner.uid === root.metadata.uid)
|
|
15
|
+
const status = owned ? getWorkloadStatus(workload, kind) : undefined
|
|
16
|
+
return <Property label={<ResourceLink {...reference} label={`${reference.kind} / ${reference.name}`} onNavigate={onNavigate} />} value={query.error ? 'Could not read workload; open it for details.' : !workload ? 'Reading current status…' : !owned ? 'Not currently controlled by this Collector; status not attributed.' : <Badge severity={healthToSeverity(status!.level)}>{status!.text}</Badge>} />
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function OpenTelemetryCollectorRenderer({ data, onNavigate, active = true }: { data: any; onNavigate?: (ref: ResourceRef) => void; active?: boolean }) {
|
|
20
|
+
const root = useResource<any>('opentelemetrycollectors', data.metadata.namespace, data.metadata.name, 'opentelemetry.io', { enabled: active, refetchInterval: active ? 30000 : false })
|
|
21
|
+
const coverage = root.relationships?.ownership
|
|
22
|
+
const children = (root.relationships?.children ?? []).filter(ref => ref.group === 'apps' && ['Deployment', 'StatefulSet', 'DaemonSet'].includes(ref.kind))
|
|
23
|
+
const runtimeGap = coverage?.children.notChecked?.some(gap => !gap.kind || gap.group === 'apps' && ['Deployment', 'StatefulSet', 'DaemonSet'].includes(gap.kind))
|
|
24
|
+
const partial = !coverage || coverage.unavailableReason || runtimeGap || coverage.children.truncated
|
|
25
|
+
return <BaseRenderer data={data} workloadEvidence={<Section title="Current Workloads" defaultExpanded>
|
|
26
|
+
<p className="mb-2 text-xs text-theme-text-tertiary">Workloads this Collector runs. Ready Pods do not confirm that telemetry is delivered.</p>
|
|
27
|
+
{root.isLoading ? <p className="text-sm text-theme-text-secondary">Reading owned workloads…</p> : root.error ? <p className="text-sm text-theme-text-secondary">Could not read owned workloads. Retry or inspect Related Resources.</p> : !coverage ? <p className="text-sm text-theme-text-secondary">Owned-workload evidence is unavailable. Related Resources may provide more detail.</p> : children.length ? <PropertyList>{children.slice(0, 3).map(ref => <OwnedWorkload key={`${ref.group}/${ref.kind}/${ref.namespace}/${ref.name}`} root={data} reference={ref} onNavigate={onNavigate} active={active} />)}</PropertyList> : <p className="text-sm text-theme-text-secondary">No standalone workloads observed{partial ? ' in the available evidence' : ''}. {data.spec?.mode === 'sidecar' ? 'Sidecar mode runs inside annotated application Pods.' : 'Inspect reconciliation and management state if you expected a runtime.'}</p>}
|
|
28
|
+
{(partial || children.length > 3) && <p className="mt-2 text-xs text-theme-text-tertiary">This workload preview is incomplete. Inspect Related Resources for coverage and additional owned objects.</p>}
|
|
29
|
+
{coverage?.children.narrowed && <p className="mt-2 text-xs text-theme-text-tertiary">Only resources you can read are shown.</p>}
|
|
30
|
+
</Section>} />
|
|
31
|
+
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
1
4
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
5
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
6
|
import { RayClusterRenderer } from './RayClusterRenderer'
|
|
4
|
-
const mock = vi.hoisted(() => ({ result: {} as any, calls: [] as any[] }))
|
|
5
|
-
vi.mock('../../../api/client', () => ({
|
|
7
|
+
const mock = vi.hoisted(() => ({ result: {} as any, calls: [] as any[], canViewLogs: true, opened: [] as any[], support: 'supported' as string, logsUnknown: false, capsFailed: false }))
|
|
8
|
+
vi.mock('../../../api/client', () => ({
|
|
9
|
+
ApiError: class ApiError extends Error { constructor(message: string, public status: number) { super(message) } },
|
|
10
|
+
useWorkloadPods: (...args: any[]) => { mock.calls.push(args); return mock.result },
|
|
11
|
+
useCapabilities: () => ({ data: mock.capsFailed ? undefined : { features: { rayClusterPods: true, podSidecarMarks: true } }, isError: mock.capsFailed }),
|
|
12
|
+
isStableClientError: (e: any) => [400, 403, 404, 409].includes(e?.status),
|
|
13
|
+
useRadarFeature: () => ({ support: mock.support, upgrade: mock.support === 'unsupported' ? { feature: 'RayCluster runtime Pods', minimumVersion: 'v1.15.0' } : null }),
|
|
14
|
+
}))
|
|
15
|
+
vi.mock('../../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canViewLogs: mock.canViewLogs, logsUnknown: mock.logsUnknown }) }))
|
|
16
|
+
vi.mock('../../dock', () => ({ useOpenLogs: () => (opts: any) => mock.opened.push(opts) }))
|
|
17
|
+
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
|
6
18
|
const root = { apiVersion: 'ray.io/v1', kind: 'RayCluster', metadata: { name: 'cluster', namespace: 'ml', uid: 'current' } }
|
|
19
|
+
const worker = { name: 'cluster-cpu-worker-def', ready: true, containers: ['wait-gcs-ready', 'ray-worker'], containerStatuses: [{ name: 'ray-worker', ready: true, restartCount: 0 }, { name: 'wait-gcs-ready', init: true, ready: true, restartCount: 0 }] }
|
|
7
20
|
describe('RayCluster host evidence', () => {
|
|
8
|
-
beforeEach(() => { mock.result = {}; mock.calls = [] })
|
|
21
|
+
beforeEach(() => { mock.result = {}; mock.calls = []; mock.canViewLogs = true; mock.opened = []; mock.support = 'supported'; mock.logsUnknown = false; mock.capsFailed = false })
|
|
9
22
|
it('makes one bounded UID-bound query with polling', () => {
|
|
10
23
|
renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
11
24
|
expect(mock.calls).toEqual([['rayclusters', 'ml', 'cluster', { ownerUID: 'current', limit: 200, refetchInterval: 5000 }]])
|
|
@@ -15,4 +28,69 @@ describe('RayCluster host evidence', () => {
|
|
|
15
28
|
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
16
29
|
expect(html).toContain(message); expect(html).not.toContain('No directly owned Pods')
|
|
17
30
|
})
|
|
31
|
+
it('opens a verified Pod in the logs dock on its application container', () => {
|
|
32
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
33
|
+
const host = document.createElement('div')
|
|
34
|
+
const view = createRoot(host)
|
|
35
|
+
act(() => view.render(<RayClusterRenderer data={root} />))
|
|
36
|
+
act(() => host.querySelector<HTMLButtonElement>('[aria-label="Open logs for cluster-cpu-worker-def"]')!.click())
|
|
37
|
+
expect(mock.opened).toEqual([{ namespace: 'ml', podName: 'cluster-cpu-worker-def', containers: ['wait-gcs-ready', 'ray-worker'], containerName: 'ray-worker' }])
|
|
38
|
+
act(() => view.unmount())
|
|
39
|
+
})
|
|
40
|
+
it('opens a Pending worker in the init container it waits on', () => {
|
|
41
|
+
mock.result = { data: { pods: [{ ...worker, phase: 'Pending', containerStatuses: [{ name: 'wait-gcs-ready', init: true, ready: false, restartCount: 0 }, { name: 'ray-worker', ready: false, restartCount: 0 }] }], total: 1, truncated: false } }
|
|
42
|
+
const host = document.createElement('div')
|
|
43
|
+
const view = createRoot(host)
|
|
44
|
+
act(() => view.render(<RayClusterRenderer data={root} />))
|
|
45
|
+
act(() => host.querySelector<HTMLButtonElement>('[aria-label="Open logs for cluster-cpu-worker-def"]')!.click())
|
|
46
|
+
expect(mock.opened.at(-1).containerName).toBe('wait-gcs-ready')
|
|
47
|
+
act(() => view.unmount())
|
|
48
|
+
})
|
|
49
|
+
it('keeps the last Pod list, with its Logs buttons, through a passing refresh failure', async () => {
|
|
50
|
+
const { ApiError } = await import('../../../api/client') as any
|
|
51
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false }, error: new ApiError('Cluster connection changed; retry the Pod request', 503) }
|
|
52
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
53
|
+
expect(html).toContain('Open logs for cluster-cpu-worker-def')
|
|
54
|
+
expect(html).toContain('Pod list not refreshed: Cluster connection changed')
|
|
55
|
+
expect(html).not.toContain('Pod evidence unavailable')
|
|
56
|
+
})
|
|
57
|
+
it('offers no log links without permission to read Pod logs, and says so', () => {
|
|
58
|
+
mock.canViewLogs = false
|
|
59
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
60
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
61
|
+
expect(html).not.toContain('Open logs for'); expect(html).toContain('Pod logs need get on pods/log')
|
|
62
|
+
})
|
|
63
|
+
it('keeps log links while the namespace permission is unconfirmed', () => {
|
|
64
|
+
mock.canViewLogs = false
|
|
65
|
+
mock.logsUnknown = true
|
|
66
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
67
|
+
expect(renderToStaticMarkup(<RayClusterRenderer data={root} />)).toContain('Open logs for')
|
|
68
|
+
})
|
|
69
|
+
it('keeps log links when the global permission check has failed without an answer', () => {
|
|
70
|
+
mock.canViewLogs = false
|
|
71
|
+
mock.capsFailed = true
|
|
72
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false } }
|
|
73
|
+
expect(renderToStaticMarkup(<RayClusterRenderer data={root} />)).toContain('Open logs for')
|
|
74
|
+
})
|
|
75
|
+
it('withholds cached Pod evidence after a definitive access denial', async () => {
|
|
76
|
+
const { ApiError } = await import('../../../api/client') as any
|
|
77
|
+
mock.result = { data: { pods: [worker], total: 1, truncated: false }, error: new ApiError('Reading RayCluster Pods requires get rayclusters and list pods', 403) }
|
|
78
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
79
|
+
expect(html).toContain('Pod evidence unavailable')
|
|
80
|
+
expect(html).not.toContain('Open logs for')
|
|
81
|
+
expect(html).not.toContain('Pod list not refreshed')
|
|
82
|
+
})
|
|
83
|
+
it('names an unsupporting Radar rather than echoing its 400 when support is unknown', async () => {
|
|
84
|
+
const { ApiError } = await import('../../../api/client') as any
|
|
85
|
+
mock.support = 'unknown'
|
|
86
|
+
mock.result = { error: new ApiError('only deployments, statefulsets, daemonsets, rollouts, jobs, and workflows are supported', 400) }
|
|
87
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
88
|
+
expect(html).toContain('Radar v1.15 and later'); expect(html).not.toContain('only deployments')
|
|
89
|
+
})
|
|
90
|
+
it('does not ask an older Radar for Pods it cannot list, and says which Radar can', () => {
|
|
91
|
+
mock.support = 'unsupported'
|
|
92
|
+
const html = renderToStaticMarkup(<RayClusterRenderer data={root} />)
|
|
93
|
+
expect(mock.calls[0][2]).toBe('')
|
|
94
|
+
expect(html).toContain('RayCluster runtime Pods'); expect(html).toContain('v1.15')
|
|
95
|
+
})
|
|
18
96
|
})
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
2
|
import { RayClusterRenderer as BaseRenderer, type RayClusterPodSelection } from '@skyhook-io/k8s-ui/components/resources/renderers/RayClusterRenderer'
|
|
3
|
-
import type { ResourceRef } from '@skyhook-io/k8s-ui'
|
|
4
|
-
import { useWorkloadPods } from '../../../api/client'
|
|
3
|
+
import type { ResourceRef, WorkloadPodInfo } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { isStableClientError, useRadarFeature, useWorkloadPods } from '../../../api/client'
|
|
5
|
+
import { useOpenLogs } from '../../dock'
|
|
6
|
+
import { logsContainer } from '@skyhook-io/k8s-ui/components/resources/resource-utils-ray'
|
|
7
|
+
import { rayClusterPodsError, useLogsReadability, useSidecarsMarked } from '../../logs/rayClusterPods'
|
|
5
8
|
|
|
6
9
|
export function RayClusterRenderer(props: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
|
|
7
10
|
return <RayClusterEvidence key={props.data.metadata.uid} {...props} />
|
|
@@ -10,8 +13,20 @@ export function RayClusterRenderer(props: { data: any; onNavigate?: (ref: Resour
|
|
|
10
13
|
function RayClusterEvidence({ data, onNavigate }: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
|
|
11
14
|
const [requestedSelection, setSelection] = useState<RayClusterPodSelection>({})
|
|
12
15
|
const selection = requestedSelection.workerGroup != null && !(data.spec?.workerGroupSpecs ?? []).some((group: any) => group.groupName === requestedSelection.workerGroup) ? {} : requestedSelection
|
|
13
|
-
const
|
|
16
|
+
const { support, upgrade } = useRadarFeature('rayClusterPods')
|
|
17
|
+
const query = useWorkloadPods('rayclusters', data.metadata.namespace, data.metadata.uid && support !== 'unsupported' ? data.metadata.name : '', {
|
|
14
18
|
ownerUID: data.metadata.uid, ...selection, limit: 200, refetchInterval: 5000,
|
|
15
19
|
})
|
|
16
|
-
|
|
20
|
+
const logsReadable = useLogsReadability(data.metadata.namespace) !== 'denied'
|
|
21
|
+
// A refresh that fails for a passing reason keeps the last list, as the Logs tab does.
|
|
22
|
+
const kept = query.data && query.error && !isStableClientError(query.error)
|
|
23
|
+
const openLogs = useOpenLogs()
|
|
24
|
+
const sidecarsMarked = useSidecarsMarked()
|
|
25
|
+
const openPodLogs = (pod: WorkloadPodInfo) => openLogs({
|
|
26
|
+
namespace: data.metadata.namespace,
|
|
27
|
+
podName: pod.name,
|
|
28
|
+
containers: pod.containers,
|
|
29
|
+
containerName: logsContainer(pod, sidecarsMarked),
|
|
30
|
+
})
|
|
31
|
+
return <BaseRenderer data={data} onNavigate={onNavigate} selection={selection} onSelectPods={setSelection} podEvidence={query.data} podsLoading={query.isLoading} podsError={kept ? undefined : rayClusterPodsError(query.error, support)} podsNote={kept ? `Pod list not refreshed: ${rayClusterPodsError(query.error, support)}` : undefined} onOpenPodLogs={logsReadable ? openPodLogs : undefined} podLogsNote={logsReadable ? undefined : 'Pod logs need get on pods/log in this namespace.'} podsUpgrade={support === 'unsupported' ? upgrade : null} />
|
|
17
32
|
}
|
|
@@ -1308,7 +1308,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1308
1308
|
// source it names may since have gone. A retry detects again first, which
|
|
1309
1309
|
// also picks another available source, and the first failed connect gets
|
|
1310
1310
|
// one such retry on its own.
|
|
1311
|
-
const handleConnect = useCallback((redetect: boolean) => {
|
|
1311
|
+
const handleConnect = useCallback((redetect: boolean, automatic = false) => {
|
|
1312
1312
|
setIsConnecting(true)
|
|
1313
1313
|
setConnectionError(null)
|
|
1314
1314
|
queryClient.removeQueries({ queryKey: ['traffic-flows'] })
|
|
@@ -1324,7 +1324,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1324
1324
|
}
|
|
1325
1325
|
const detected = fresh ? detectSourcesAgain() : Promise.resolve(undefined)
|
|
1326
1326
|
detected.then(
|
|
1327
|
-
() => connectMutation.mutate(
|
|
1327
|
+
() => connectMutation.mutate({ automatic }, {
|
|
1328
1328
|
onSuccess: (data) => {
|
|
1329
1329
|
if (!data.connected && data.error) {
|
|
1330
1330
|
fail(data.error)
|
|
@@ -1355,7 +1355,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1355
1355
|
useEffect(() => {
|
|
1356
1356
|
if (wizardState === 'ready' && !hasAutoConnectedRef.current && !isConnecting) {
|
|
1357
1357
|
hasAutoConnectedRef.current = true
|
|
1358
|
-
handleConnect(false)
|
|
1358
|
+
handleConnect(false, true)
|
|
1359
1359
|
}
|
|
1360
1360
|
}, [wizardState, isConnecting, handleConnect])
|
|
1361
1361
|
|
|
@@ -0,0 +1,105 @@
|
|
|
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 { Omnibar } from './Omnibar'
|
|
6
|
+
import type { SearchHit } from '../../api/client'
|
|
7
|
+
|
|
8
|
+
vi.mock('../../api/usage-data', () => ({ recordUsageEvent: vi.fn() }))
|
|
9
|
+
|
|
10
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
11
|
+
let root: Root
|
|
12
|
+
let host: HTMLDivElement
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.useFakeTimers()
|
|
16
|
+
Element.prototype.scrollIntoView = vi.fn()
|
|
17
|
+
host = document.createElement('div')
|
|
18
|
+
document.body.appendChild(host)
|
|
19
|
+
root = createRoot(host)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
act(() => root.unmount())
|
|
24
|
+
host.remove()
|
|
25
|
+
document.body.innerHTML = ''
|
|
26
|
+
vi.useRealTimers()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
function render(onInvestigateQuery: ((query: { text: string; namespaces: string[] }) => void) | undefined, hits: SearchHit[] = []) {
|
|
30
|
+
act(() => {
|
|
31
|
+
root.render(<Omnibar onOpenResource={vi.fn()} commandItems={[]} searchData={{ hits }} onInvestigateQuery={onInvestigateQuery} />)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function typeQuery(text: string) {
|
|
36
|
+
const input = host.querySelector('input')!
|
|
37
|
+
act(() => input.focus())
|
|
38
|
+
act(() => {
|
|
39
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, text)
|
|
40
|
+
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
41
|
+
})
|
|
42
|
+
act(() => { vi.advanceTimersByTime(200) })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const investigateButton = () =>
|
|
46
|
+
[...document.body.querySelectorAll('button')].find((b) => b.textContent?.startsWith('Investigate “'))
|
|
47
|
+
|
|
48
|
+
describe('Omnibar investigate row', () => {
|
|
49
|
+
it('hands the typed words to the host as a question', () => {
|
|
50
|
+
const onInvestigate = vi.fn()
|
|
51
|
+
render(onInvestigate)
|
|
52
|
+
typeQuery('checkout returns 502s')
|
|
53
|
+
const row = investigateButton()
|
|
54
|
+
expect(row?.textContent).toContain('Investigate “checkout returns 502s”')
|
|
55
|
+
act(() => { row!.click() })
|
|
56
|
+
expect(onInvestigate).toHaveBeenCalledWith({ text: 'checkout returns 502s', namespaces: [] })
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('comes after a resource match', () => {
|
|
60
|
+
render(vi.fn(), [{ score: 1, kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'checkout' }])
|
|
61
|
+
typeQuery('checkout')
|
|
62
|
+
const rows = [...document.body.querySelectorAll('[data-selected]')]
|
|
63
|
+
expect(rows.at(-1)?.textContent).toContain('Investigate “checkout”')
|
|
64
|
+
expect(rows[0]?.textContent).not.toContain('Investigate')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('waits for search results before Enter can ask', () => {
|
|
68
|
+
const onInvestigate = vi.fn()
|
|
69
|
+
act(() => {
|
|
70
|
+
root.render(<Omnibar onOpenResource={vi.fn()} commandItems={[]} searchData={{ hits: [] }} isFetching onInvestigateQuery={onInvestigate} />)
|
|
71
|
+
})
|
|
72
|
+
typeQuery('checkout')
|
|
73
|
+
act(() => {
|
|
74
|
+
host.querySelector('input')!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }))
|
|
75
|
+
})
|
|
76
|
+
expect(onInvestigate).not.toHaveBeenCalled()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('is absent when the host has no question entry', () => {
|
|
80
|
+
render(undefined)
|
|
81
|
+
typeQuery('checkout returns 502s')
|
|
82
|
+
expect(investigateButton()).toBeUndefined()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('carries ns: modifiers as where to start', () => {
|
|
86
|
+
const onInvestigate = vi.fn()
|
|
87
|
+
act(() => {
|
|
88
|
+
root.render(<Omnibar onOpenResource={vi.fn()} commandItems={[]} searchData={{ hits: [] }} seedNamespaces={['payments']} onInvestigateQuery={onInvestigate} />)
|
|
89
|
+
})
|
|
90
|
+
typeQuery('slow checkout')
|
|
91
|
+
expect(investigateButton()?.textContent).toContain('as a question · in payments')
|
|
92
|
+
act(() => { investigateButton()!.click() })
|
|
93
|
+
expect(onInvestigate).toHaveBeenCalledWith({ text: 'slow checkout', namespaces: ['payments'] })
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('counts a long namespace list instead of naming it', () => {
|
|
97
|
+
const namespaces = Array.from({ length: 25 }, (_, i) => `ns-${i}`)
|
|
98
|
+
act(() => {
|
|
99
|
+
root.render(<Omnibar onOpenResource={vi.fn()} commandItems={[]} searchData={{ hits: [] }} seedNamespaces={namespaces} onInvestigateQuery={vi.fn()} />)
|
|
100
|
+
})
|
|
101
|
+
typeQuery('pods keep restarting')
|
|
102
|
+
expect(investigateButton()?.textContent).toContain('Investigate “pods keep restarting”')
|
|
103
|
+
expect(investigateButton()?.textContent).toContain('as a question · in 25 namespaces')
|
|
104
|
+
})
|
|
105
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useMemo, useRef, useEffect, useCallback, forwardRef, useImperativeHandle, type ReactNode } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
|
-
import { Search, CornerDownLeft, Loader2, AlertTriangle, Info } from 'lucide-react'
|
|
3
|
+
import { Search, CornerDownLeft, Loader2, AlertTriangle, Info, Sparkles } from 'lucide-react'
|
|
4
4
|
import { clsx } from 'clsx'
|
|
5
5
|
import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
|
|
6
6
|
import { TRANSITION_BACKDROP, TRANSITION_MENU, TW_EASE_UI, overlayExitMs, overlayTransitionStyle } from '../../utils/animation'
|
|
@@ -136,6 +136,11 @@ export interface OmnibarProps {
|
|
|
136
136
|
* searching, handing the full (uncapped) query off to the host's dedicated
|
|
137
137
|
* search surface. Omit to keep the omnibar a pure launcher. */
|
|
138
138
|
onViewAllResults?: (query: string) => void
|
|
139
|
+
/** When set, an "Investigate" row tails the list while there is free text,
|
|
140
|
+
* handing the words, and any `ns:` modifiers as where to start, to the
|
|
141
|
+
* host's AI investigation composer as a question. It is last so a
|
|
142
|
+
* resource or command match always comes first. */
|
|
143
|
+
onInvestigateQuery?: (query: { text: string; namespaces: string[] }) => void
|
|
139
144
|
/** Empty-launcher content. `true` (default) lists Views + Actions — the
|
|
140
145
|
* cmd-K menu. `false` shows only Actions so recents/search lead and views
|
|
141
146
|
* surface on type (use when the views are already always-visible, e.g. a
|
|
@@ -153,6 +158,7 @@ type Row =
|
|
|
153
158
|
| { id: string; kind: 'resource'; hit: SearchHit; recent?: boolean }
|
|
154
159
|
| { id: string; kind: 'command'; command: CommandItem }
|
|
155
160
|
| { id: string; kind: 'viewAll'; query: string; count: number }
|
|
161
|
+
| { id: string; kind: 'investigate'; text: string; namespaces: string[] }
|
|
156
162
|
|
|
157
163
|
const COMMAND_CATEGORY_ORDER = ['Views', 'Resource Kinds', 'Namespaces', 'Clusters', 'Actions']
|
|
158
164
|
const PAGE = 8
|
|
@@ -184,6 +190,7 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
184
190
|
loadRecents,
|
|
185
191
|
recordRecent,
|
|
186
192
|
onViewAllResults,
|
|
193
|
+
onInvestigateQuery,
|
|
187
194
|
launcherShowsViews = true,
|
|
188
195
|
placeholder = 'Search resources & commands…',
|
|
189
196
|
size = 'default',
|
|
@@ -330,9 +337,18 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
330
337
|
if (onViewAllResults && searchActive && resourceRows.length > 0) {
|
|
331
338
|
out.push({ id: 'view-all', kind: 'viewAll', query: queryString, count: searchData?.total_matched ?? resourceRows.length })
|
|
332
339
|
}
|
|
340
|
+
if (onInvestigateQuery && freeText) {
|
|
341
|
+
out.push({
|
|
342
|
+
id: 'investigate',
|
|
343
|
+
kind: 'investigate',
|
|
344
|
+
text: freeText,
|
|
345
|
+
namespaces: pills.filter((pill) => pill.key === 'ns').map((pill) => pill.value),
|
|
346
|
+
})
|
|
347
|
+
}
|
|
333
348
|
return out
|
|
334
|
-
}, [recentRows, leadingKinds, resourceRows, commandGroups, freeText, pills
|
|
349
|
+
}, [recentRows, leadingKinds, resourceRows, commandGroups, freeText, pills, searchActive, onViewAllResults, onInvestigateQuery, queryString, searchData])
|
|
335
350
|
const viewAllRow = rows.find((r): r is Extract<Row, { kind: 'viewAll' }> => r.kind === 'viewAll')
|
|
351
|
+
const investigateRow = rows.find((r): r is Extract<Row, { kind: 'investigate' }> => r.kind === 'investigate')
|
|
336
352
|
|
|
337
353
|
// Selection tracked by stable id (not array index) so Enter can never fire a
|
|
338
354
|
// stale row when the set shifts. Auto-follows the TOP result until the user
|
|
@@ -385,13 +401,15 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
385
401
|
row.command.action()
|
|
386
402
|
} else if (row.kind === 'viewAll') {
|
|
387
403
|
onViewAllResults?.(row.query)
|
|
404
|
+
} else if (row.kind === 'investigate') {
|
|
405
|
+
onInvestigateQuery?.({ text: row.text, namespaces: row.namespaces })
|
|
388
406
|
} else {
|
|
389
407
|
const h = row.hit
|
|
390
408
|
recordRecent?.({ kind: h.kind, group: h.group, namespace: h.namespace, name: h.name, cluster: h.cluster, clusterName: h.clusterName })
|
|
391
409
|
onOpenResource(h)
|
|
392
410
|
}
|
|
393
411
|
close()
|
|
394
|
-
}, [onOpenResource, recordRecent, onViewAllResults, close])
|
|
412
|
+
}, [onOpenResource, recordRecent, onViewAllResults, onInvestigateQuery, close])
|
|
395
413
|
|
|
396
414
|
// The resources shown don't (yet) belong to the current query: the debounce
|
|
397
415
|
// hasn't fired, the data is React Query placeholder, or results haven't landed.
|
|
@@ -412,6 +430,9 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
412
430
|
const row = rows[selectedIndex]
|
|
413
431
|
if (row) {
|
|
414
432
|
if (row.kind === 'resource' && resourcesStale) return
|
|
433
|
+
// Investigate sits first only until results land; an Enter before
|
|
434
|
+
// then is someone looking for a resource, not asking a question.
|
|
435
|
+
if (row.kind === 'investigate' && resourcesStale && !userMovedRef.current) return
|
|
415
436
|
execute(row)
|
|
416
437
|
return
|
|
417
438
|
}
|
|
@@ -567,6 +588,29 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
567
588
|
<CornerDownLeft className="w-3 h-3 ml-auto shrink-0 text-theme-text-tertiary" />
|
|
568
589
|
</button>
|
|
569
590
|
)}
|
|
591
|
+
|
|
592
|
+
{investigateRow && (
|
|
593
|
+
<button
|
|
594
|
+
type="button"
|
|
595
|
+
data-selected={investigateRow.id === selectedId}
|
|
596
|
+
onMouseEnter={() => selectRow(investigateRow.id)}
|
|
597
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
598
|
+
onClick={() => execute(investigateRow)}
|
|
599
|
+
className={clsx('w-full flex items-center gap-2.5 px-3 py-1.5 mt-1 text-left border-t border-theme-border transition-colors', investigateRow.id === selectedId ? 'selection' : 'hover:bg-theme-elevated/40')}
|
|
600
|
+
>
|
|
601
|
+
<Sparkles className="w-4 h-4 shrink-0 text-accent" />
|
|
602
|
+
<span className="min-w-0 truncate text-sm text-theme-text-primary">Investigate “{investigateRow.text}”</span>
|
|
603
|
+
{/* The words come first; a long namespace list must not squeeze them out. */}
|
|
604
|
+
<span className="max-w-[45%] shrink-0 truncate text-xs text-theme-text-tertiary">
|
|
605
|
+
as a question{investigateRow.namespaces.length > 2
|
|
606
|
+
? ` · in ${investigateRow.namespaces.length} namespaces`
|
|
607
|
+
: investigateRow.namespaces.length > 0
|
|
608
|
+
? ` · in ${investigateRow.namespaces.join(', ')}`
|
|
609
|
+
: ''}
|
|
610
|
+
</span>
|
|
611
|
+
<CornerDownLeft className="w-3 h-3 ml-auto shrink-0 text-theme-text-tertiary" />
|
|
612
|
+
</button>
|
|
613
|
+
)}
|
|
570
614
|
</div>
|
|
571
615
|
<div className="flex items-center gap-3 px-3 py-1.5 border-t border-theme-border text-[11px] text-theme-text-tertiary">
|
|
572
616
|
<span className="flex items-center gap-1">
|
|
@@ -7,6 +7,7 @@ import type { SearchCoverageEntry } from './searchCoverageNote'
|
|
|
7
7
|
import { coverageOf } from './searchCoverage.fixtures'
|
|
8
8
|
|
|
9
9
|
vi.mock('../../api/usage-data', () => ({ recordUsageEvent: vi.fn() }))
|
|
10
|
+
vi.mock('../diagnose/DiagnoseContext', () => ({ useDiagnose: () => ({ available: false, questions: false, openQuestion: vi.fn() }) }))
|
|
10
11
|
vi.mock('../../hooks/useRecentResources', () => ({ loadRecentResources: () => [], recordRecentResource: vi.fn() }))
|
|
11
12
|
vi.mock('../../api/apiResources', async (importOriginal) => ({ ...(await importOriginal<object>()), useAPIResources: () => ({ data: [] }) }))
|
|
12
13
|
vi.mock('./command-items', async (importOriginal) => ({ ...(await importOriginal<object>()), useCommandItems: () => [] }))
|
|
@@ -5,6 +5,7 @@ import { useAPIResources } from '../../api/apiResources'
|
|
|
5
5
|
import { loadRecentResources, recordRecentResource } from '../../hooks/useRecentResources'
|
|
6
6
|
import { useCommandItems, type CommandItemCallbacks } from './command-items'
|
|
7
7
|
import { PENDING_RETRY_BUDGET_MS, PENDING_RETRY_MS, searchCoverageNote } from './searchCoverageNote'
|
|
8
|
+
import { useDiagnose } from '../diagnose/DiagnoseContext'
|
|
8
9
|
|
|
9
10
|
interface RadarOmnibarProps extends CommandItemCallbacks {
|
|
10
11
|
onOpenResource: (hit: SearchHit) => void
|
|
@@ -55,6 +56,15 @@ export const RadarOmnibar = forwardRef<OmnibarHandle, RadarOmnibarProps>(functio
|
|
|
55
56
|
}), [nsScope, apiResources])
|
|
56
57
|
|
|
57
58
|
const commandItems = useCommandItems(callbacks)
|
|
59
|
+
// Words that find nothing (or more than a lookup) can become a question;
|
|
60
|
+
// the composer opens with them so where and since when stay visible.
|
|
61
|
+
const diagnose = useDiagnose()
|
|
62
|
+
const onInvestigateQuery = diagnose.available && diagnose.questions
|
|
63
|
+
? // The omnibar seeds its ns: pills from the namespace picker, so no pill
|
|
64
|
+
// means the engineer cleared the scope: start across the cluster.
|
|
65
|
+
({ text, namespaces }: { text: string; namespaces: string[] }) =>
|
|
66
|
+
diagnose.openQuestion({ text, namespaces })
|
|
67
|
+
: undefined
|
|
58
68
|
const { onNavigateKind } = callbacks
|
|
59
69
|
const note = searchCoverageNote(searchData?.coverage, {
|
|
60
70
|
hits: searchData?.hits,
|
|
@@ -80,6 +90,7 @@ export const RadarOmnibar = forwardRef<OmnibarHandle, RadarOmnibarProps>(functio
|
|
|
80
90
|
note={note}
|
|
81
91
|
modifierOptions={modifierOptions}
|
|
82
92
|
seedNamespaces={nsScope?.actives}
|
|
93
|
+
onInvestigateQuery={onInvestigateQuery}
|
|
83
94
|
loadRecents={() => loadRecentResources(contextKey)}
|
|
84
95
|
recordRecent={(r) => recordRecentResource(r, contextKey)}
|
|
85
96
|
/>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { expect, it, vi } from 'vitest'
|
|
5
|
+
import { bestScore, useCommandItems } from './command-items'
|
|
6
|
+
vi.mock('../../api/client', () => ({ useNamespaces: () => ({ data: [] }), useContexts: () => ({ data: [] }) }))
|
|
7
|
+
vi.mock('../../api/apiResources', () => ({ CORE_RESOURCES: [], useAPIResources: () => ({ data: [{ group: 'apiextensions.k8s.io', kind: 'CustomResourceDefinition', name: 'customresourcedefinitions', verbs: ['list'] }, { group: '', kind: 'Pod', name: 'pods', verbs: ['list'] }] }) }))
|
|
8
|
+
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
|
|
9
|
+
it('uses the shared CRD aliases in command items', () => {
|
|
10
|
+
let scores: number[] = []
|
|
11
|
+
function Probe() {
|
|
12
|
+
const cb = { onNavigateView: vi.fn(), onNavigateKind: vi.fn(), onSwitchContext: vi.fn(), onSetNamespaces: vi.fn(), onToggleTheme: vi.fn() }
|
|
13
|
+
const items = useCommandItems(cb)
|
|
14
|
+
scores = items.filter(i => i.category === 'Resource Kinds').map(i => bestScore(i, 'crd'))
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
const host = document.createElement('div'); const root = createRoot(host)
|
|
18
|
+
act(() => root.render(<Probe />))
|
|
19
|
+
expect(scores).toHaveLength(2)
|
|
20
|
+
expect(scores[0]).toBeGreaterThan(0)
|
|
21
|
+
expect(scores[1]).toBe(0)
|
|
22
|
+
act(() => root.unmount())
|
|
23
|
+
})
|