@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,10 +1,11 @@
|
|
|
1
|
+
import { RelatedFindingsSection } from './RelatedFindingsSection'
|
|
1
2
|
import { decorateResourceDiagnose, resourceDetailRedirect, resourceDetailSlots, resourceLogs, resourceRendererOverrides } from '../../integrations/resourceHosts'
|
|
3
|
+
import { ApplicationEvidenceAction } from '../application-evidence/ApplicationEvidenceAction'
|
|
2
4
|
import { useMemo, useEffect, useCallback, useRef, useState, type ReactNode } from 'react'
|
|
3
5
|
import { useQueries, useQueryClient } from '@tanstack/react-query'
|
|
4
6
|
import { Navigate, useNavigate, useLocation, useSearchParams } from 'react-router-dom'
|
|
5
7
|
import { workloadPodAwaitsScheduling } from '../capacity/podDemandGate'
|
|
6
|
-
import {
|
|
7
|
-
import { Terminal, Stethoscope } from 'lucide-react'
|
|
8
|
+
import { Stethoscope } from 'lucide-react'
|
|
8
9
|
import {
|
|
9
10
|
WorkloadView as BaseWorkloadView,
|
|
10
11
|
EditableYamlView,
|
|
@@ -55,7 +56,6 @@ import {
|
|
|
55
56
|
fetchWorkloadHistoryPage,
|
|
56
57
|
useChanges,
|
|
57
58
|
useResourceWithRelationships,
|
|
58
|
-
usePodLogs,
|
|
59
59
|
useTopology,
|
|
60
60
|
useUpdateResource,
|
|
61
61
|
usePreviewResources,
|
|
@@ -101,11 +101,14 @@ import { WorkloadCostTab } from '../cost/WorkloadCostTab'
|
|
|
101
101
|
import { isOpenCostWorkloadKind } from '../cost/kinds'
|
|
102
102
|
import { isRadarFeatureUnsupported } from '../../api/radarFeatures'
|
|
103
103
|
import { useTrafficAvailable } from '../../api/traffic'
|
|
104
|
-
import { useResourceAudit, useResourceIssues, useSubjectIssues, useRadarFeature, useTrace, fetchTraceWithProbes, fetchInClusterCapability, runInClusterMerged } from '../../api/client'
|
|
104
|
+
import { isNotFoundError, useResourceAudit, useResourceIssues, useSubjectIssues, useRadarFeature, useTrace, fetchTraceWithProbes, fetchInClusterCapability, runInClusterMerged } from '../../api/client'
|
|
105
105
|
import { AuditAlerts, getRadarUpgradeRequirement, ResourceIssuesSection, ReachabilityView, TraceSummary, InClusterConsentDialog, traceFingerprint, staticPollUnreliable, summarizeInClusterTests, type Trace as NetworkTrace, type InClusterCapability, inClusterConsentGiven, consentRequestRows } from '@skyhook-io/k8s-ui'
|
|
106
106
|
import { WorkloadLogsViewer } from '../logs/WorkloadLogsViewer'
|
|
107
107
|
import { ScheduledWorkloadLogsViewer } from '../logs/ScheduledWorkloadLogsViewer'
|
|
108
108
|
import { LogsViewer } from '../logs/LogsViewer'
|
|
109
|
+
import { MultiPodLogsTab } from '../logs/MultiPodLogsTab'
|
|
110
|
+
import { RayClusterLogsTab } from '../logs/RayClusterLogsTab'
|
|
111
|
+
import { isKubeRayCluster } from '../logs/rayClusterPods'
|
|
109
112
|
import { BatchExecutionFullscreen } from '../execution/BatchExecutionView'
|
|
110
113
|
import { workloadRunTimelineEvents } from '../execution/batch-timeline'
|
|
111
114
|
import {
|
|
@@ -131,8 +134,20 @@ import { useDesktopDownload } from '../../hooks/useDesktopDownload'
|
|
|
131
134
|
import { useCompareLauncher } from '../compare/useCompareLauncher'
|
|
132
135
|
import { useDiagnoseCustomization } from '../../context/DiagnoseCustomization'
|
|
133
136
|
import { NodeDrainStatus } from './NodeDrainStatus'
|
|
137
|
+
import { recordUsageEvent } from '../../api/usage-data'
|
|
138
|
+
import { issueResourceOpener } from './issueResourceOpener'
|
|
134
139
|
|
|
135
140
|
type TabType = WorkloadTabType
|
|
141
|
+
|
|
142
|
+
// The usage-report view a tab counts under. Timeline holds the resource's
|
|
143
|
+
// events (it replaced the Events tab), so it counts as panel:events.
|
|
144
|
+
const PANEL_USAGE_VIEWS: Partial<Record<TabType, string>> = {
|
|
145
|
+
logs: 'panel:logs',
|
|
146
|
+
yaml: 'panel:yaml',
|
|
147
|
+
metrics: 'panel:metrics',
|
|
148
|
+
timeline: 'panel:events',
|
|
149
|
+
}
|
|
150
|
+
|
|
136
151
|
const BATCH_EXECUTION_KINDS = new Set([
|
|
137
152
|
'Job',
|
|
138
153
|
'CronJob',
|
|
@@ -357,6 +372,8 @@ function useActionsBarProps(
|
|
|
357
372
|
const argoRefreshMutation = useArgoRefresh()
|
|
358
373
|
const argoSuspendMutation = useArgoSuspend()
|
|
359
374
|
const argoResumeMutation = useArgoResume()
|
|
375
|
+
const { upgrade: argoResumeUpgrade, blockedReason: argoResumeBlockedReason } = useRadarFeature('argoAutoSyncEnable')
|
|
376
|
+
const { support: argoInheritanceSupport } = useRadarFeature('argoSyncInheritance')
|
|
360
377
|
|
|
361
378
|
const {
|
|
362
379
|
data: cascadePreview,
|
|
@@ -461,9 +478,10 @@ function useActionsBarProps(
|
|
|
461
478
|
onFluxResume: (params: Parameters<typeof fluxResumeMutation.mutate>[0]) =>
|
|
462
479
|
fluxResumeMutation.mutate(params),
|
|
463
480
|
isFluxResuming: fluxResumeMutation.isPending,
|
|
464
|
-
onArgoSync: (params: Parameters<typeof argoSyncMutation.
|
|
465
|
-
argoSyncMutation.
|
|
481
|
+
onArgoSync: (params: Parameters<typeof argoSyncMutation.mutateAsync>[0]) =>
|
|
482
|
+
argoSyncMutation.mutateAsync(params),
|
|
466
483
|
isArgoSyncing: argoSyncMutation.isPending,
|
|
484
|
+
argoSyncDialog: { pinsComparedRevision: argoInheritanceSupport === 'supported' },
|
|
467
485
|
onArgoRefresh: (params: Parameters<typeof argoRefreshMutation.mutate>[0]) =>
|
|
468
486
|
argoRefreshMutation.mutate(params),
|
|
469
487
|
isArgoRefreshing: argoRefreshMutation.isPending,
|
|
@@ -473,6 +491,8 @@ function useActionsBarProps(
|
|
|
473
491
|
onArgoResume: (params: Parameters<typeof argoResumeMutation.mutate>[0]) =>
|
|
474
492
|
argoResumeMutation.mutate(params),
|
|
475
493
|
isArgoResuming: argoResumeMutation.isPending,
|
|
494
|
+
argoResumeUpgrade,
|
|
495
|
+
argoResumeBlockedReason,
|
|
476
496
|
canNodeWrite,
|
|
477
497
|
onCordonNode: (params: Parameters<typeof cordonMutation.mutate>[0]) =>
|
|
478
498
|
cordonMutation.mutate(params),
|
|
@@ -526,8 +546,14 @@ export function WorkloadView({
|
|
|
526
546
|
? 'reachability' // the network tab was renamed Reachability
|
|
527
547
|
: (rawTab as TabType) || 'overview'
|
|
528
548
|
|
|
549
|
+
|
|
550
|
+
// A panel counts when someone switches to it. Counting renders instead would
|
|
551
|
+
// recount the same open tab: the drawer mounts hidden WorkloadView layers
|
|
552
|
+
// for expand-on-hover and crossfades.
|
|
529
553
|
const handleTabChange = useCallback(
|
|
530
554
|
(tab: TabType, opts?: { replace?: boolean }) => {
|
|
555
|
+
const panel = PANEL_USAGE_VIEWS[tab]
|
|
556
|
+
if (panel && tab !== migratedTab) recordUsageEvent({ type: 'view', name: panel })
|
|
531
557
|
const params = new URLSearchParams(searchParams)
|
|
532
558
|
if (tab === 'overview') {
|
|
533
559
|
params.delete('tab')
|
|
@@ -536,7 +562,7 @@ export function WorkloadView({
|
|
|
536
562
|
}
|
|
537
563
|
setSearchParams(params, { replace: opts?.replace ?? !pushTabHistory, state: location.state })
|
|
538
564
|
},
|
|
539
|
-
[pushTabHistory, searchParams, setSearchParams, location.state],
|
|
565
|
+
[migratedTab, pushTabHistory, searchParams, setSearchParams, location.state],
|
|
540
566
|
)
|
|
541
567
|
|
|
542
568
|
const selectedRunKey = searchParams.get('run') ?? ''
|
|
@@ -549,6 +575,13 @@ export function WorkloadView({
|
|
|
549
575
|
},
|
|
550
576
|
[searchParams, setSearchParams],
|
|
551
577
|
)
|
|
578
|
+
// A pushed entry, so Back returns to the graph.
|
|
579
|
+
const handleSelectTopologyMember = useCallback(
|
|
580
|
+
(memberKey: string) => {
|
|
581
|
+
setSearchParams(memberOverviewParams(searchParams, memberKey), { state: location.state })
|
|
582
|
+
},
|
|
583
|
+
[searchParams, setSearchParams, location.state],
|
|
584
|
+
)
|
|
552
585
|
|
|
553
586
|
// Fetch resource with relationships
|
|
554
587
|
const {
|
|
@@ -814,7 +847,9 @@ export function WorkloadView({
|
|
|
814
847
|
const isCronJob = apiKind === 'cronjobs' && (!effectiveGroup || effectiveGroup === 'batch')
|
|
815
848
|
const { support: coverageSupport } = useRadarFeature('resourceIssueCoverage')
|
|
816
849
|
const useCronJobCoverage = isCronJob && coverageSupport === 'supported'
|
|
817
|
-
const
|
|
850
|
+
const issueObservation = resource ? JSON.stringify([resource.metadata?.uid, resource.metadata?.resourceVersion]) : undefined
|
|
851
|
+
const ordinaryIssues = useResourceIssues(apiKind, rest.group, namespace, name,
|
|
852
|
+
rest.active !== false && !useCronJobCoverage && !isNotFoundError(resourceError), issueObservation)
|
|
818
853
|
const cronJobIssues = useSubjectIssues(useCronJobCoverage ? { kind: 'CronJob', group: 'batch', namespace, name, uid: resource?.metadata?.uid } : null, useCronJobCoverage && Boolean(resource))
|
|
819
854
|
const liveIssues = useCronJobCoverage ? cronJobIssues.data?.issues : ordinaryIssues.data
|
|
820
855
|
const issuesPending = useCronJobCoverage ? cronJobIssues.isPending : ordinaryIssues.isPending
|
|
@@ -826,6 +861,7 @@ export function WorkloadView({
|
|
|
826
861
|
}, [schedulingEvidence, handleTabChange])
|
|
827
862
|
const { data: auditFindings } = useResourceAudit(apiKind, namespace, name, effectiveGroup)
|
|
828
863
|
const hasOperationalIssues = Boolean(liveIssues?.length)
|
|
864
|
+
const openIssueResource = issueResourceOpener(rest.onNavigateToResource)
|
|
829
865
|
const {
|
|
830
866
|
onCompareTo,
|
|
831
867
|
onCompareAcrossClusters,
|
|
@@ -1178,6 +1214,8 @@ export function WorkloadView({
|
|
|
1178
1214
|
olderHistoryError={historyFallback ? null : olderHistoryError}
|
|
1179
1215
|
historyScoped={!historyFallback}
|
|
1180
1216
|
historyIncomplete={!historyFallback && Boolean(historyQuery.data?.incomplete)}
|
|
1217
|
+
historyCoverage={historyFallback ? undefined : historyQuery.data?.historyCoverage}
|
|
1218
|
+
historyGaps={historyFallback ? undefined : historyQuery.data?.gaps}
|
|
1181
1219
|
historyError={(historyFallback ? namespaceChanges.error : historyQuery.error) as Error | null}
|
|
1182
1220
|
onRetryHistory={() => void (historyFallback ? namespaceChanges.refetch() : historyQuery.refetch())}
|
|
1183
1221
|
relatedTimelineEvents={relatedTimelineEvents}
|
|
@@ -1205,6 +1243,8 @@ export function WorkloadView({
|
|
|
1205
1243
|
renderLogsTab={(props) => (
|
|
1206
1244
|
<LogsTabContent
|
|
1207
1245
|
{...props}
|
|
1246
|
+
resourceLoading={resourceLoading}
|
|
1247
|
+
resourceError={resourceError}
|
|
1208
1248
|
group={effectiveGroup}
|
|
1209
1249
|
selectedRunKey={selectedRunKey}
|
|
1210
1250
|
onSelectRun={handleSelectedRunChange}
|
|
@@ -1212,6 +1252,7 @@ export function WorkloadView({
|
|
|
1212
1252
|
/>
|
|
1213
1253
|
)}
|
|
1214
1254
|
{...resourceDetailSlots({ kind: apiKind, group: resource?.apiVersion ? resourceGroup : effectiveGroup, namespace, name }, rest.extraTabs)}
|
|
1255
|
+
onSelectTopologyMember={batchExecution && batchKind === 'JobSet' ? handleSelectTopologyMember : undefined}
|
|
1215
1256
|
renderExpandedOverview={({ kind: k, apiKind, namespace: ns, name: n, resource: res, leadContent }) =>
|
|
1216
1257
|
supportsBatchExecution(k, apiKind, effectiveGroup, res?.apiVersion) &&
|
|
1217
1258
|
res ? (
|
|
@@ -1298,7 +1339,12 @@ export function WorkloadView({
|
|
|
1298
1339
|
return (
|
|
1299
1340
|
<>
|
|
1300
1341
|
{diagnoseInline}
|
|
1342
|
+
<ApplicationEvidenceAction kind={k} namespace={ns} name={n} group={g} uid={resource?.metadata?.uid ?? ''} />
|
|
1301
1343
|
{diagnoseHint}
|
|
1344
|
+
<RelatedFindingsSection
|
|
1345
|
+
data={resourceResponse?.relatedFindings}
|
|
1346
|
+
onResourceClick={openIssueResource}
|
|
1347
|
+
/>
|
|
1302
1348
|
<AuditOverviewSection
|
|
1303
1349
|
findings={auditFindings ?? []}
|
|
1304
1350
|
onViewAll={() => navigateRouter('/checks')}
|
|
@@ -1314,17 +1360,7 @@ export function WorkloadView({
|
|
|
1314
1360
|
renderDetailSection={schedulingEvidence?.state === 'reported' ? ({ issue }) => issue.kind === 'CronJob' && issue.reason === schedulingEvidence.reason ? <CronJobSchedulingDetails evidence={schedulingEvidence} onViewTimeline={viewSchedulingReport} /> : null : undefined}
|
|
1315
1361
|
compact={!expanded}
|
|
1316
1362
|
subjectResource={{ kind: apiKind, namespace, name, group: rest.group }}
|
|
1317
|
-
onResourceClick={
|
|
1318
|
-
rest.onNavigateToResource
|
|
1319
|
-
? (ref) =>
|
|
1320
|
-
rest.onNavigateToResource?.({
|
|
1321
|
-
kind: kindToPluralWithGroup(ref.kind, ref.group ?? ''),
|
|
1322
|
-
namespace: ref.namespace ?? '',
|
|
1323
|
-
name: ref.name,
|
|
1324
|
-
group: ref.group ?? '',
|
|
1325
|
-
})
|
|
1326
|
-
: undefined
|
|
1327
|
-
}
|
|
1363
|
+
onResourceClick={openIssueResource}
|
|
1328
1364
|
/>
|
|
1329
1365
|
</div>
|
|
1330
1366
|
)}
|
|
@@ -1365,6 +1401,16 @@ export function WorkloadView({
|
|
|
1365
1401
|
)
|
|
1366
1402
|
}
|
|
1367
1403
|
|
|
1404
|
+
/** The search params that open `memberKey` in the Overview: the member and
|
|
1405
|
+
* the tab change in one write, since two writes from the same render would
|
|
1406
|
+
* each start from the old params and the second would drop the first. */
|
|
1407
|
+
export function memberOverviewParams(current: URLSearchParams, memberKey: string): URLSearchParams {
|
|
1408
|
+
const params = new URLSearchParams(current)
|
|
1409
|
+
params.set('run', memberKey)
|
|
1410
|
+
params.delete('tab')
|
|
1411
|
+
return params
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1368
1414
|
export function collectServingRefs(relationships: Relationships | undefined): ResourceRef[] {
|
|
1369
1415
|
if (!relationships) return []
|
|
1370
1416
|
return dedupeResourceRefs([
|
|
@@ -1484,6 +1530,8 @@ function LogsTabContent({
|
|
|
1484
1530
|
selectedRunKey,
|
|
1485
1531
|
onSelectRun,
|
|
1486
1532
|
viewNamespaces,
|
|
1533
|
+
resourceLoading,
|
|
1534
|
+
resourceError,
|
|
1487
1535
|
}: {
|
|
1488
1536
|
kind: string
|
|
1489
1537
|
apiKind: string
|
|
@@ -1499,6 +1547,8 @@ function LogsTabContent({
|
|
|
1499
1547
|
selectedRunKey: string
|
|
1500
1548
|
onSelectRun: (runKey: string) => void
|
|
1501
1549
|
viewNamespaces: string[]
|
|
1550
|
+
resourceLoading: boolean
|
|
1551
|
+
resourceError: Error | null
|
|
1502
1552
|
}) {
|
|
1503
1553
|
if (SCHEDULED_LOG_KINDS.has(kind) && supportsBatchExecution(kind, apiKind, group, resource?.apiVersion)) {
|
|
1504
1554
|
return (
|
|
@@ -1518,6 +1568,22 @@ function LogsTabContent({
|
|
|
1518
1568
|
const integrationLogs = resourceLogs({ kind, group, namespace, name }, resource)
|
|
1519
1569
|
if (integrationLogs) return integrationLogs
|
|
1520
1570
|
|
|
1571
|
+
if (isKubeRayCluster(kind, group, resource?.apiVersion)) {
|
|
1572
|
+
return (
|
|
1573
|
+
<RayClusterLogsTab
|
|
1574
|
+
namespace={namespace}
|
|
1575
|
+
name={name}
|
|
1576
|
+
uid={resource?.metadata?.uid}
|
|
1577
|
+
suspendRequested={resource?.spec?.suspend === true}
|
|
1578
|
+
rootLoading={resourceLoading}
|
|
1579
|
+
rootError={resourceError}
|
|
1580
|
+
historyPods={pods}
|
|
1581
|
+
selectedPod={selectedPod}
|
|
1582
|
+
onSelectPod={onSelectPod}
|
|
1583
|
+
/>
|
|
1584
|
+
)
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1521
1587
|
// Workload kinds with stable pod selectors use the aggregated workload logs viewer
|
|
1522
1588
|
if (WORKLOAD_LOG_KINDS.has(kind) && (kind !== 'Job' || isCoreBatchJob(apiKind, group))) {
|
|
1523
1589
|
return (
|
|
@@ -1613,85 +1679,6 @@ function PodLogsTab({
|
|
|
1613
1679
|
)
|
|
1614
1680
|
}
|
|
1615
1681
|
|
|
1616
|
-
function MultiPodLogsTab({
|
|
1617
|
-
pods,
|
|
1618
|
-
namespace,
|
|
1619
|
-
selectedPod,
|
|
1620
|
-
onSelectPod,
|
|
1621
|
-
initialContainer,
|
|
1622
|
-
}: {
|
|
1623
|
-
pods: ResourceRef[]
|
|
1624
|
-
namespace: string
|
|
1625
|
-
selectedPod: string | null
|
|
1626
|
-
onSelectPod: (name: string | null) => void
|
|
1627
|
-
initialContainer?: string | null
|
|
1628
|
-
}) {
|
|
1629
|
-
useEffect(() => {
|
|
1630
|
-
if (pods.length > 0 && !selectedPod) {
|
|
1631
|
-
onSelectPod(pods[0].name)
|
|
1632
|
-
}
|
|
1633
|
-
}, [pods, selectedPod, onSelectPod])
|
|
1634
|
-
|
|
1635
|
-
const podNamespace = pods.find((p) => p.name === selectedPod)?.namespace || namespace
|
|
1636
|
-
|
|
1637
|
-
// Fetch container list for the selected pod
|
|
1638
|
-
const { data: logsData } = usePodLogs(podNamespace, selectedPod || '', {
|
|
1639
|
-
tailLines: 1,
|
|
1640
|
-
})
|
|
1641
|
-
const containers = logsData?.containers || []
|
|
1642
|
-
|
|
1643
|
-
// A terminated pod (common for Job/CronJob children) has nothing to follow —
|
|
1644
|
-
// only stream live ones. Wait for the pod to load before deciding so we don't
|
|
1645
|
-
// briefly auto-stream a completed pod while its phase is still unknown.
|
|
1646
|
-
const { data: selectedPodResource } = useResource<any>('Pod', podNamespace, selectedPod || '')
|
|
1647
|
-
const phase = selectedPodResource?.status?.phase
|
|
1648
|
-
const autoStream = !!phase && phase !== 'Succeeded' && phase !== 'Failed'
|
|
1649
|
-
|
|
1650
|
-
if (pods.length === 0) {
|
|
1651
|
-
return (
|
|
1652
|
-
<div className="flex flex-col items-center justify-center h-full text-theme-text-tertiary">
|
|
1653
|
-
<Terminal className="w-12 h-12 mb-4 opacity-50" />
|
|
1654
|
-
<p>No pods available</p>
|
|
1655
|
-
</div>
|
|
1656
|
-
)
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
return (
|
|
1660
|
-
<div className="h-full flex flex-col">
|
|
1661
|
-
{pods.length > 1 && (
|
|
1662
|
-
<div className="shrink-0 border-b border-theme-border bg-theme-surface/50 px-4 py-2 flex gap-2 overflow-x-auto">
|
|
1663
|
-
{pods.map((pod) => (
|
|
1664
|
-
<button
|
|
1665
|
-
key={pod.name}
|
|
1666
|
-
onClick={() => onSelectPod(pod.name)}
|
|
1667
|
-
className={clsx(
|
|
1668
|
-
'px-3 py-1.5 text-sm rounded-lg whitespace-nowrap transition-colors',
|
|
1669
|
-
selectedPod === pod.name
|
|
1670
|
-
? 'bg-blue-500 text-theme-text-primary'
|
|
1671
|
-
: 'bg-theme-elevated text-theme-text-secondary hover:bg-theme-hover',
|
|
1672
|
-
)}
|
|
1673
|
-
>
|
|
1674
|
-
{pod.name.length > 40 ? '...' + pod.name.slice(-37) : pod.name}
|
|
1675
|
-
</button>
|
|
1676
|
-
))}
|
|
1677
|
-
</div>
|
|
1678
|
-
)}
|
|
1679
|
-
{selectedPod && containers.length > 0 && (
|
|
1680
|
-
<div className="flex-1 min-h-0">
|
|
1681
|
-
<LogsViewer
|
|
1682
|
-
key={selectedPod}
|
|
1683
|
-
namespace={podNamespace}
|
|
1684
|
-
podName={selectedPod}
|
|
1685
|
-
containers={containers}
|
|
1686
|
-
initialContainer={initialContainer || undefined}
|
|
1687
|
-
autoStream={autoStream}
|
|
1688
|
-
/>
|
|
1689
|
-
</div>
|
|
1690
|
-
)}
|
|
1691
|
-
</div>
|
|
1692
|
-
)
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
1682
|
function AuditOverviewSection({
|
|
1696
1683
|
findings,
|
|
1697
1684
|
onViewAll,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { recordUsageEvent } from '../../api/usage-data'
|
|
3
|
+
import { issueResourceOpener } from './issueResourceOpener'
|
|
4
|
+
|
|
5
|
+
vi.mock('../../api/usage-data', () => ({ recordUsageEvent: vi.fn() }))
|
|
6
|
+
|
|
7
|
+
describe('issueResourceOpener', () => {
|
|
8
|
+
afterEach(() => vi.mocked(recordUsageEvent).mockClear())
|
|
9
|
+
|
|
10
|
+
it('opens the resource and counts it once', () => {
|
|
11
|
+
const navigate = vi.fn()
|
|
12
|
+
issueResourceOpener(navigate)?.({ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'cart' })
|
|
13
|
+
expect(navigate).toHaveBeenCalledWith({ kind: 'deployments', namespace: 'shop', name: 'cart', group: 'apps' })
|
|
14
|
+
expect(vi.mocked(recordUsageEvent).mock.calls).toEqual([[{ type: 'ui', name: 'issue_action:open' }]])
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('leaves links off when the host has nowhere to navigate', () => {
|
|
18
|
+
expect(issueResourceOpener(undefined)).toBeUndefined()
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { kindToPluralWithGroup, type IssueResourceRef } from '@skyhook-io/k8s-ui'
|
|
2
|
+
import { recordUsageEvent } from '../../api/usage-data'
|
|
3
|
+
import type { NavigateToResource } from '../../utils/navigation'
|
|
4
|
+
|
|
5
|
+
// Opens a resource linked from an issue or finding, and counts it for usage data.
|
|
6
|
+
export function issueResourceOpener(navigate: NavigateToResource | undefined) {
|
|
7
|
+
if (!navigate) return undefined
|
|
8
|
+
return (ref: IssueResourceRef) => {
|
|
9
|
+
recordUsageEvent({ type: 'ui', name: 'issue_action:open' })
|
|
10
|
+
navigate({
|
|
11
|
+
kind: kindToPluralWithGroup(ref.kind, ref.group ?? ''),
|
|
12
|
+
namespace: ref.namespace ?? '',
|
|
13
|
+
name: ref.name,
|
|
14
|
+
group: ref.group ?? '',
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createContext, useContext, useState, useCallback, useEffect, useRef, ReactNode } from 'react'
|
|
2
2
|
import { useQuery, useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'
|
|
3
|
-
import { getApiBase } from '../api/config'
|
|
3
|
+
import { automaticRequestHeaders, getApiBase } from '../api/config'
|
|
4
4
|
import { readErrorBody } from '../api/httpErrors'
|
|
5
5
|
import { apiFetch, type SyncStatusSnapshot, type NodeDrainActivity } from '../api/client'
|
|
6
|
+
import { ClusterConnectedContext } from './clusterConnected'
|
|
6
7
|
|
|
7
8
|
export type ConnectionStateType = 'connected' | 'disconnected' | 'connecting'
|
|
8
9
|
|
|
@@ -13,6 +14,9 @@ export interface ConnectionState {
|
|
|
13
14
|
error?: string
|
|
14
15
|
errorType?: string // config, auth, auth-rejected, auth-plugin-stuck, rbac, network, timeout, tls, unknown
|
|
15
16
|
progressMessage?: string
|
|
17
|
+
// When this context stopped working (RFC 3339). Set by the server while
|
|
18
|
+
// disconnected; older servers never send it.
|
|
19
|
+
disconnectedAt?: string
|
|
16
20
|
// Per-kind readiness while the initial informer sync runs ('connecting'
|
|
17
21
|
// with informers started). Drives the progressive app shell — absent once
|
|
18
22
|
// connected or before informers exist.
|
|
@@ -49,6 +53,15 @@ class ConnectionRetryError extends Error {
|
|
|
49
53
|
const ConnectionContext = createContext<ConnectionContextValue | null>(null)
|
|
50
54
|
const AUTO_RETRY_INITIAL_DELAY_MS = 10000
|
|
51
55
|
const AUTO_RETRY_MAX_DELAY_MS = 60000
|
|
56
|
+
// Failed attempts in an outage before an unattended window slows to
|
|
57
|
+
// AUTO_RETRY_UNATTENDED_DELAY_MS (10s + 20s + 40s + 60s + 60s ≈ 3 minutes).
|
|
58
|
+
const AUTO_RETRY_ATTEMPTS_BEFORE_SLOWDOWN = 5
|
|
59
|
+
const AUTO_RETRY_UNATTENDED_DELAY_MS = 5 * 60_000
|
|
60
|
+
const WAKE_RETRY_DEDUPE_MS = 2000
|
|
61
|
+
// Returning to the window retries at once, but no sooner than this after the
|
|
62
|
+
// previous attempt started: someone alt-tabbing while they fix a VPN would
|
|
63
|
+
// otherwise run a full reconnect on every return.
|
|
64
|
+
const WAKE_RETRY_MIN_GAP_MS = AUTO_RETRY_INITIAL_DELAY_MS
|
|
52
65
|
const CONNECTION_STATUS_FALLBACK_POLL_MS = 30000
|
|
53
66
|
|
|
54
67
|
export function refreshQueriesAfterReconnect(queryClient: QueryClient, previousContext: string, nextContext: string) {
|
|
@@ -97,9 +110,10 @@ async function fetchConnectionStatus(sseGenerationAtStart: number): Promise<Poll
|
|
|
97
110
|
return { ...status, sseGenerationAtStart }
|
|
98
111
|
}
|
|
99
112
|
|
|
100
|
-
async function retryConnection(): Promise<ConnectionState> {
|
|
113
|
+
async function retryConnection(automatic = false): Promise<ConnectionState> {
|
|
101
114
|
const response = await apiFetch(`${getApiBase()}/connection/retry`, {
|
|
102
115
|
method: 'POST',
|
|
116
|
+
headers: automatic ? automaticRequestHeaders() : undefined,
|
|
103
117
|
})
|
|
104
118
|
if (!response.ok) {
|
|
105
119
|
const error = await readErrorBody(response) as { error?: string; errorType?: string }
|
|
@@ -125,6 +139,12 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
125
139
|
const hasConnectedRef = useRef(false)
|
|
126
140
|
const autoRetryInFlightRef = useRef(false)
|
|
127
141
|
const autoRetryDelayRef = useRef(AUTO_RETRY_INITIAL_DELAY_MS)
|
|
142
|
+
// Attempts in the current outage; only a successful connect resets it, so a
|
|
143
|
+
// manual retry's brief 'connecting' doesn't restart the count.
|
|
144
|
+
const autoRetryAttemptsRef = useRef(0)
|
|
145
|
+
const autoRetryContextRef = useRef('')
|
|
146
|
+
const lastWakeRetryAtRef = useRef(0)
|
|
147
|
+
const lastAutoRetryAtRef = useRef(0)
|
|
128
148
|
const manualRetryPendingRef = useRef(false)
|
|
129
149
|
// Fed by the status poll only (SSE frames don't carry the field, and must
|
|
130
150
|
// not clear it): while the server's recovery loop owns the episode, browser
|
|
@@ -155,6 +175,9 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
155
175
|
// Cache refresh shared by every path that lands on 'connected'.
|
|
156
176
|
const lastCacheRefreshAtRef = useRef(0)
|
|
157
177
|
const refreshCachesOnConnect = useCallback(() => {
|
|
178
|
+
// RBAC queries don't refetch an errored answer on mount; a fresh
|
|
179
|
+
// connection is when that answer may have changed.
|
|
180
|
+
queryClient.removeQueries({ queryKey: ['rbac'], predicate: query => query.state.status === 'error' })
|
|
158
181
|
const firstConnect = !hasConnectedRef.current
|
|
159
182
|
hasConnectedRef.current = true
|
|
160
183
|
// Poll and SSE can both observe the same reconnect within moments of each
|
|
@@ -258,6 +281,7 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
258
281
|
error: data.error,
|
|
259
282
|
errorType: data.errorType,
|
|
260
283
|
progressMessage: data.progressMessage,
|
|
284
|
+
disconnectedAt: data.disconnectedAt,
|
|
261
285
|
syncStatus: data.syncStatus,
|
|
262
286
|
})
|
|
263
287
|
if (becameConnected) {
|
|
@@ -267,7 +291,7 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
267
291
|
|
|
268
292
|
// Retry mutation
|
|
269
293
|
const retryMutation = useMutation({
|
|
270
|
-
mutationFn: retryConnection,
|
|
294
|
+
mutationFn: () => retryConnection(),
|
|
271
295
|
onMutate: () => {
|
|
272
296
|
manualRetryPendingRef.current = true
|
|
273
297
|
// Until SSE re-delivers state, a failed retry may report its own error
|
|
@@ -322,6 +346,13 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
322
346
|
}, [retryMutation.isPending])
|
|
323
347
|
|
|
324
348
|
useEffect(() => {
|
|
349
|
+
// An outage belongs to one context: switching to another starts its own
|
|
350
|
+
// count and backoff, and so does connecting.
|
|
351
|
+
if (connection.state === 'connected' || autoRetryContextRef.current !== connection.context) {
|
|
352
|
+
autoRetryAttemptsRef.current = 0
|
|
353
|
+
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
354
|
+
autoRetryContextRef.current = connection.context
|
|
355
|
+
}
|
|
325
356
|
if (connection.state !== 'disconnected' || !shouldAutoRetryConnection(connection.errorType)) {
|
|
326
357
|
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
327
358
|
return
|
|
@@ -329,65 +360,102 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
329
360
|
let stopped = false
|
|
330
361
|
let retryTimeout: number | undefined
|
|
331
362
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (serverOwnsRecoveryRef.current) {
|
|
342
|
-
scheduleRetry()
|
|
343
|
-
return
|
|
344
|
-
}
|
|
363
|
+
// Nobody is looking at a hidden or unfocused window (a desktop window
|
|
364
|
+
// behind others still reports visible), so after a few failures it
|
|
365
|
+
// checks only every few minutes. Coming back retries at once.
|
|
366
|
+
const nextDelay = () => {
|
|
367
|
+
const unattended = document.visibilityState === 'hidden' || !document.hasFocus()
|
|
368
|
+
return unattended && autoRetryAttemptsRef.current >= AUTO_RETRY_ATTEMPTS_BEFORE_SLOWDOWN
|
|
369
|
+
? AUTO_RETRY_UNATTENDED_DELAY_MS
|
|
370
|
+
: autoRetryDelayRef.current
|
|
371
|
+
}
|
|
345
372
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
373
|
+
const attempt = () => {
|
|
374
|
+
if (stopped) return
|
|
375
|
+
if (manualRetryPendingRef.current || autoRetryInFlightRef.current) {
|
|
376
|
+
scheduleRetry()
|
|
377
|
+
return
|
|
378
|
+
}
|
|
379
|
+
// Checked at fire time (not arm time): the poll may have learned
|
|
380
|
+
// mid-wait that the server's recovery loop owns this episode.
|
|
381
|
+
if (serverOwnsRecoveryRef.current) {
|
|
382
|
+
scheduleRetry()
|
|
383
|
+
return
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
autoRetryInFlightRef.current = true
|
|
387
|
+
autoRetryAttemptsRef.current += 1
|
|
388
|
+
lastAutoRetryAtRef.current = Date.now()
|
|
389
|
+
setIsAutoRetrying(true)
|
|
390
|
+
let recovered = false
|
|
391
|
+
retryConnection(true)
|
|
392
|
+
.then((result) => {
|
|
393
|
+
if (stopped) return
|
|
394
|
+
recovered = true
|
|
395
|
+
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
396
|
+
sseActiveRef.current = false
|
|
397
|
+
const previousContext = connectionRef.current.context
|
|
398
|
+
setConnection(result)
|
|
399
|
+
if (result.state === 'connected') {
|
|
400
|
+
hasConnectedRef.current = true
|
|
401
|
+
lastCacheRefreshAtRef.current = Date.now()
|
|
402
|
+
}
|
|
403
|
+
refreshQueriesAfterReconnect(queryClient, previousContext, result.context)
|
|
404
|
+
})
|
|
405
|
+
.catch((error: Error) => {
|
|
406
|
+
if (stopped) return
|
|
407
|
+
const retryError = error as ConnectionRetryError
|
|
408
|
+
setConnection(prev => {
|
|
409
|
+
if (sseActiveRef.current && prev.state === 'connected') return prev
|
|
410
|
+
return {
|
|
411
|
+
...prev,
|
|
412
|
+
state: 'disconnected',
|
|
413
|
+
error: error.message || prev.error,
|
|
414
|
+
errorType: retryError.errorType || prev.errorType,
|
|
415
|
+
progressMessage: undefined,
|
|
387
416
|
}
|
|
388
417
|
})
|
|
389
|
-
|
|
418
|
+
autoRetryDelayRef.current = Math.min(autoRetryDelayRef.current * 2, AUTO_RETRY_MAX_DELAY_MS)
|
|
419
|
+
// Keep the visible disconnected state until a retry succeeds.
|
|
420
|
+
})
|
|
421
|
+
.finally(() => {
|
|
422
|
+
autoRetryInFlightRef.current = false
|
|
423
|
+
setIsAutoRetrying(false)
|
|
424
|
+
// Mirror the manual-retry onSettled: re-poll so a status update
|
|
425
|
+
// dropped by the mid-retry guard isn't stranded until next tick.
|
|
426
|
+
queryClient.invalidateQueries({ queryKey: ['connection-status'] })
|
|
427
|
+
if (!stopped && !recovered) {
|
|
428
|
+
scheduleRetry()
|
|
429
|
+
}
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const scheduleRetry = () => {
|
|
434
|
+
retryTimeout = window.setTimeout(attempt, nextDelay())
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Returning to the window or regaining the network retries now, silently.
|
|
438
|
+
// focus and visibilitychange often fire together, so one wake per moment.
|
|
439
|
+
// The network coming back counts even in a background window.
|
|
440
|
+
const wake = (event: Event) => {
|
|
441
|
+
if (stopped) return
|
|
442
|
+
if (event.type !== 'online' && document.visibilityState === 'hidden') return
|
|
443
|
+
const now = Date.now()
|
|
444
|
+
if (now - lastWakeRetryAtRef.current < WAKE_RETRY_DEDUPE_MS) return
|
|
445
|
+
// The network coming back is worth an attempt right away; a focus or
|
|
446
|
+
// visibility change only once the previous attempt is old enough.
|
|
447
|
+
if (event.type !== 'online' && now - lastAutoRetryAtRef.current < WAKE_RETRY_MIN_GAP_MS) return
|
|
448
|
+
lastWakeRetryAtRef.current = now
|
|
449
|
+
if (manualRetryPendingRef.current || autoRetryInFlightRef.current || serverOwnsRecoveryRef.current) return
|
|
450
|
+
if (retryTimeout !== undefined) {
|
|
451
|
+
window.clearTimeout(retryTimeout)
|
|
452
|
+
}
|
|
453
|
+
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
454
|
+
attempt()
|
|
390
455
|
}
|
|
456
|
+
window.addEventListener('focus', wake)
|
|
457
|
+
window.addEventListener('online', wake)
|
|
458
|
+
document.addEventListener('visibilitychange', wake)
|
|
391
459
|
|
|
392
460
|
scheduleRetry()
|
|
393
461
|
|
|
@@ -396,8 +464,11 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
396
464
|
if (retryTimeout !== undefined) {
|
|
397
465
|
window.clearTimeout(retryTimeout)
|
|
398
466
|
}
|
|
467
|
+
window.removeEventListener('focus', wake)
|
|
468
|
+
window.removeEventListener('online', wake)
|
|
469
|
+
document.removeEventListener('visibilitychange', wake)
|
|
399
470
|
}
|
|
400
|
-
}, [connection.errorType, connection.state, queryClient])
|
|
471
|
+
}, [connection.context, connection.errorType, connection.state, queryClient])
|
|
401
472
|
|
|
402
473
|
const retry = useCallback(() => {
|
|
403
474
|
if (retryMutation.isPending || autoRetryInFlightRef.current) return
|
|
@@ -444,7 +515,9 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
444
515
|
|
|
445
516
|
return (
|
|
446
517
|
<ConnectionContext.Provider value={value}>
|
|
447
|
-
{
|
|
518
|
+
<ClusterConnectedContext.Provider value={connection.state === 'connected'}>
|
|
519
|
+
{children}
|
|
520
|
+
</ClusterConnectedContext.Provider>
|
|
448
521
|
</ConnectionContext.Provider>
|
|
449
522
|
)
|
|
450
523
|
}
|