@skyhook-io/radar-app 1.18.2 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/src/App.tsx +31 -6
  4. package/src/api/application-evidence.ts +63 -0
  5. package/src/api/argoSync.test.ts +22 -0
  6. package/src/api/client.audit-gating.test.tsx +48 -0
  7. package/src/api/client.kueuePosition.test.ts +32 -0
  8. package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
  9. package/src/api/client.resource-identity.test.ts +3 -0
  10. package/src/api/client.resourceIssues.test.tsx +239 -0
  11. package/src/api/client.resourcePath.test.ts +3 -0
  12. package/src/api/client.ts +285 -55
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.test.ts +33 -2
  15. package/src/api/diagnose.ts +97 -3
  16. package/src/api/radarFeatures.render.test.tsx +33 -1
  17. package/src/api/radarFeatures.test.ts +47 -0
  18. package/src/api/radarFeatures.ts +41 -1
  19. package/src/api/rbac.settled.test.tsx +42 -0
  20. package/src/api/rbac.test.ts +18 -0
  21. package/src/api/rbac.ts +37 -7
  22. package/src/api/traffic.ts +9 -4
  23. package/src/api/usage-data.fixtures.ts +3 -1
  24. package/src/api/usage-data.test.tsx +134 -0
  25. package/src/api/usage-data.ts +35 -7
  26. package/src/api/workloadPodsPolling.test.ts +26 -0
  27. package/src/components/CloudConnectFlow.test.tsx +86 -0
  28. package/src/components/CloudConnectFlow.tsx +65 -27
  29. package/src/components/CloudFunnelButton.test.tsx +140 -5
  30. package/src/components/CloudFunnelButton.tsx +50 -9
  31. package/src/components/ConnectionErrorView.test.tsx +34 -0
  32. package/src/components/ConnectionErrorView.tsx +35 -11
  33. package/src/components/ContextSwitcher.tsx +5 -2
  34. package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
  35. package/src/components/SwitchAwareConnectionError.tsx +85 -0
  36. package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
  37. package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
  38. package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
  39. package/src/components/capacity/CapacityDemand.tsx +3 -2
  40. package/src/components/capacity/demandSummary.test.ts +38 -0
  41. package/src/components/capacity/shared.tsx +12 -1
  42. package/src/components/cost/ApplicationCostTab.tsx +4 -0
  43. package/src/components/cost/CostTrendChart.tsx +2 -0
  44. package/src/components/cost/WorkloadCostTab.tsx +4 -0
  45. package/src/components/cost/source.test.ts +5 -0
  46. package/src/components/cost/source.ts +11 -0
  47. package/src/components/diagnose/AIMarkdown.tsx +4 -1
  48. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  49. package/src/components/diagnose/AgentControls.tsx +53 -6
  50. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  51. package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
  52. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  53. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  54. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  55. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  56. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  57. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  58. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  59. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  60. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  61. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  62. package/src/components/diagnose/DiagnoseContext.tsx +272 -10
  63. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  64. package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
  65. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  66. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  67. package/src/components/diagnose/Home.test.tsx +208 -5
  68. package/src/components/diagnose/Home.tsx +187 -36
  69. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  70. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  71. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  72. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  73. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  74. package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
  75. package/src/components/diagnose/InvestigationView.tsx +249 -54
  76. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  77. package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
  78. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  79. package/src/components/diagnose/NextStepJump.tsx +75 -0
  80. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  81. package/src/components/diagnose/QuestionComposer.tsx +495 -0
  82. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  83. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  84. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  85. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  86. package/src/components/diagnose/assessmentCopy.ts +5 -0
  87. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  88. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  89. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  90. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  91. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  92. package/src/components/diagnose/investigationCase.test.tsx +9 -1
  93. package/src/components/diagnose/investigationCase.ts +33 -1
  94. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  95. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  96. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
  97. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  98. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  99. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  100. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  101. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  102. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  103. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  104. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  105. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  106. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  107. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  108. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  109. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  110. package/src/components/diagnose/investigationEvidence/types.ts +7 -0
  111. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  112. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  113. package/src/components/diagnose/investigationFocus.ts +132 -0
  114. package/src/components/diagnose/investigationState.ts +28 -0
  115. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  116. package/src/components/diagnose/lastInvestigation.ts +58 -0
  117. package/src/components/diagnose/launch.test.ts +125 -1
  118. package/src/components/diagnose/launch.ts +57 -10
  119. package/src/components/diagnose/parts.test.tsx +20 -0
  120. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  121. package/src/components/diagnose/questionSuggestions.ts +150 -0
  122. package/src/components/diagnose/storyParts.test.tsx +13 -0
  123. package/src/components/diagnose/target.test.ts +143 -2
  124. package/src/components/diagnose/target.ts +109 -7
  125. package/src/components/diagnose/testdata/story-runs.json +474 -0
  126. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  127. package/src/components/diagnose/verdictText.test.tsx +87 -0
  128. package/src/components/diagnose/verdictText.ts +68 -0
  129. package/src/components/execution/BatchExecutionView.tsx +24 -11
  130. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  131. package/src/components/execution/JobSetAdmission.tsx +18 -3
  132. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  133. package/src/components/execution/runState.test.ts +14 -0
  134. package/src/components/execution/runState.ts +8 -0
  135. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  136. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  137. package/src/components/gitops/GitOpsView.tsx +86 -17
  138. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  139. package/src/components/gitops/destination-toast.test.ts +1 -1
  140. package/src/components/gitops/destination-toast.ts +2 -2
  141. package/src/components/home/ClusterHealthCard.tsx +13 -39
  142. package/src/components/home/HomeAgentBlock.test.tsx +141 -0
  143. package/src/components/home/HomeAgentBlock.tsx +103 -0
  144. package/src/components/home/HomeDiagramCard.tsx +47 -0
  145. package/src/components/home/HomeView.tsx +86 -47
  146. package/src/components/home/MCPSetupDialog.test.tsx +95 -5
  147. package/src/components/home/MCPSetupDialog.tsx +30 -5
  148. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  149. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  150. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  151. package/src/components/home/RadarVersionLine.tsx +3 -28
  152. package/src/components/home/TopologyPreview.test.tsx +73 -0
  153. package/src/components/home/TopologyPreview.tsx +120 -233
  154. package/src/components/home/TrafficSummary.test.tsx +63 -0
  155. package/src/components/home/TrafficSummary.tsx +135 -138
  156. package/src/components/home/mcpToolCatalog.ts +23 -10
  157. package/src/components/issues/IssuesPane.test.ts +11 -0
  158. package/src/components/issues/IssuesPane.tsx +15 -5
  159. package/src/components/issues/uncheckedSources.test.ts +20 -1
  160. package/src/components/issues/uncheckedSources.ts +18 -0
  161. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  162. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  163. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  164. package/src/components/kueue/useRelatedReads.ts +205 -0
  165. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  166. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  167. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  168. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  169. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  170. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  171. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  172. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  173. package/src/components/logs/rayClusterPods.ts +32 -0
  174. package/src/components/outageSince.test.ts +21 -0
  175. package/src/components/outageSince.ts +10 -0
  176. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  177. package/src/components/resource/PrometheusCharts.tsx +3 -40
  178. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  179. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  180. package/src/components/resources/crd/host.tsx +14 -0
  181. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  182. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  183. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  184. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  185. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  186. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  187. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  188. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  189. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  190. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  191. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  192. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  193. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  194. package/src/components/traffic/TrafficView.tsx +3 -3
  195. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  196. package/src/components/ui/Omnibar.tsx +47 -3
  197. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  198. package/src/components/ui/RadarOmnibar.tsx +11 -0
  199. package/src/components/ui/command-items-crd.test.tsx +23 -0
  200. package/src/components/ui/command-items.ts +2 -1
  201. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  202. package/src/components/useContextSwitchFlow.tsx +21 -4
  203. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  204. package/src/components/whats-new/WhatsNew.tsx +5 -1
  205. package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
  206. package/src/components/whats-new/releaseNotes.ts +136 -4
  207. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  208. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  209. package/src/components/workload/WorkloadView.test.ts +10 -1
  210. package/src/components/workload/WorkloadView.tsx +85 -98
  211. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  212. package/src/components/workload/issueResourceOpener.ts +17 -0
  213. package/src/context/ConnectionContext.tsx +133 -60
  214. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  215. package/src/context/ContextSwitchContext.tsx +14 -1
  216. package/src/context/DiagnoseCustomization.tsx +3 -0
  217. package/src/context/clusterConnected.ts +10 -0
  218. package/src/contexts/CapabilitiesContext.tsx +6 -4
  219. package/src/hooks/useAgentSignin.test.tsx +190 -0
  220. package/src/hooks/useAgentSignin.ts +160 -0
  221. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
  222. package/src/hooks/useElementSize.ts +30 -0
  223. package/src/integrations/resourceHost.test.tsx +1 -0
  224. package/src/integrations/resourceHost.ts +5 -1
  225. package/src/integrations/resourceHosts.test.tsx +21 -4
  226. package/src/integrations/resourceHosts.tsx +12 -0
  227. package/src/main.tsx +5 -0
  228. package/src/utils/related-findings.ts +46 -0
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { renderToStaticMarkup } from "react-dom/server";
3
3
  import { deployment, groupsOf, project, tool } from "../evidenceFixtures";
4
+ import { projectInvestigationEvidence } from "../index";
4
5
  import { RankingBody } from "../bodies/ranking";
5
6
  import { PostureBody } from "../bodies/posture";
6
7
  import { InventoryBody, namedInventoryRows } from "../bodies/inventory";
@@ -680,3 +681,48 @@ describe("metric discovery receipt", () => {
680
681
  expect(group.latest.summary).toBe("42 metrics · last hour");
681
682
  });
682
683
  });
684
+
685
+ describe("posture cards in a run with no resource", () => {
686
+ const audit = tool("audit", "get_cluster_audit", {
687
+ findings: [
688
+ {
689
+ resource: "Deployment/other/web",
690
+ check: "noLimits",
691
+ severity: "medium",
692
+ message: "No limits.",
693
+ },
694
+ ],
695
+ totalCount: 1,
696
+ });
697
+ const none = { kind: "", group: "", namespace: "", name: "" };
698
+
699
+ it("keeps every finding as a citable card and says nothing about a resource", () => {
700
+ const projection = projectInvestigationEvidence(
701
+ [{ timeline: [audit] }],
702
+ none,
703
+ );
704
+ const [card] = groupsOf(projection.groups, "posture");
705
+ expect(card.latest.relevance).toBe("broader");
706
+ expect(
707
+ card.latest.data.type === "posture" &&
708
+ card.latest.data.findings.map((finding) => finding.name),
709
+ ).toEqual(["web"]);
710
+ expect(
711
+ groupsOf(projection.groups, "receipt").map((group) => group.latest.title),
712
+ ).not.toContain("No posture findings on this resource");
713
+ });
714
+
715
+ it("files an empty scan without naming a resource", () => {
716
+ const empty = tool("audit", "get_cluster_audit", {
717
+ findings: [],
718
+ totalCount: 0,
719
+ });
720
+ const projection = projectInvestigationEvidence(
721
+ [{ timeline: [empty] }],
722
+ none,
723
+ );
724
+ expect(
725
+ groupsOf(projection.groups, "receipt").map((group) => group.latest.title),
726
+ ).toContain("No posture findings");
727
+ });
728
+ });
@@ -251,6 +251,15 @@ export function adaptDiagnose(
251
251
  : "producer-related";
252
252
  };
253
253
  addNarrowHint(builder, source, value);
254
+ const resourceOnly = nonEmptyString(value.coverage);
255
+ if (resourceOnly) {
256
+ builder.limit(
257
+ source,
258
+ "Diagnosis coverage",
259
+ value.coverage as string,
260
+ "unknown",
261
+ );
262
+ }
254
263
 
255
264
  const relatedRaw = value.relatedIssues;
256
265
  const related = Array.isArray(relatedRaw)
@@ -330,6 +339,9 @@ export function adaptDiagnose(
330
339
  source.confirmedSuccess &&
331
340
  related.length === 0 &&
332
341
  relatedValid &&
342
+ (context?.relatedFindings === undefined ||
343
+ (Array.isArray(context.relatedFindings) &&
344
+ context.relatedFindings.length === 0)) &&
333
345
  isDiagnosableWorkloadKind(resource.kind)
334
346
  ) {
335
347
  const scope = scopeFromArgs(source);
@@ -358,6 +370,42 @@ export function adaptDiagnose(
358
370
  bundleRelevance,
359
371
  );
360
372
 
373
+ if (
374
+ apiVersionToGroup(resource.apiVersion) === "kafka.strimzi.io" &&
375
+ (resource.kind === "KafkaConnector" || resource.kind === "KafkaConnect")
376
+ ) {
377
+ const snapshot = record(value.operatorSnapshot);
378
+ if (
379
+ !snapshot ||
380
+ !["observed", "failing", "recovered", "unknown"].includes(
381
+ String(snapshot.state),
382
+ ) ||
383
+ typeof snapshot.generationCurrent !== "boolean"
384
+ ) {
385
+ invalidPayload(builder, source, "Operator snapshot");
386
+ } else if (snapshot.state === "unknown") {
387
+ builder.limit(
388
+ source,
389
+ "Operator snapshot",
390
+ `Operator status is unverifiable: ${nonEmptyString(snapshot.reason) ? snapshot.reason : "unknown"}. Missing findings do not establish application health.`,
391
+ "unknown",
392
+ );
393
+ } else if (
394
+ resource.kind === "KafkaConnector" &&
395
+ source.confirmedSuccess &&
396
+ snapshot.state === "recovered" &&
397
+ snapshot.generationCurrent === true
398
+ ) {
399
+ builder.connectorRecoveryBySource.set(source.id, {
400
+ group: "kafka.strimzi.io",
401
+ kind: "KafkaConnector",
402
+ namespace: resource.metadata.namespace,
403
+ name: resource.metadata.name,
404
+ });
405
+ }
406
+ return;
407
+ }
408
+
361
409
  if (Array.isArray(blockersRaw)) {
362
410
  for (const { blocker, pods, foldedInto } of blockerGroups) {
363
411
  if (foldedInto) continue;
@@ -643,7 +691,7 @@ export function adaptDiagnose(
643
691
  `events:diagnose:${scopeFromArgs(source)}`,
644
692
  typeof value.eventsTotalGroups !== "number" ||
645
693
  value.eventsTotalGroups <= events.length,
646
- true,
694
+ !resourceOnly,
647
695
  relatedRelevance,
648
696
  );
649
697
  } else {
@@ -660,7 +708,7 @@ export function adaptDiagnose(
660
708
  [],
661
709
  `events:diagnose:${scopeFromArgs(source)}`,
662
710
  true,
663
- true,
711
+ !resourceOnly,
664
712
  relatedRelevance,
665
713
  );
666
714
  } else if (eventsRaw !== undefined) {
@@ -762,6 +810,11 @@ export function adaptDiagnose(
762
810
  name: resource.metadata.name,
763
811
  },
764
812
  bundleRelevance,
813
+ Array.isArray(value.podNames) &&
814
+ value.podNames.every(nonEmptyString) &&
815
+ value.podNamesTruncated !== true
816
+ ? (value.podNames as string[])
817
+ : undefined,
765
818
  );
766
819
  if (value.recentChangesSaturated === true) {
767
820
  builder.limit(
@@ -837,6 +890,8 @@ function addDiagnoseMetrics(
837
890
  raw: unknown,
838
891
  subject: DiagnosisResourceRef,
839
892
  relevance: InvestigationEvidenceRelevance,
893
+ // The bundle's pod list comes from the same pod set its charts sum.
894
+ podNames: string[] | undefined,
840
895
  ): void {
841
896
  if (raw === undefined) return;
842
897
  const value = record(raw);
@@ -907,6 +962,7 @@ function addDiagnoseMetrics(
907
962
  truncated: false,
908
963
  subject,
909
964
  pods: value.pods,
965
+ ...(podNames ? { podNames } : {}),
910
966
  partial,
911
967
  };
912
968
  builder.observe(
@@ -1,10 +1,12 @@
1
1
  import { type Issue, type IssueRecentChange } from "@skyhook-io/k8s-ui";
2
+ import { type UncheckedSource } from "../../../../api/client";
2
3
  import { type DiagnosisDNSContext } from "../../diagnoseEvidenceTypes";
3
4
  import {
4
5
  ProjectionBuilder,
5
6
  addChanges,
6
7
  addIssueObservation,
7
8
  addNarrowHint,
9
+ addUncheckedIssueLimitations,
8
10
  evidenceTierForRelevance,
9
11
  invalidPayload,
10
12
  scopeFromArgs,
@@ -43,6 +45,13 @@ export function adaptIssues(
43
45
  return;
44
46
  }
45
47
  addNarrowHint(builder, source, value);
48
+ if (Array.isArray(value.unchecked_sources)) {
49
+ addUncheckedIssueLimitations(
50
+ builder,
51
+ source,
52
+ value.unchecked_sources as UncheckedSource[],
53
+ );
54
+ }
46
55
  if (
47
56
  value.total_matched > issues.length &&
48
57
  !nonEmptyString(value.narrowHint)
@@ -24,7 +24,30 @@ function keep(
24
24
  label: string,
25
25
  ): void {
26
26
  const kept = findings.filter((_, index) => relevances[index] !== "broader");
27
+ const elsewhere = findings.filter(
28
+ (_, index) => relevances[index] === "broader",
29
+ );
27
30
  const scope = scopeFromArgs(source);
31
+ // A run with no resource keeps every finding as one broader card, which the
32
+ // pane withholds unless the agent cites it; without it such a run would
33
+ // have nothing to cite. A run about a resource keeps the receipt alone, so
34
+ // a citation of "nothing here concerns this resource" lands on it.
35
+ const keepElsewhere = () => {
36
+ if (elsewhere.length === 0 || builder.target.name) return;
37
+ builder.observe(
38
+ `posture:${origin}:broader:${source.args ?? scope}`,
39
+ "posture",
40
+ source,
41
+ {
42
+ tier: evidenceTierForRelevance("context", "broader"),
43
+ relevance: "broader",
44
+ tone: "neutral",
45
+ title: label,
46
+ summary: `${elsewhere.length} finding${elsewhere.length === 1 ? "" : "s"} · ${scope}`,
47
+ data: { type: "posture", source: origin, findings: elsewhere, scope },
48
+ },
49
+ );
50
+ };
28
51
  if (missing.length > 0) {
29
52
  builder.limit(
30
53
  source,
@@ -34,7 +57,9 @@ function keep(
34
57
  );
35
58
  }
36
59
  if (kept.length === 0) {
60
+ keepElsewhere();
37
61
  if (!source.confirmedSuccess) return;
62
+ if (!builder.target.name && elsewhere.length > 0) return;
38
63
  builder.observe(
39
64
  `posture:${origin}:receipt:${source.args ?? scope}`,
40
65
  "receipt",
@@ -43,7 +68,9 @@ function keep(
43
68
  tier: evidenceTierForRelevance("checked", "producer-related"),
44
69
  relevance: "producer-related",
45
70
  tone: "neutral",
46
- title: `No ${label.toLowerCase()} on this resource`,
71
+ title: builder.target.name
72
+ ? `No ${label.toLowerCase()} on this resource`
73
+ : `No ${label.toLowerCase()}`,
47
74
  summary: scope,
48
75
  data: {
49
76
  type: "receipt",
@@ -82,6 +109,7 @@ function keep(
82
109
  data: { type: "posture", source: origin, findings: kept, scope },
83
110
  },
84
111
  );
112
+ keepElsewhere();
85
113
  }
86
114
 
87
115
  function relevanceOf(
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
2
2
  import {
3
3
  investigationEvidenceSubjectRef,
4
4
  metricsScope,
5
+ metricsSelectedPod,
5
6
  projectInvestigationEvidence,
6
7
  type InvestigationEvidenceTarget,
7
8
  } from "../index";
@@ -1640,3 +1641,42 @@ describe("query_prometheus evidence", () => {
1640
1641
  expect(groups[0].observations[1].changedFromPrevious).toBe(true);
1641
1642
  });
1642
1643
  });
1644
+
1645
+ describe("metricsSelectedPod", () => {
1646
+ const selector = (...matchers: [string, string, string][]) => ({
1647
+ metric: "kube_pod_container_status_restarts_total",
1648
+ matchers: matchers.map(([label, op, value]) => ({ label, op, value })),
1649
+ });
1650
+ it("names the one Pod every selector selects exactly", () => {
1651
+ expect(
1652
+ metricsSelectedPod([
1653
+ selector(["namespace", "=", "shop"], ["pod", "=~", "^(api-0)$"]),
1654
+ selector(["namespace", "=", "shop"], ["pod", "=", "api-0"]),
1655
+ ]),
1656
+ ).toBe("api-0");
1657
+ });
1658
+ it("names no Pod for a set, a pattern, disagreeing selectors or a selector without one", () => {
1659
+ expect(
1660
+ metricsSelectedPod([selector(["pod", "=~", "^(api-0|api-1)$"])]),
1661
+ ).toBeUndefined();
1662
+ expect(
1663
+ metricsSelectedPod([selector(["pod", "=~", "api-.*"])]),
1664
+ ).toBeUndefined();
1665
+ expect(
1666
+ metricsSelectedPod([selector(["pod", "!=", "api-0"])]),
1667
+ ).toBeUndefined();
1668
+ expect(
1669
+ metricsSelectedPod([
1670
+ selector(["pod", "=", "api-0"]),
1671
+ selector(["pod", "=", "api-1"]),
1672
+ ]),
1673
+ ).toBeUndefined();
1674
+ expect(
1675
+ metricsSelectedPod([
1676
+ selector(["pod", "=", "api-0"]),
1677
+ selector(["namespace", "=", "shop"]),
1678
+ ]),
1679
+ ).toBeUndefined();
1680
+ expect(metricsSelectedPod([])).toBeUndefined();
1681
+ });
1682
+ });
@@ -338,8 +338,10 @@ export function adaptPrometheusRules(
338
338
  // every alerting rule (a name or group filter never looked at the rest), a
339
339
  // complete list, every rule evaluated, and every returned instance placed
340
340
  // in another namespace outright. An instance this projection merely fails
341
- // to recognize is not evidence of absence.
341
+ // to recognize is not evidence of absence. A run with no resource has
342
+ // nothing for an alert to miss.
342
343
  if (
344
+ builder.target.name &&
343
345
  source.confirmedSuccess &&
344
346
  !truncated &&
345
347
  !namesTarget &&
@@ -440,6 +442,30 @@ function exactPodSet(value: string): string[] | undefined {
440
442
  ? names
441
443
  : undefined;
442
444
  }
445
+ /**
446
+ * The one Pod a query is about, when every selector names exactly that Pod
447
+ * and nothing else. A query over two Pods is about neither alone, and a
448
+ * selector without a pod matcher is about whatever else it selects.
449
+ */
450
+ export function metricsSelectedPod(
451
+ selectors: readonly InvestigationMetricsSelector[],
452
+ ): string | undefined {
453
+ let pod: string | undefined;
454
+ for (const selector of selectors) {
455
+ const named = selector.matchers.filter(
456
+ (matcher) => matcher.label === "pod",
457
+ );
458
+ if (named.length === 0) return undefined;
459
+ for (const { op, value } of named) {
460
+ const names =
461
+ op === "=" ? [value] : op === "=~" ? exactPodSet(value) : undefined;
462
+ if (names?.length !== 1 || (pod !== undefined && names[0] !== pod))
463
+ return undefined;
464
+ pod = names[0];
465
+ }
466
+ }
467
+ return pod;
468
+ }
443
469
  /**
444
470
  * Whether a workload identity label names the target: the label
445
471
  * kube-state-metrics uses for the kind (`deployment`, `job_name`, …) or a
@@ -0,0 +1,111 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { renderToStaticMarkup } from "react-dom/server";
3
+
4
+ import { MetricsBody, metricsReading } from "./metrics";
5
+ import type { EvidenceDataOf } from "../cardParts";
6
+
7
+ const QUERY =
8
+ 'sum(kube_pod_container_status_restarts_total{namespace="gl-crash-config",pod=~"^(api-7c6f9c7bb9-p9czp)$",container="api"})';
9
+
10
+ function range(query: string): EvidenceDataOf<"metrics"> {
11
+ return {
12
+ type: "metrics",
13
+ origin: "query",
14
+ query,
15
+ mode: "range",
16
+ series: [
17
+ {
18
+ labels: {},
19
+ dataPoints: [
20
+ { timestamp: 1_788_679_043, value: 1 },
21
+ { timestamp: 1_788_682_643, value: 2 },
22
+ ],
23
+ },
24
+ ],
25
+ truncated: false,
26
+ } as EvidenceDataOf<"metrics">;
27
+ }
28
+
29
+ const occurrences = (html: string, text: string) => html.split(text).length - 1;
30
+
31
+ describe("MetricsBody", () => {
32
+ it("prints a long query once, in full, instead of also cutting it short above the chart", () => {
33
+ const html = renderToStaticMarkup(<MetricsBody data={range(QUERY)} />);
34
+ expect(occurrences(html, "kube_pod_container_status_restarts_total")).toBe(
35
+ 1,
36
+ );
37
+ expect(html).not.toContain("investigation-metrics-axis-label");
38
+ });
39
+
40
+ it("keeps a short query on the line above the chart", () => {
41
+ const html = renderToStaticMarkup(<MetricsBody data={range("sum(up)")} />);
42
+ expect(html).toContain("investigation-metrics-axis-label");
43
+ expect(occurrences(html, "sum(up)")).toBe(1);
44
+ });
45
+
46
+ it("keeps a long label that is not the query, cut short", () => {
47
+ const label = `Restarts of every container in the checkout service ${"x".repeat(40)}`;
48
+ const html = renderToStaticMarkup(
49
+ <MetricsBody data={{ ...range(QUERY), label }} />,
50
+ );
51
+ expect(html).toContain("investigation-metrics-axis-label");
52
+ expect(html).toContain("Restarts of every container");
53
+ });
54
+
55
+ it("draws a short chart only when asked", () => {
56
+ expect(
57
+ renderToStaticMarkup(<MetricsBody data={range(QUERY)} size="short" />),
58
+ ).toContain("height:140px");
59
+ expect(
60
+ renderToStaticMarkup(<MetricsBody data={range(QUERY)} />),
61
+ ).not.toContain("height:140px");
62
+ });
63
+ });
64
+
65
+ describe("metricsReading", () => {
66
+ const points = (...values: (number | null)[]) =>
67
+ values.map((value, index) => ({ timestamp: 1_788_679_043 + index, value }));
68
+ const data = (
69
+ series: ReturnType<typeof points>[],
70
+ mode: "range" | "instant" = "range",
71
+ ) =>
72
+ ({
73
+ ...range("up"),
74
+ // Values read in the chart's own unit formatting.
75
+ unit: "count",
76
+ mode,
77
+ series: series.map((dataPoints) => ({ labels: {}, dataPoints })),
78
+ }) as EvidenceDataOf<"metrics">;
79
+
80
+ it("reads one series from its first to its last value", () => {
81
+ expect(metricsReading(data([points(3, 9, 12)]))).toBe("3 → 12");
82
+ });
83
+
84
+ it("adds a peak or a low that the first and last values hide", () => {
85
+ expect(metricsReading(data([points(3, 40, 12)]))).toBe("3 → 12 · peak 40");
86
+ // A dip to zero or a counter reset is the incident; it must not fold away.
87
+ expect(metricsReading(data([points(1, 0, 1)]))).toBe("1 → 1 · low 0");
88
+ expect(metricsReading(data([points(100, 0, 101)]))).toBe(
89
+ "100 → 101 · low 0",
90
+ );
91
+ });
92
+
93
+ it("says when samples are missing and reads several series by their range", () => {
94
+ expect(metricsReading(data([points(5, 7, null, null)]))).toBe(
95
+ "5 → 7 · with gaps",
96
+ );
97
+ expect(metricsReading(data([points(1, 2), points(8, 3)]))).toBe(
98
+ "2 series · 1 to 8",
99
+ );
100
+ // A series with no samples still counts as one of the series read.
101
+ expect(metricsReading(data([points(1, 2), points(null)]))).toBe(
102
+ "2 series · 1 to 2 · with gaps",
103
+ );
104
+ });
105
+
106
+ it("reads an instant value as itself and says nothing without a sample", () => {
107
+ expect(metricsReading(data([points(4)], "instant"))).toBe("4");
108
+ expect(metricsReading(data([points(null)]))).toBeUndefined();
109
+ expect(metricsReading(data([]))).toBeUndefined();
110
+ });
111
+ });
@@ -70,20 +70,62 @@ function MetricsValueTable({
70
70
  );
71
71
  }
72
72
 
73
+ /**
74
+ * One line of what a folded chart shows, so its card says something before it
75
+ * is opened: one series' first and last value with any low or peak between
76
+ * them (a dip, a counter reset), or the range across several series. Missing
77
+ * samples are said, not smoothed over. Undefined when nothing was captured.
78
+ */
79
+ export function metricsReading(
80
+ data: EvidenceDataOf<"metrics">,
81
+ ): string | undefined {
82
+ const unit = data.unit ?? "";
83
+ const format = (value: number) => formatMetricValue(value, unit);
84
+ const values = data.series.map((series) =>
85
+ finiteSamples(series).map((point) => point.value as number),
86
+ );
87
+ const all = values.flat();
88
+ if (all.length === 0) return undefined;
89
+ const low = Math.min(...all);
90
+ const peak = Math.max(...all);
91
+ const gaps = data.series.some((series) =>
92
+ series.dataPoints.some((point) => typeof point.value !== "number"),
93
+ )
94
+ ? " · with gaps"
95
+ : "";
96
+ if (data.series.length > 1) {
97
+ return `${data.series.length} series · ${format(low)} to ${format(peak)}${gaps}`;
98
+ }
99
+ const samples = values[0];
100
+ const first = samples[0];
101
+ const last = samples[samples.length - 1];
102
+ if (data.mode === "instant" || samples.length === 1) {
103
+ return `${format(last)}${gaps}`;
104
+ }
105
+ const between = [
106
+ low < first && low < last ? `low ${format(low)}` : "",
107
+ peak > first && peak > last ? `peak ${format(peak)}` : "",
108
+ ].filter(Boolean);
109
+ return [`${format(first)} → ${format(last)}`, ...between].join(" · ") + gaps;
110
+ }
111
+
112
+ /** Rendered height of a chart drawn short beside the story's prose. */
113
+ const SHORT_CHART_HEIGHT_PX = 140;
114
+
73
115
  export function MetricsBody({
74
116
  data,
75
117
  changeCoverage,
118
+ size = "full",
76
119
  }: {
77
120
  data: EvidenceDataOf<"metrics">;
78
121
  changeCoverage?: MetricsChangeCoverage;
122
+ /** "short" draws a low chart, for a placed card the story does not rest on. */
123
+ size?: "full" | "short";
79
124
  }) {
80
125
  const annotations = changeCoverage?.markers;
81
126
  const unit = data.unit ?? "";
82
127
  const axisLabel = data.label ?? data.query;
83
128
  const axisTruncated = axisLabel.length > METRICS_AXIS_LABEL_MAX_CHARS;
84
- const axisText = axisTruncated
85
- ? `${axisLabel.slice(0, METRICS_AXIS_LABEL_MAX_CHARS - 1)}…`
86
- : axisLabel;
87
129
  const domain = metricsDomain(data);
88
130
  const windowText = domain
89
131
  ? `${new Date(domain.start * 1000).toLocaleString()} to ${new Date(domain.end * 1000).toLocaleString()}`
@@ -139,19 +181,26 @@ export function MetricsBody({
139
181
  return (
140
182
  <div className="space-y-2">
141
183
  <div className="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5 text-xs">
142
- <Tooltip
143
- content={axisLabel}
144
- delay={200}
145
- position="top"
146
- disabled={!axisTruncated}
147
- >
148
- <span
149
- className="min-w-0 truncate font-mono text-theme-text-secondary"
150
- data-testid="investigation-metrics-axis-label"
184
+ {/* A query too long for this line is printed in full below the
185
+ chart; repeating its first half here would say it twice. A
186
+ distinct label keeps its line, cut short with the rest on hover. */}
187
+ {axisTruncated && axisLabel === data.query ? null : (
188
+ <Tooltip
189
+ content={axisLabel}
190
+ delay={200}
191
+ position="top"
192
+ disabled={!axisTruncated}
151
193
  >
152
- {axisText}
153
- </span>
154
- </Tooltip>
194
+ <span
195
+ className="min-w-0 truncate font-mono text-theme-text-secondary"
196
+ data-testid="investigation-metrics-axis-label"
197
+ >
198
+ {axisTruncated
199
+ ? `${axisLabel.slice(0, METRICS_AXIS_LABEL_MAX_CHARS - 1)}…`
200
+ : axisLabel}
201
+ </span>
202
+ </Tooltip>
203
+ )}
155
204
  {unit ? (
156
205
  <span className="text-theme-text-tertiary">({unit})</span>
157
206
  ) : null}
@@ -169,7 +218,9 @@ export function MetricsBody({
169
218
  unit={unit}
170
219
  annotations={annotations}
171
220
  domain={domain}
172
- layout="auto"
221
+ {...(size === "short"
222
+ ? { layout: "dashboard" as const, height: SHORT_CHART_HEIGHT_PX }
223
+ : { layout: "auto" as const })}
173
224
  />
174
225
  {charted.length > 1 ? (
175
226
  <SeriesLegend
@@ -1,3 +1,4 @@
1
+ import { resourceKey } from "@skyhook-io/k8s-ui";
1
2
  import {
2
3
  apiVersionToGroup,
3
4
  knownKindForPluralWithGroup,
@@ -307,12 +308,32 @@ export function projectInvestigationEvidence(
307
308
  source: InvestigationEvidenceSource,
308
309
  podContainer: string,
309
310
  ) => `previous-log:${source.tool}:${scopeFromArgs(source)}:${podContainer}`;
311
+ const connectorCoverageKey = (ref: {
312
+ group?: string;
313
+ kind: string;
314
+ namespace?: string;
315
+ name: string;
316
+ }) =>
317
+ `connector:${resourceKey(ref.group ?? "", ref.kind, ref.namespace ?? "", ref.name)}`;
310
318
  const retirementKey = (
311
319
  group: InvestigationEvidenceGroup,
312
320
  observation: InvestigationEvidenceObservation,
313
321
  ): string | undefined => {
314
322
  switch (group.kind) {
315
323
  case "issue":
324
+ if (
325
+ observation.data.type === "issue" &&
326
+ observation.data.issue.group === "kafka.strimzi.io" &&
327
+ observation.data.issue.kind === "KafkaConnector"
328
+ )
329
+ return connectorCoverageKey(observation.data.issue);
330
+ // A clean parent diagnosis cannot prove an associated resource recovered.
331
+ if (
332
+ observation.data.type === "issue" &&
333
+ observation.data.associatedVia
334
+ )
335
+ return undefined;
336
+ return semanticCoverageKey(group.kind);
316
337
  case "startup":
317
338
  case "crash":
318
339
  case "dns":
@@ -344,6 +365,15 @@ export function projectInvestigationEvidence(
344
365
  turns.forEach((turn, turnIndex) => {
345
366
  if (!turn.verify || turn.status !== "done") return;
346
367
  const keys = new Set<string>();
368
+ for (const source of builder.sources) {
369
+ const recovered = builder.connectorRecoveryBySource.get(source.id);
370
+ if (
371
+ source.turnIndex === turnIndex &&
372
+ source.confirmedSuccess &&
373
+ recovered
374
+ )
375
+ keys.add(connectorCoverageKey(recovered));
376
+ }
347
377
  for (const group of builder.groups) {
348
378
  for (const observation of group.observations) {
349
379
  if (
@@ -30,16 +30,29 @@ describe("storyExcerpt", () => {
30
30
  });
31
31
  });
32
32
 
33
- it("shows a chart only when the card is the cause or the symptom, and never compact", () => {
33
+ it("shows a placed chart whatever its role, folding a compact one the story does not rest on", () => {
34
34
  const metrics = observation({ type: "metrics", origin: "query" } as never);
35
35
  expect(
36
36
  storyExcerpt(metrics, [{ role: "context" }], { compact: false }),
37
- ).toBeUndefined();
37
+ ).toEqual({ kind: "chart", size: "short", folded: false });
38
+ expect(
39
+ storyExcerpt(metrics, [{ role: "rules_out" }], { compact: true }),
40
+ ).toEqual({ kind: "chart", size: "short", folded: true });
41
+ // The agent marks a card compact for the prose's flow, so a symptom
42
+ // placed compact still starts open.
38
43
  expect(
39
- storyExcerpt(metrics, [{ role: "symptom" }], { compact: false }),
40
- ).toEqual({ kind: "chart" });
44
+ storyExcerpt(metrics, [{ role: "symptom" }], { compact: true }),
45
+ ).toEqual({ kind: "chart", size: "full", folded: false });
41
46
  expect(
42
- storyExcerpt(metrics, [{ role: "cause" }], { compact: true }),
47
+ storyExcerpt(metrics, [{ role: "context" }, { role: "cause" }], {
48
+ compact: true,
49
+ }),
50
+ ).toEqual({ kind: "chart", size: "full", folded: false });
51
+ expect(
52
+ storyExcerpt(metrics, [{ role: "cause" }], {
53
+ compact: true,
54
+ preview: true,
55
+ }),
43
56
  ).toBeUndefined();
44
57
  });
45
58