@skyhook-io/radar-app 1.20.3 → 1.21.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/package.json +10 -9
- package/src/App.tsx +54 -10
- package/src/api/client.audit-gating.test.tsx +105 -5
- package/src/api/client.auditBadgesSync.test.tsx +118 -0
- package/src/api/client.capabilitiesPoll.test.ts +61 -0
- package/src/api/client.ts +129 -5
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/radarFeatures.ts +7 -0
- package/src/api/substrateHealth.ts +134 -0
- package/src/api/velero.test.ts +60 -0
- package/src/api/velero.ts +201 -0
- package/src/api/vulnerabilities.ts +255 -0
- package/src/components/NamespaceSwitcher.tsx +3 -1
- package/src/components/audit/AuditView.tsx +4 -0
- package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
- package/src/components/audit/ChecksViewTabs.tsx +11 -1
- package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
- package/src/components/audit/UpgradeReadinessView.tsx +60 -2
- package/src/components/audit/VulnerabilitiesView.tsx +907 -0
- package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
- package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
- package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
- package/src/components/cnpg/CNPGView.tsx +43 -117
- package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
- package/src/components/cnpg/host.tsx +2 -2
- package/src/components/cnpg/routes.ts +3 -1
- package/src/components/cnpg/shared.tsx +5 -53
- package/src/components/cnpg/useCNPGNavigate.ts +1 -21
- package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
- package/src/components/community.tsx +42 -0
- package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
- package/src/components/diagnose/investigationMetrics.test.ts +20 -0
- package/src/components/diagnose/investigationMetrics.ts +2 -1
- package/src/components/dock/BottomDock.tsx +1 -0
- package/src/components/dock/LogsTab.tsx +3 -0
- package/src/components/gitops/GitOpsView.tsx +1 -1
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmView.tsx +20 -16
- package/src/components/helm/OwnedResources.tsx +4 -3
- package/src/components/home/ClusterHealthCard.tsx +3 -1
- package/src/components/home/HomeAgentBlock.tsx +3 -0
- package/src/components/home/HomeView.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +19 -12
- package/src/components/home/MCPSetupDialog.tsx +4 -2
- package/src/components/home/mcpToolCatalog.ts +15 -2
- package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
- package/src/components/home/useVulnerabilitiesRow.ts +50 -0
- package/src/components/logs/LogsViewer.tsx +3 -1
- package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
- package/src/components/logs/MultiPodLogsTab.tsx +9 -5
- package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
- package/src/components/nav/PrimaryNavRail.tsx +174 -29
- package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
- package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
- package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
- package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
- package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
- package/src/components/resources/ResourcesView.tsx +12 -6
- package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
- package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
- package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
- package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +3 -2
- package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
- package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
- package/src/components/timeline/TimelineView.tsx +3 -1
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
- package/src/components/traffic/TrafficData.test.tsx +37 -0
- package/src/components/traffic/TrafficData.tsx +27 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -7
- package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
- package/src/components/traffic/TrafficGraph.test.tsx +269 -0
- package/src/components/traffic/TrafficGraph.tsx +135 -64
- package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
- package/src/components/traffic/TrafficView.tsx +46 -129
- package/src/components/traffic/trafficFilters.test.ts +172 -1
- package/src/components/traffic/trafficFilters.ts +139 -0
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +31 -2
- package/src/components/ui/UpdateNotification.tsx +34 -17
- package/src/components/ui/command-items.ts +24 -1
- package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
- package/src/components/velero/VeleroBackupNow.tsx +143 -0
- package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
- package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
- package/src/components/velero/VeleroDetailPage.tsx +148 -0
- package/src/components/velero/VeleroKindLists.test.tsx +48 -0
- package/src/components/velero/VeleroKindLists.tsx +43 -0
- package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
- package/src/components/velero/VeleroLocations.test.tsx +86 -0
- package/src/components/velero/VeleroLocations.tsx +240 -0
- package/src/components/velero/VeleroOverview.test.tsx +311 -0
- package/src/components/velero/VeleroOverview.tsx +485 -0
- package/src/components/velero/VeleroPages.test.tsx +516 -0
- package/src/components/velero/VeleroPages.tsx +1056 -0
- package/src/components/velero/VeleroRunLists.tsx +309 -0
- package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
- package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
- package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
- package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
- package/src/components/velero/VeleroSchedules.tsx +255 -0
- package/src/components/velero/VeleroView.tsx +59 -0
- package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
- package/src/components/velero/attention.test.ts +178 -0
- package/src/components/velero/attention.ts +281 -0
- package/src/components/velero/backupDelete.test.tsx +91 -0
- package/src/components/velero/backupDelete.tsx +182 -0
- package/src/components/velero/coverage.test.ts +87 -0
- package/src/components/velero/coverage.ts +150 -0
- package/src/components/velero/host.tsx +86 -0
- package/src/components/velero/routes.ts +78 -0
- package/src/components/velero/runs.tsx +121 -0
- package/src/components/velero/shared.test.ts +84 -0
- package/src/components/velero/shared.tsx +423 -0
- package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
- package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
- package/src/components/velero/velero.fixtures.ts +61 -0
- package/src/components/velero/workspaceRoute.ts +21 -0
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
- package/src/components/vulnerabilities/parts.test.ts +72 -0
- package/src/components/vulnerabilities/parts.tsx +291 -0
- package/src/components/workload/WorkloadView.tsx +64 -27
- package/src/components/workspace/DrawerTrailBack.tsx +32 -0
- package/src/components/workspace/WorkspaceFrame.tsx +71 -0
- package/src/components/workspace/coverage.ts +61 -0
- package/src/components/workspace/layout.test.tsx +29 -1
- package/src/components/workspace/layout.tsx +15 -5
- package/src/components/workspace/sidebar.ts +9 -0
- package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
- package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
- package/src/desktop/AboutDialog.test.ts +12 -0
- package/src/desktop/AboutDialog.tsx +151 -0
- package/src/desktop/WindowsTitleBar.tsx +359 -0
- package/src/desktop/titleBar.test.ts +61 -0
- package/src/desktop/titleBar.ts +45 -0
- package/src/index.css +19 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +14 -2
- package/src/integrations/resourceHosts.tsx +22 -6
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.test.ts +11 -0
- package/src/integrations/workspaceRoutes.ts +3 -1
- package/src/integrations/workspaceScreens.tsx +2 -0
- package/src/main.tsx +8 -0
- package/src/utils/desktop-zoom.test.ts +53 -0
- package/src/utils/desktop-zoom.ts +30 -0
- package/src/utils/staleAssetPrompt.test.tsx +76 -0
- package/src/utils/staleAssetPrompt.tsx +32 -0
package/src/api/client.ts
CHANGED
|
@@ -90,6 +90,7 @@ import {
|
|
|
90
90
|
} from './radarFeatures'
|
|
91
91
|
import { useRadarUpgradeHost } from '../context/RadarUpgradeHost'
|
|
92
92
|
import { apiVersionToGroup } from '../utils/navigation'
|
|
93
|
+
import { isBadgeWorthy } from '../utils/auditBadges'
|
|
93
94
|
import type { DeploymentMode } from '../types'
|
|
94
95
|
|
|
95
96
|
// Auto-refresh cadences (ms) — named constants for each polled hook's
|
|
@@ -739,11 +740,26 @@ export function useDashboard(
|
|
|
739
740
|
export function useAudit(namespaces: string[] = []) {
|
|
740
741
|
const params =
|
|
741
742
|
namespaces.length > 0 ? `?namespaces=${namespaces.join(",")}` : "";
|
|
742
|
-
//
|
|
743
|
+
// Without the connection check a mounted view keeps polling a cluster that
|
|
744
|
+
// is down.
|
|
743
745
|
const connected = useClusterConnected();
|
|
746
|
+
const queryClient = useQueryClient();
|
|
744
747
|
return useQuery<AuditResponse>({
|
|
745
748
|
queryKey: ["audit", namespaces],
|
|
746
|
-
queryFn: () =>
|
|
749
|
+
queryFn: async () => {
|
|
750
|
+
const audit = await fetchJSON<AuditResponse>(`/audit${params}`);
|
|
751
|
+
// Resource badges read the same scan through their own smaller query.
|
|
752
|
+
// A fresher full scan has them refetch rather than show a different
|
|
753
|
+
// answer: invalidating, unlike writing the projection, can't install an
|
|
754
|
+
// older scan or one from before a context switch. An in-flight badges
|
|
755
|
+
// request may predate this scan, and a first request isn't restarted by
|
|
756
|
+
// invalidation, so it is cancelled first. This runs with the fetch, not
|
|
757
|
+
// the view, so leaving the page mid-fetch doesn't skip it.
|
|
758
|
+
const badges = ["audit", namespaces, "badges"];
|
|
759
|
+
await queryClient.cancelQueries({ queryKey: badges, exact: true });
|
|
760
|
+
void queryClient.invalidateQueries({ queryKey: badges, exact: true });
|
|
761
|
+
return audit;
|
|
762
|
+
},
|
|
747
763
|
enabled: connected,
|
|
748
764
|
staleTime: 30000,
|
|
749
765
|
refetchInterval: AUDIT_REFRESH_INTERVAL_MS,
|
|
@@ -751,6 +767,39 @@ export function useAudit(namespaces: string[] = []) {
|
|
|
751
767
|
});
|
|
752
768
|
}
|
|
753
769
|
|
|
770
|
+
export type AuditBadges = Pick<AuditResponse, "findings" | "checks">;
|
|
771
|
+
|
|
772
|
+
// Keeps only what a badge view shows: findings of badge-worthy checks and
|
|
773
|
+
// those checks' catalog entries. A Radar that predates include=badges answers
|
|
774
|
+
// with the full response, which this cuts down rather than retaining.
|
|
775
|
+
export function projectAuditBadges(response: AuditBadges): AuditBadges {
|
|
776
|
+
const findings = (response.findings ?? []).filter((f) => isBadgeWorthy(f, response.checks));
|
|
777
|
+
const checks: AuditBadges["checks"] = {};
|
|
778
|
+
for (const f of findings) checks[f.checkID] = response.checks[f.checkID];
|
|
779
|
+
return { findings, checks };
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// The audit as resource badges need it (topology, resource lists): the
|
|
783
|
+
// badge-worthy findings only, a small fraction of the full scan, which repeats
|
|
784
|
+
// every finding per resource and per check for the Checks page.
|
|
785
|
+
export function useAuditBadges(
|
|
786
|
+
namespaces: string[] = [],
|
|
787
|
+
options: { enabled?: boolean } = {},
|
|
788
|
+
) {
|
|
789
|
+
const params = new URLSearchParams({ include: "badges" });
|
|
790
|
+
if (namespaces.length > 0) params.set("namespaces", namespaces.join(","));
|
|
791
|
+
const connected = useClusterConnected();
|
|
792
|
+
return useQuery<AuditBadges>({
|
|
793
|
+
queryKey: ["audit", namespaces, "badges"],
|
|
794
|
+
// The signal lets a superseded request stop downloading, not just lose.
|
|
795
|
+
queryFn: async ({ signal }) => projectAuditBadges(await fetchJSON<AuditBadges>(`/audit?${params}`, signal)),
|
|
796
|
+
enabled: connected && (options.enabled ?? true),
|
|
797
|
+
staleTime: 30000,
|
|
798
|
+
refetchInterval: AUDIT_REFRESH_INTERVAL_MS,
|
|
799
|
+
placeholderData: (prev) => prev,
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
|
|
754
803
|
export function useUpgradeReadiness(target?: string) {
|
|
755
804
|
// The server memoizes scans per caller (~60s). Ordinary and background
|
|
756
805
|
// refetches read that memo; only the explicit manual refresh passes
|
|
@@ -2074,9 +2123,10 @@ export function useApplyDesktopUpdate() {
|
|
|
2074
2123
|
}
|
|
2075
2124
|
return response.json();
|
|
2076
2125
|
},
|
|
2126
|
+
// No success toast: the update card shows the restart, in the corner a
|
|
2127
|
+
// toast would cover.
|
|
2077
2128
|
meta: {
|
|
2078
2129
|
errorMessage: "Failed to apply update",
|
|
2079
|
-
successMessage: "Update applied — restarting...",
|
|
2080
2130
|
},
|
|
2081
2131
|
});
|
|
2082
2132
|
}
|
|
@@ -2202,10 +2252,33 @@ export function useCapabilities() {
|
|
|
2202
2252
|
staleTime: 60000, // 1 minute - cached on backend too
|
|
2203
2253
|
// Re-check periodically so transient failures self-correct, but not while
|
|
2204
2254
|
// the cluster is down: reconnecting refreshes every query anyway.
|
|
2205
|
-
refetchInterval: connected ? 60000 : false,
|
|
2255
|
+
refetchInterval: (query) => connected ? capabilitiesRefetchInterval(query, 60000) : false,
|
|
2206
2256
|
});
|
|
2207
2257
|
}
|
|
2208
2258
|
|
|
2259
|
+
// A result built on a failed access check is kept by the server for only 5s;
|
|
2260
|
+
// ask again soon, backing off while the checks keep failing.
|
|
2261
|
+
export function capabilitiesRefetchInterval(
|
|
2262
|
+
query: { state: { dataUpdatedAt: number; data?: Pick<Capabilities, "checksIncomplete"> } },
|
|
2263
|
+
settled: number | false,
|
|
2264
|
+
): number | false {
|
|
2265
|
+
return backoffRefetchInterval(query, query.state.dataUpdatedAt, !!query.state.data?.checksIncomplete, settled);
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
const failedAnswerStreaks = new WeakMap<object, { answeredAt: number; count: number }>();
|
|
2269
|
+
|
|
2270
|
+
// backoffRefetchInterval polls 5s, 10s, 20s… up to 60s after consecutive
|
|
2271
|
+
// failed answers, so a struggling apiserver isn't asked more often the longer
|
|
2272
|
+
// it struggles; answeredAt identifies an answer, since React Query asks for
|
|
2273
|
+
// the interval more than once per fetch.
|
|
2274
|
+
export function backoffRefetchInterval(query: object, answeredAt: number, failing: boolean, settled: number | false): number | false {
|
|
2275
|
+
const previous = failedAnswerStreaks.get(query) ?? { answeredAt: 0, count: 0 };
|
|
2276
|
+
const streak = answeredAt === previous.answeredAt ? previous : { answeredAt, count: failing ? previous.count + 1 : 0 };
|
|
2277
|
+
failedAnswerStreaks.set(query, streak);
|
|
2278
|
+
if (!failing || streak.count === 0) return settled;
|
|
2279
|
+
return Math.min(5000 * 2 ** (streak.count - 1), 60_000);
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2209
2282
|
// ============================================================================
|
|
2210
2283
|
// In-product Cloud Connect (driver lane)
|
|
2211
2284
|
// ============================================================================
|
|
@@ -2484,12 +2557,14 @@ export function useNamespaceCapabilities(
|
|
|
2484
2557
|
globalCaps: Capabilities | undefined,
|
|
2485
2558
|
) {
|
|
2486
2559
|
const needsCheck = namespace && globalCaps;
|
|
2560
|
+
const connected = useClusterConnected();
|
|
2487
2561
|
return useQuery<Capabilities>({
|
|
2488
2562
|
queryKey: ["capabilities", namespace],
|
|
2489
2563
|
queryFn: () =>
|
|
2490
2564
|
fetchJSON(`/capabilities?namespace=${encodeURIComponent(namespace!)}`),
|
|
2491
2565
|
enabled: !!needsCheck,
|
|
2492
2566
|
staleTime: 60000,
|
|
2567
|
+
refetchInterval: (query) => connected ? capabilitiesRefetchInterval(query, false) : false,
|
|
2493
2568
|
});
|
|
2494
2569
|
}
|
|
2495
2570
|
|
|
@@ -2610,13 +2685,26 @@ export function useCanHelmAct(namespace?: string): { allowed: boolean; reason?:
|
|
|
2610
2685
|
|
|
2611
2686
|
// Namespaces
|
|
2612
2687
|
export function useNamespaces() {
|
|
2688
|
+
const connected = useClusterConnected();
|
|
2613
2689
|
return useQuery<Namespace[]>({
|
|
2614
2690
|
queryKey: ["namespaces"],
|
|
2615
2691
|
queryFn: () => fetchJSON("/namespaces"),
|
|
2616
2692
|
staleTime: 30000, // 30 seconds
|
|
2693
|
+
refetchInterval: (query) => namespacesRefetchInterval(query, connected),
|
|
2617
2694
|
});
|
|
2618
2695
|
}
|
|
2619
2696
|
|
|
2697
|
+
// A 5xx is a list Radar couldn't read (a timed-out LIST or access check), not
|
|
2698
|
+
// an empty one; ask again (backing off) until it answers. A denial won't
|
|
2699
|
+
// change by polling, and while the cluster is disconnected reconnecting
|
|
2700
|
+
// refreshes every query anyway.
|
|
2701
|
+
export function namespacesRefetchInterval(query: { state: { status: string; error: unknown; dataUpdatedAt: number; errorUpdatedAt: number } }, connected = true): number | false {
|
|
2702
|
+
if (!connected) return false;
|
|
2703
|
+
const { status, error, dataUpdatedAt, errorUpdatedAt } = query.state;
|
|
2704
|
+
const failing = status === "error" && error instanceof ApiError && error.status >= 500;
|
|
2705
|
+
return backoffRefetchInterval(query, Math.max(dataUpdatedAt, errorUpdatedAt), failing, false);
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2620
2708
|
// Topology (for manual refresh)
|
|
2621
2709
|
export function useTopology(
|
|
2622
2710
|
namespaces: string[],
|
|
@@ -4743,7 +4831,10 @@ function deleteResourceNotification(result: DeleteResourceResult): { message: st
|
|
|
4743
4831
|
return { message: "Resource deleted", type: "success" };
|
|
4744
4832
|
}
|
|
4745
4833
|
|
|
4746
|
-
export function useDeleteResource(
|
|
4834
|
+
export function useDeleteResource(options?: {
|
|
4835
|
+
/** Runs after any outcome, even when the caller unmounted meanwhile. */
|
|
4836
|
+
onSettled?: () => void;
|
|
4837
|
+
}) {
|
|
4747
4838
|
const queryClient = useQueryClient();
|
|
4748
4839
|
|
|
4749
4840
|
return useMutation({
|
|
@@ -4753,12 +4844,17 @@ export function useDeleteResource() {
|
|
|
4753
4844
|
namespace,
|
|
4754
4845
|
name,
|
|
4755
4846
|
force,
|
|
4847
|
+
uid,
|
|
4848
|
+
resourceVersion,
|
|
4756
4849
|
}: {
|
|
4757
4850
|
kind: string;
|
|
4758
4851
|
group?: string;
|
|
4759
4852
|
namespace: string;
|
|
4760
4853
|
name: string;
|
|
4761
4854
|
force?: boolean;
|
|
4855
|
+
/** Delete only the object reviewed: a Radar with resourceDeletePreconditions answers 409 when it changed. */
|
|
4856
|
+
uid?: string;
|
|
4857
|
+
resourceVersion?: string;
|
|
4762
4858
|
}) => {
|
|
4763
4859
|
const url = new URL(
|
|
4764
4860
|
apiUrl(`/resources/${resourcePathSegments(kind, namespace, name)}`),
|
|
@@ -4770,6 +4866,8 @@ export function useDeleteResource() {
|
|
|
4770
4866
|
if (force) {
|
|
4771
4867
|
url.searchParams.set("force", "true");
|
|
4772
4868
|
}
|
|
4869
|
+
if (uid) url.searchParams.set("uid", uid);
|
|
4870
|
+
if (resourceVersion) url.searchParams.set("resourceVersion", resourceVersion);
|
|
4773
4871
|
return readDeleteResult(apiFetch(url.toString(), { method: "DELETE" }));
|
|
4774
4872
|
},
|
|
4775
4873
|
meta: {
|
|
@@ -4787,6 +4885,7 @@ export function useDeleteResource() {
|
|
|
4787
4885
|
});
|
|
4788
4886
|
queryClient.invalidateQueries({ queryKey: ["topology"] });
|
|
4789
4887
|
},
|
|
4888
|
+
onSettled: () => options?.onSettled?.(),
|
|
4790
4889
|
});
|
|
4791
4890
|
}
|
|
4792
4891
|
|
|
@@ -7692,17 +7791,42 @@ export interface NamespaceScope {
|
|
|
7692
7791
|
cacheScopeNamespace?: string;
|
|
7693
7792
|
/** true when this client may rebuild the local cache for another namespace. */
|
|
7694
7793
|
namespaceRescope: boolean;
|
|
7794
|
+
/**
|
|
7795
|
+
* The server's namespace LIST failed for a reason other than RBAC (e.g. a
|
|
7796
|
+
* timeout right after a context switch), so accessibleNamespaces is only
|
|
7797
|
+
* its short fallback list. Absent from older servers.
|
|
7798
|
+
*/
|
|
7799
|
+
listFailed?: boolean;
|
|
7695
7800
|
}
|
|
7696
7801
|
|
|
7802
|
+
/**
|
|
7803
|
+
* A failed namespace list is retried rather than kept as the answer: 3s after
|
|
7804
|
+
* the first failure, doubling to 30s so a list that keeps failing doesn't add
|
|
7805
|
+
* load to an apiserver that is already struggling.
|
|
7806
|
+
*/
|
|
7807
|
+
export function namespaceScopeRefetchInterval(
|
|
7808
|
+
scope: Pick<NamespaceScope, "listFailed"> | undefined,
|
|
7809
|
+
consecutiveFailures: number,
|
|
7810
|
+
): number | false {
|
|
7811
|
+
if (!scope?.listFailed) return false;
|
|
7812
|
+
return Math.min(3000 * 2 ** Math.max(0, consecutiveFailures - 1), 30000);
|
|
7813
|
+
}
|
|
7814
|
+
|
|
7815
|
+
// Consecutive listFailed answers per apiBase, for the back-off above.
|
|
7816
|
+
const namespaceListFailures = new Map<string, number>();
|
|
7817
|
+
|
|
7697
7818
|
export function useNamespaceScope() {
|
|
7698
7819
|
return useQuery<NamespaceScope>({
|
|
7699
7820
|
queryKey: ["namespace-scope"],
|
|
7700
7821
|
queryFn: async ({ signal }) => {
|
|
7701
7822
|
const apiBase = getApiBase();
|
|
7702
7823
|
const scope = await fetchJSON<NamespaceScope>("/cluster/namespace-scope", signal);
|
|
7824
|
+
namespaceListFailures.set(apiBase, scope.listFailed ? (namespaceListFailures.get(apiBase) ?? 0) + 1 : 0);
|
|
7703
7825
|
return applyTabPick(scope, apiBase);
|
|
7704
7826
|
},
|
|
7705
7827
|
staleTime: 30000,
|
|
7828
|
+
refetchInterval: (query) =>
|
|
7829
|
+
namespaceScopeRefetchInterval(query.state.data, namespaceListFailures.get(getApiBase()) ?? 0),
|
|
7706
7830
|
});
|
|
7707
7831
|
}
|
|
7708
7832
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { namespaceScopeRefetchInterval } from './client'
|
|
3
|
+
|
|
4
|
+
describe('namespaceScopeRefetchInterval', () => {
|
|
5
|
+
it('retries a failed namespace list, backing off to 30s', () => {
|
|
6
|
+
expect([1, 2, 3, 4, 5, 6, 20].map(n => namespaceScopeRefetchInterval({ listFailed: true }, n)))
|
|
7
|
+
.toEqual([3000, 6000, 12000, 24000, 30000, 30000, 30000])
|
|
8
|
+
})
|
|
9
|
+
it('keeps a real answer, and an older Radar that never says', () => {
|
|
10
|
+
expect(namespaceScopeRefetchInterval({ listFailed: false }, 3)).toBe(false)
|
|
11
|
+
expect(namespaceScopeRefetchInterval({}, 0)).toBe(false)
|
|
12
|
+
expect(namespaceScopeRefetchInterval(undefined, 0)).toBe(false)
|
|
13
|
+
})
|
|
14
|
+
})
|
package/src/api/radarFeatures.ts
CHANGED
|
@@ -46,8 +46,14 @@ export const RADAR_FEATURES = {
|
|
|
46
46
|
applications: { label: 'Applications', minimumVersion: 'v1.7.7' },
|
|
47
47
|
workloadHistory: { label: 'Workload history', flag: 'workloadHistory', flagShippedWithEndpoint: true },
|
|
48
48
|
deploymentPause: { label: 'Deployment rollout pause and resume', flag: 'deploymentPause', flagShippedWithEndpoint: true },
|
|
49
|
+
substrateHealthMetrics: { label: 'Agent Substrate charts', flag: 'substrateHealthMetrics', flagShippedWithEndpoint: true, requireAffirmativeSupport: true },
|
|
49
50
|
cnpgWorkspace: { label: 'CloudNativePG views', flag: 'cnpgWorkspace', flagShippedWithEndpoint: true },
|
|
50
51
|
cnpgProtectionSetup: { label: 'CloudNativePG backup setup', flag: 'cnpgProtectionSetup', flagShippedWithEndpoint: true },
|
|
52
|
+
veleroWorkspace: { label: 'Velero views', flag: 'veleroWorkspace', flagShippedWithEndpoint: true },
|
|
53
|
+
veleroBackupNow: { label: 'Back up now', flag: 'veleroBackupNow', flagShippedWithEndpoint: true },
|
|
54
|
+
veleroRuns: { label: 'Velero backup and restore lists', flag: 'veleroRuns', flagShippedWithEndpoint: true },
|
|
55
|
+
veleroDeleteBackup: { label: 'Delete a Velero backup', flag: 'veleroDeleteBackup', flagShippedWithEndpoint: true },
|
|
56
|
+
resourceDeletePreconditions: { label: 'Delete only the object you reviewed', flag: 'resourceDeletePreconditions', flagShippedWithEndpoint: true },
|
|
51
57
|
gitopsWriteEvidence: { label: 'GitOps revert warnings', flag: 'gitopsWriteEvidence', flagShippedWithEndpoint: true },
|
|
52
58
|
serviceEndpointSlices: { label: 'Service EndpointSlice inventories', flag: 'serviceEndpointSlices', flagShippedWithEndpoint: true },
|
|
53
59
|
trafficRecords: { label: 'Flow records for a graph selection', flag: 'trafficRecords', flagShippedWithEndpoint: true },
|
|
@@ -72,6 +78,7 @@ export const RADAR_FEATURES = {
|
|
|
72
78
|
helmInventory: { label: 'Helm releases without Secret access', flag: 'helmInventory', flagShippedWithEndpoint: true },
|
|
73
79
|
agentSigninCheck: { label: 'Agent sign-in checks', flag: 'agentSigninCheck', flagShippedWithEndpoint: true },
|
|
74
80
|
podFileUpload: { label: 'Pod file uploads', flag: 'podFileUpload', flagShippedWithEndpoint: true },
|
|
81
|
+
vulnerabilities: { label: 'Vulnerability views', flag: 'vulnerabilities', flagShippedWithEndpoint: true },
|
|
75
82
|
} as const satisfies Record<string, RadarFeatureSpec>
|
|
76
83
|
|
|
77
84
|
export type RadarFeature = keyof typeof RADAR_FEATURES
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query'
|
|
2
|
+
import { getApiBase } from './config'
|
|
3
|
+
import type { TimeSeries } from '@skyhook-io/k8s-ui/components/charts'
|
|
4
|
+
import { ApiError, fetchJSON, useClusterInfo, useRadarFeature, type PrometheusTimeRange } from './client'
|
|
5
|
+
|
|
6
|
+
export type SubstrateChartState =
|
|
7
|
+
| 'ok'
|
|
8
|
+
| 'empty'
|
|
9
|
+
| 'noSeries'
|
|
10
|
+
| 'notAttributable'
|
|
11
|
+
| 'duplicateSources'
|
|
12
|
+
| 'ambiguous'
|
|
13
|
+
| 'mismatch'
|
|
14
|
+
| 'error'
|
|
15
|
+
|
|
16
|
+
export interface SubstrateChart {
|
|
17
|
+
id: string
|
|
18
|
+
title: string
|
|
19
|
+
unit: string
|
|
20
|
+
population: string
|
|
21
|
+
/** The metrics read, in the spelling Prometheus holds them. */
|
|
22
|
+
source: string
|
|
23
|
+
state: SubstrateChartState
|
|
24
|
+
/** Why there are no series; on an ok chart, which named series has no data. */
|
|
25
|
+
reason?: string
|
|
26
|
+
isolation: { mode: 'configured' | 'verified' | 'unverified' | ''; labels?: Record<string, string>; note: string }
|
|
27
|
+
/** One display label per series, under `series`. A null value is a gap. */
|
|
28
|
+
series: TimeSeries[]
|
|
29
|
+
/** Series beyond the first 12. */
|
|
30
|
+
omitted?: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type SubstrateVerdictState =
|
|
34
|
+
/** Substrate's own capacity alert condition has held for five minutes. */
|
|
35
|
+
| 'workerShortfall'
|
|
36
|
+
/** No API replica sees a free actor slot. */
|
|
37
|
+
| 'noFreeActorSlots'
|
|
38
|
+
/** Some worker has a free actor slot. Slots are counted by actors alone: an
|
|
39
|
+
* actor can still fail to place for lack of CPU or memory. */
|
|
40
|
+
| 'freeActorSlots'
|
|
41
|
+
/** No schedulable worker of a known class. */
|
|
42
|
+
| 'noSchedulableWorkers'
|
|
43
|
+
/** A node: some actor's snapshot upload is overdue. */
|
|
44
|
+
| 'uploadsOverdue'
|
|
45
|
+
/** A node: no overdue upload is counted. Snapshots with no storage
|
|
46
|
+
* destination are not counted, so this does not prove all are saved. */
|
|
47
|
+
| 'noUploadsOverdue'
|
|
48
|
+
| 'unknown'
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* One number behind a verdict. resumeP95, resumeFailures and crashes summarize
|
|
52
|
+
* the requested range; workersWithFreeActorSlots, overdueUploads and oldestUnsaved read now.
|
|
53
|
+
*/
|
|
54
|
+
export interface SubstrateFact {
|
|
55
|
+
id: string
|
|
56
|
+
/** Display text. */
|
|
57
|
+
label: string
|
|
58
|
+
unit: 'workers' | 'seconds' | 'percent' | 'count'
|
|
59
|
+
/** ok has a value; empty means the series exist and recorded nothing here; unavailable says why. */
|
|
60
|
+
state: 'ok' | 'empty' | 'unavailable'
|
|
61
|
+
value?: number
|
|
62
|
+
/**
|
|
63
|
+
* Only on an ok fact that compares: workersWithFreeActorSlots, out of the
|
|
64
|
+
* schedulable workers of known classes; schedulableWorkers (present only on a
|
|
65
|
+
* workerShortfall verdict, listed first), out of the fewest desired over five
|
|
66
|
+
* minutes.
|
|
67
|
+
*/
|
|
68
|
+
of?: number
|
|
69
|
+
reason?: string
|
|
70
|
+
/** Only on an ok overdueUploads: Substrate's band keys with actors in them, worst first. */
|
|
71
|
+
parts?: { label: string; value: number }[]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SubstrateVerdict {
|
|
75
|
+
state: SubstrateVerdictState
|
|
76
|
+
/** Why the state is unknown, or what qualifies a known one (a shortfall that could not be judged). */
|
|
77
|
+
reason?: string
|
|
78
|
+
facts: SubstrateFact[]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface SubstrateHealth {
|
|
82
|
+
/**
|
|
83
|
+
* available: some chart has data or a refusal of its own; read each chart's
|
|
84
|
+
* state. notFound: no chart has series for this subject in the range, which
|
|
85
|
+
* does not say whether Substrate or the object exists. notOnNode,
|
|
86
|
+
* notAttributable: a node's atelet series. error: every chart failed.
|
|
87
|
+
*/
|
|
88
|
+
status: 'available' | 'notFound' | 'notOnNode' | 'notAttributable' | 'error'
|
|
89
|
+
reason?: string
|
|
90
|
+
/** The range served: 1h when the request named an unknown one. */
|
|
91
|
+
range: string
|
|
92
|
+
/** Unix seconds. */
|
|
93
|
+
start: number
|
|
94
|
+
end: number
|
|
95
|
+
stepSeconds: number
|
|
96
|
+
charts: SubstrateChart[]
|
|
97
|
+
/** Set when status is available. */
|
|
98
|
+
verdict?: SubstrateVerdict
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type SubstrateTarget =
|
|
102
|
+
| { kind: 'workerpool'; namespace: string; name: string }
|
|
103
|
+
| { kind: 'node'; name: string }
|
|
104
|
+
|
|
105
|
+
function substratePath(target: SubstrateTarget, range: PrometheusTimeRange): string {
|
|
106
|
+
const query = new URLSearchParams({ range })
|
|
107
|
+
return target.kind === 'workerpool'
|
|
108
|
+
? `/prometheus/substrate/workerpools/${encodeURIComponent(target.namespace)}/${encodeURIComponent(target.name)}?${query}`
|
|
109
|
+
: `/prometheus/substrate/nodes/${encodeURIComponent(target.name)}?${query}`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Curated Agent Substrate charts for one WorkerPool or Node. Requests only a
|
|
114
|
+
* Radar that advertises the endpoints: Radar Hub can embed this UI against an
|
|
115
|
+
* older Radar, which would answer with a 404.
|
|
116
|
+
*/
|
|
117
|
+
/** The verdict and the charts read one response, so they share one range. */
|
|
118
|
+
export const SUBSTRATE_RANGE: PrometheusTimeRange = '1h'
|
|
119
|
+
|
|
120
|
+
export function useSubstrateHealth(target: SubstrateTarget, enabled: boolean) {
|
|
121
|
+
const range = SUBSTRATE_RANGE
|
|
122
|
+
const { data: cluster } = useClusterInfo()
|
|
123
|
+
const feature = useRadarFeature('substrateHealthMetrics')
|
|
124
|
+
const query = useQuery<SubstrateHealth>({
|
|
125
|
+
queryKey: ['substrate-health', getApiBase(), cluster?.context, target.kind, target.kind === 'workerpool' ? target.namespace : '', target.name, range],
|
|
126
|
+
queryFn: ({ signal }) => feature.guard(() => fetchJSON<SubstrateHealth>(substratePath(target, range), signal)),
|
|
127
|
+
enabled: enabled && feature.support === 'supported',
|
|
128
|
+
staleTime: 30_000,
|
|
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,
|
|
132
|
+
})
|
|
133
|
+
return { ...query, upgrade: feature.upgrade, blockedReason: feature.blockedReason, support: feature.support }
|
|
134
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { beforeEach, expect, it, vi } from 'vitest'
|
|
2
|
+
import { useMutation, useQuery } from '@tanstack/react-query'
|
|
3
|
+
import { fetchJSON } from './client'
|
|
4
|
+
import { useVeleroBackupDeletion, useVeleroDeleteBackup, useVeleroRuns } from './velero'
|
|
5
|
+
|
|
6
|
+
vi.mock('@tanstack/react-query', () => ({ useQuery: vi.fn(), useMutation: vi.fn(), useQueryClient: vi.fn() }))
|
|
7
|
+
vi.mock('./client', () => ({
|
|
8
|
+
apiFetch: vi.fn(),
|
|
9
|
+
fetchJSON: vi.fn(),
|
|
10
|
+
useRadarFeature: () => ({ gatedKey: [], guard: (request: () => Promise<unknown>) => request() }),
|
|
11
|
+
}))
|
|
12
|
+
beforeEach(() => vi.clearAllMocks())
|
|
13
|
+
|
|
14
|
+
function lastQuery() { return vi.mocked(useQuery).mock.calls.at(-1)![0] }
|
|
15
|
+
|
|
16
|
+
it('puts run filters in the URL and key and never reuses another filter’s answer', async () => {
|
|
17
|
+
useVeleroRuns('backups', 'velero', { schedule: 'nightly' })
|
|
18
|
+
const first = lastQuery()
|
|
19
|
+
useVeleroRuns('backups', 'velero', { schedule: 'weekly' })
|
|
20
|
+
const second = lastQuery()
|
|
21
|
+
const request = second.queryFn as (context: { signal: AbortSignal }) => Promise<unknown>
|
|
22
|
+
await request({ signal: new AbortController().signal })
|
|
23
|
+
expect(fetchJSON).toHaveBeenCalledWith('/velero/runs/backups?namespace=velero&schedule=weekly', expect.any(AbortSignal))
|
|
24
|
+
expect(second.queryKey).not.toEqual(first.queryKey)
|
|
25
|
+
const previous = { runs: [] }
|
|
26
|
+
const placeholder = second.placeholderData as (prev: unknown, query: { queryKey: readonly unknown[] }) => unknown
|
|
27
|
+
expect(placeholder(previous, { queryKey: first.queryKey })).toBeUndefined()
|
|
28
|
+
expect(placeholder(previous, { queryKey: second.queryKey })).toBe(previous)
|
|
29
|
+
useVeleroRuns('restores', undefined, { backup: 'source' })
|
|
30
|
+
const restore = lastQuery().queryFn as typeof request
|
|
31
|
+
await restore({ signal: new AbortController().signal })
|
|
32
|
+
expect(fetchJSON).toHaveBeenLastCalledWith('/velero/runs/restores?backup=source', expect.any(AbortSignal))
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('looks up deletion by backup UID without a request name or browser operation store', async () => {
|
|
36
|
+
useVeleroBackupDeletion('velero', 'nightly', 'uid-one')
|
|
37
|
+
const options = lastQuery()
|
|
38
|
+
const request = options.queryFn as (context: { signal: AbortSignal }) => Promise<unknown>
|
|
39
|
+
await request({ signal: new AbortController().signal })
|
|
40
|
+
expect(fetchJSON).toHaveBeenCalledWith('/velero/backups/velero/nightly/deletion?uid=uid-one', expect.any(AbortSignal))
|
|
41
|
+
expect(options.enabled).toBe(true)
|
|
42
|
+
useVeleroDeleteBackup()
|
|
43
|
+
const mutation = vi.mocked(useMutation).mock.calls.at(-1)![0]!.mutationFn as (variables: unknown) => Promise<unknown>
|
|
44
|
+
await mutation({ namespace: 'velero', name: 'nightly', uid: 'uid-one' })
|
|
45
|
+
expect(fetchJSON).toHaveBeenLastCalledWith('/velero/backups/velero/nightly/delete', expect.objectContaining({ body: JSON.stringify({ uid: 'uid-one' }) }))
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('stops deletion polling and retries on every 4xx, including with a previous reading', () => {
|
|
49
|
+
useVeleroBackupDeletion('velero', 'nightly', 'uid-one')
|
|
50
|
+
const options = lastQuery()
|
|
51
|
+
const poll = options.refetchInterval as (query: { state: { error?: unknown; data?: { state: string } } }) => number | false
|
|
52
|
+
const retry = options.retry as (count: number, error: unknown) => boolean
|
|
53
|
+
for (const status of [400, 401, 403, 404, 408, 409, 429]) {
|
|
54
|
+
expect(poll({ state: { error: { status }, data: { state: 'waiting' } } })).toBe(false)
|
|
55
|
+
expect(retry(0, { status })).toBe(false)
|
|
56
|
+
}
|
|
57
|
+
expect(poll({ state: { error: { status: 503 }, data: { state: 'waiting' } } })).toBe(2000)
|
|
58
|
+
expect(retry(0, { status: 503 })).toBe(true)
|
|
59
|
+
for (const state of ['refused', 'failed', 'deleted', 'unknown']) expect(poll({ state: { data: { state } } })).toBe(false)
|
|
60
|
+
})
|