@skyhook-io/radar-app 1.22.0 → 1.22.2

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.
Files changed (95) hide show
  1. package/package.json +1 -1
  2. package/src/App.tsx +98 -29
  3. package/src/RadarApp.tsx +5 -0
  4. package/src/api/client.ts +18 -1
  5. package/src/api/cnpg-history.ts +3 -3
  6. package/src/api/cnpg-storage.ts +3 -3
  7. package/src/api/diagnose.test.ts +34 -0
  8. package/src/api/diagnose.ts +17 -4
  9. package/src/api/radarFeatures.test.ts +13 -1
  10. package/src/api/radarFeatures.ts +2 -0
  11. package/src/api/resourceActions.test.ts +829 -0
  12. package/src/api/resourceActions.ts +584 -0
  13. package/src/api/resourceActions.ui.test.tsx +1882 -0
  14. package/src/api/reviewedActionMutation.ts +56 -28
  15. package/src/api/substrateHealth.ts +2 -3
  16. package/src/api/traffic.ts +13 -5
  17. package/src/api/workloadMetrics.test.ts +11 -2
  18. package/src/api/workloadMetrics.ts +2 -2
  19. package/src/api/workloadSource.test.tsx +857 -0
  20. package/src/api/workloadSource.ts +292 -0
  21. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  22. package/src/components/APIUnreachableBanner.tsx +20 -0
  23. package/src/components/ConnectionErrorView.test.tsx +63 -2
  24. package/src/components/ConnectionErrorView.tsx +88 -68
  25. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  26. package/src/components/diagnose/AnalysisStory.test.tsx +12 -0
  27. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  28. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  29. package/src/components/diagnose/DiagnoseContext.question.test.tsx +34 -1
  30. package/src/components/diagnose/DiagnoseContext.tsx +28 -3
  31. package/src/components/diagnose/DiagnoseSurface.tsx +5 -4
  32. package/src/components/diagnose/Home.test.tsx +6 -0
  33. package/src/components/diagnose/Home.tsx +13 -3
  34. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  35. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +61 -0
  36. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  37. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  38. package/src/components/diagnose/InvestigationView.followupFailure.test.tsx +122 -0
  39. package/src/components/diagnose/InvestigationView.tsx +130 -25
  40. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +1 -1
  41. package/src/components/diagnose/LocalDiagnoseAction.tsx +2 -2
  42. package/src/components/diagnose/QuestionComposer.test.tsx +16 -2
  43. package/src/components/diagnose/QuestionComposer.tsx +13 -8
  44. package/src/components/diagnose/diagnoseEvidenceTypes.ts +47 -8
  45. package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +153 -0
  46. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +9 -13
  47. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +21 -5
  48. package/src/components/diagnose/investigationEvidence/bodies/network.tsx +63 -26
  49. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  51. package/src/components/diagnose/investigationState.ts +9 -0
  52. package/src/components/diagnose/launch.ts +1 -1
  53. package/src/components/diagnose/parts.test.tsx +11 -3
  54. package/src/components/diagnose/toolCallLabel.ts +3 -0
  55. package/src/components/dock/PodDebugSession.test.tsx +66 -0
  56. package/src/components/dock/PodDebugSession.tsx +3 -1
  57. package/src/components/dock/TerminalTab.test.tsx +43 -3
  58. package/src/components/dock/TerminalTab.tsx +10 -1
  59. package/src/components/helm/HelmReleaseDrawer.tsx +1 -1
  60. package/src/components/helm/InstallWizard.tsx +1 -1
  61. package/src/components/home/ActivitySummary.tsx +3 -8
  62. package/src/components/home/ClusterHealthCard.tsx +91 -17
  63. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  64. package/src/components/home/HomeView.tsx +6 -26
  65. package/src/components/home/TopologyPreview.test.tsx +31 -30
  66. package/src/components/home/TopologyPreview.tsx +19 -28
  67. package/src/components/home/mcpToolCatalog.ts +4 -4
  68. package/src/components/resources/PodEvictAction.test.tsx +951 -0
  69. package/src/components/resources/PodEvictAction.tsx +167 -0
  70. package/src/components/resources/ResourcesView.tsx +3 -0
  71. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  72. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  73. package/src/components/resources/renderers/WorkloadRenderer.tsx +7 -1
  74. package/src/components/settings/LocalConnectionSettings.tsx +4 -4
  75. package/src/components/settings/SettingsDialog.tsx +23 -18
  76. package/src/components/settings/integrationQueries.test.ts +98 -0
  77. package/src/components/settings/integrationQueries.ts +36 -0
  78. package/src/components/traffic/TrafficView.reconnect.test.tsx +229 -0
  79. package/src/components/traffic/TrafficView.tsx +91 -35
  80. package/src/components/ui/Markdown.test.tsx +37 -0
  81. package/src/components/ui/Markdown.tsx +15 -2
  82. package/src/components/useContextSwitchFlow.test.tsx +27 -2
  83. package/src/components/useContextSwitchFlow.tsx +20 -22
  84. package/src/components/workload/WorkloadView.tsx +83 -4
  85. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  86. package/src/context/ConnectionContext.tsx +24 -5
  87. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  88. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  89. package/src/context/DiagnoseCustomization.tsx +20 -2
  90. package/src/hooks/useEventSource.test.tsx +275 -4
  91. package/src/hooks/useEventSource.ts +278 -51
  92. package/src/index.ts +1 -0
  93. package/src/utils/navigation.test.ts +1 -6
  94. package/src/utils/navigation.ts +9 -44
  95. package/src/utils/network-policy-navigation.test.ts +21 -36
@@ -3,51 +3,79 @@ import { useMutation, useQueryClient, type MutationFunction, type QueryClient, t
3
3
  import { actionOutcomeLocked } from './actions'
4
4
  import { ApiError } from './client'
5
5
 
6
- interface Outcome {
6
+ export interface ReviewedActionOutcome {
7
7
  pending: boolean
8
8
  error: Error | null
9
9
  }
10
- const EMPTY: Outcome = { pending: false, error: null }
11
- const stores = new WeakMap<QueryClient, { entries: Map<string, Outcome>; listeners: Set<() => void> }>()
10
+
11
+ const EMPTY: ReviewedActionOutcome = { pending: false, error: null }
12
+
13
+ export interface ReviewedActionOutcomeStore {
14
+ get: (key: string) => ReviewedActionOutcome
15
+ set: (key: string, value: ReviewedActionOutcome) => void
16
+ subscribe: (listener: () => void) => () => void
17
+ getVersion: () => number
18
+ }
19
+
20
+ const stores = new WeakMap<QueryClient, ReviewedActionOutcomeStore>()
21
+
22
+ /**
23
+ * QueryClient-scoped outcome memory shared across reviewed-action flows so
24
+ * closing/remounting a dialog or connection-recovery cache purges cannot unlock
25
+ * a second write while a request is in flight or after an uncertain outcome.
26
+ */
27
+ export function getReviewedActionOutcomeStore(client: QueryClient): ReviewedActionOutcomeStore {
28
+ let store = stores.get(client)
29
+ if (!store) {
30
+ const entries = new Map<string, ReviewedActionOutcome>()
31
+ const listeners = new Set<() => void>()
32
+ let version = 0
33
+ store = {
34
+ get: (key) => entries.get(key) ?? EMPTY,
35
+ set: (key, value) => {
36
+ if (value.pending || value.error) entries.set(key, value)
37
+ else entries.delete(key)
38
+ version += 1
39
+ for (const listener of listeners) listener()
40
+ },
41
+ subscribe: (listener) => {
42
+ listeners.add(listener)
43
+ return () => { listeners.delete(listener) }
44
+ },
45
+ getVersion: () => version,
46
+ }
47
+ stores.set(client, store)
48
+ }
49
+ return store
50
+ }
51
+
52
+ export const DEFAULT_OUTCOME_RECOVERY_INSTRUCTION =
53
+ 'Inspect the current state in Kubernetes first, then reload this page and review the action again.'
12
54
 
13
55
  /** Result memory belongs to the host, so dismissing a dialog cannot unlock a second write. */
14
56
  export function useReviewedActionMutation<Data, Variables extends { request: { reviewedContext: string } }>(
15
57
  target: string,
16
58
  reviewedContext: string | undefined,
17
59
  options: Omit<UseMutationOptions<Data, Error, Variables>, 'mutationFn' | 'mutationKey'> & { mutationFn: MutationFunction<Data, Variables> },
18
- recoveryInstruction = 'Inspect the current state, then reload this page and review the action again.',
60
+ recoveryInstruction = DEFAULT_OUTCOME_RECOVERY_INSTRUCTION,
19
61
  ) {
20
62
  const client = useQueryClient()
21
- let store = stores.get(client)
22
- if (!store) {
23
- store = { entries: new Map(), listeners: new Set() }
24
- stores.set(client, store)
25
- }
26
- const outcomes = store
63
+ const outcomes = getReviewedActionOutcomeStore(client)
27
64
  const keyFor = (context: string | undefined) => JSON.stringify([target, context])
28
65
  const key = keyFor(reviewedContext)
29
- const subscribe = useCallback((listener: () => void) => {
30
- outcomes.listeners.add(listener)
31
- return () => { outcomes.listeners.delete(listener) }
32
- }, [outcomes])
33
- const snapshot = useCallback(() => outcomes.entries.get(key) ?? EMPTY, [outcomes, key])
66
+ const snapshot = useCallback(() => outcomes.get(key), [outcomes, key])
34
67
  // Connection recovery purges query/mutation caches. It must not forget a
35
68
  // request still in flight or a result that may already have changed the target.
36
- const retained = useSyncExternalStore(subscribe, snapshot, () => EMPTY)
37
- const publish = (key: string, value: Outcome) => {
38
- if (value.pending || value.error) outcomes.entries.set(key, value)
39
- else outcomes.entries.delete(key)
40
- for (const listener of outcomes.listeners) listener()
41
- }
69
+ const retained = useSyncExternalStore(outcomes.subscribe, snapshot, () => EMPTY)
42
70
  const mutation = useMutation<Data, Error, Variables>({
43
71
  ...options,
44
72
  mutationKey: ['reviewed-action', target, reviewedContext],
45
73
  mutationFn: async (variables, context) => {
46
74
  const boundKey = keyFor(variables.request.reviewedContext)
47
- const previous = outcomes.entries.get(boundKey)
48
- if (previous?.error) throw previous.error
49
- if (previous?.pending) throw new ApiError('A write to this target is still in progress. Wait for its result.', 409, { code: 'blocked' })
50
- publish(boundKey, { pending: true, error: null })
75
+ const previous = outcomes.get(boundKey)
76
+ if (previous.error) throw previous.error
77
+ if (previous.pending) throw new ApiError('A write to this target is still in progress. Wait for its result.', 409, { code: 'blocked' })
78
+ outcomes.set(boundKey, { pending: true, error: null })
51
79
  let retainedError: Error | null = null
52
80
  try {
53
81
  return await options.mutationFn(variables, context)
@@ -59,13 +87,13 @@ export function useReviewedActionMutation<Data, Variables extends { request: { r
59
87
  }
60
88
  throw error
61
89
  } finally {
62
- publish(boundKey, { pending: false, error: retainedError })
90
+ outcomes.set(boundKey, { pending: false, error: retainedError })
63
91
  }
64
92
  },
65
93
  })
66
94
  const acknowledgeOutcome = () => {
67
- if (outcomes.entries.get(key)?.error) {
68
- publish(key, EMPTY)
95
+ if (outcomes.get(key).error) {
96
+ outcomes.set(key, EMPTY)
69
97
  mutation.reset()
70
98
  }
71
99
  }
@@ -1,7 +1,7 @@
1
1
  import { useQuery } from '@tanstack/react-query'
2
2
  import { getApiBase } from './config'
3
3
  import type { TimeSeries } from '@skyhook-io/k8s-ui/components/charts'
4
- import { ApiError, fetchJSON, useClusterInfo, useRadarFeature, type PrometheusTimeRange } from './client'
4
+ import { fetchJSON, shouldRetryReplacedMember, useClusterInfo, useRadarFeature, type PrometheusTimeRange } from './client'
5
5
 
6
6
  export type SubstrateChartState =
7
7
  | 'ok'
@@ -127,8 +127,7 @@ export function useSubstrateHealth(target: SubstrateTarget, enabled: boolean) {
127
127
  enabled: enabled && feature.support === 'supported',
128
128
  staleTime: 30_000,
129
129
  refetchInterval: 60_000,
130
- // A changed connection answers 409 and is safe to retry once; a denial is final.
131
- retry: (failureCount, error) => failureCount < 1 && error instanceof ApiError && error.status === 409,
130
+ retry: shouldRetryReplacedMember,
132
131
  })
133
132
  return { ...query, upgrade: feature.upgrade, blockedReason: feature.blockedReason, support: feature.support }
134
133
  }
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useMemo } from 'react'
2
- import { useQuery, useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'
2
+ import { CancelledError, useQuery, useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'
3
3
  import type { TrafficSourcesResponse, TrafficFlowsResponse, TrafficRecordsResponse } from '../types'
4
4
  import { fetchJSON as fetchApiJSON, useRadarFeature } from './client'
5
5
  import { shouldRetryRadarQuery } from './radarFeatures'
@@ -48,11 +48,18 @@ export async function fetchTrafficSources(queryClient: QueryClient, fresh: boole
48
48
  export async function detectTrafficSourcesAgain(queryClient: QueryClient): Promise<TrafficSourcesResponse> {
49
49
  // A pending fetch of the same key would otherwise be returned in its place.
50
50
  await queryClient.cancelQueries({ queryKey: ['traffic-sources'], exact: true })
51
- return queryClient.fetchQuery({
51
+ let detectionSignal: AbortSignal | undefined
52
+ const sources = await queryClient.fetchQuery({
52
53
  queryKey: ['traffic-sources'],
53
- queryFn: ({ signal }) => fetchTrafficSources(queryClient, true, signal),
54
+ queryFn: ({ signal }) => {
55
+ detectionSignal = signal
56
+ return fetchTrafficSources(queryClient, true, signal)
57
+ },
54
58
  staleTime: 0,
55
59
  })
60
+ // A cancelled fetch with cached data can resolve with the previous answer.
61
+ if (detectionSignal?.aborted) throw new CancelledError()
62
+ return sources
56
63
  }
57
64
 
58
65
  export function useTrafficSources() {
@@ -268,11 +275,12 @@ export function useRefetchTrafficSources() {
268
275
  }
269
276
 
270
277
  // Get traffic connection status
271
- export function useTrafficConnectionStatus() {
278
+ export function useTrafficConnectionStatus(enabled = true) {
272
279
  return useQuery<TrafficConnectionInfo>({
273
280
  queryKey: ['traffic-connection'],
274
- queryFn: () => fetchJSON('/traffic/connection'),
281
+ queryFn: ({ signal }) => fetchJSON('/traffic/connection', signal),
275
282
  staleTime: 5000, // 5 seconds
283
+ enabled,
276
284
  })
277
285
  }
278
286
 
@@ -1,11 +1,12 @@
1
1
  import { describe, expect, it, vi } from 'vitest'
2
+ import { ApiError } from './client'
2
3
  import type { WorkloadMetrics } from './workloadMetrics'
3
4
 
4
5
  vi.mock('@tanstack/react-query', () => ({ useQuery: (options: unknown) => options }))
5
- vi.mock('./client', () => ({
6
+ vi.mock('./client', async importOriginal => ({
7
+ ...(await importOriginal<typeof import('./client')>()),
6
8
  useClusterInfo: () => ({ data: { context: 'cluster-a' } }),
7
9
  fetchJSON: vi.fn(),
8
- ApiError: class extends Error {},
9
10
  }))
10
11
  vi.mock('./config', () => ({ getApiBase: () => '/api' }))
11
12
  const { useWorkloadMetrics: workloadQueryOptions } = await import('./workloadMetrics')
@@ -15,6 +16,7 @@ describe('workload source-switch placeholders', () => {
15
16
  queryKey: unknown[]
16
17
  placeholderData: (data: WorkloadMetrics, query: { queryKey: unknown[] }) => WorkloadMetrics | undefined
17
18
  refetchInterval: (query: { state: { data: WorkloadMetrics } }) => number
19
+ retry: (failureCount: number, error: Error) => boolean
18
20
  }
19
21
  const data: WorkloadMetrics = {
20
22
  state: 'available', sources: [], pods: 1, podsTotal: 1,
@@ -31,6 +33,13 @@ describe('workload source-switch placeholders', () => {
31
33
  expect(options().refetchInterval({ state: { data } })).toBe(30_000)
32
34
  expect(options().refetchInterval({ state: { data: { ...data, comparison: { cpu: { state: 'detecting', unit: 'cores', series: [] } } } } })).toBe(3_000)
33
35
  })
36
+ it.each([409, 503])('retries an HTTP %s once on connection replacement', (status) => {
37
+ const { retry } = options()
38
+ const error = new ApiError('Metrics connection closed. Retry the request', status)
39
+ expect(retry(0, error)).toBe(true)
40
+ expect(retry(1, error)).toBe(false)
41
+ expect(retry(0, new ApiError('Forbidden', 403))).toBe(false)
42
+ })
34
43
  it.each([1, 2, 3, 4, 5, 6])('drops the previous payload when identity field %s changes', (index) => {
35
44
  const query = options()
36
45
  const key = [...query.queryKey]
@@ -1,6 +1,6 @@
1
1
  import { useQuery } from "@tanstack/react-query";
2
2
  import type { TimeSeries } from "@skyhook-io/k8s-ui/components/charts";
3
- import { ApiError, fetchJSON, useClusterInfo, type PrometheusTimeRange } from "./client";
3
+ import { fetchJSON, shouldRetryReplacedMember, useClusterInfo, type PrometheusTimeRange } from "./client";
4
4
  import { getApiBase } from "./config";
5
5
 
6
6
  export type WorkloadMetricState =
@@ -65,6 +65,6 @@ export function useWorkloadMetrics(
65
65
  enabled,
66
66
  staleTime: 30_000,
67
67
  refetchInterval: (query) => query.state.data?.state === "detecting" || Object.values(query.state.data?.comparison ?? {}).some((panel) => panel.state === "detecting") ? 3_000 : 30_000,
68
- retry: (failureCount, error) => failureCount < 1 && error instanceof ApiError && error.status === 409,
68
+ retry: shouldRetryReplacedMember,
69
69
  });
70
70
  }