@skyhook-io/radar-app 1.18.1 → 1.19.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 (136) hide show
  1. package/package.json +4 -4
  2. package/src/App.tsx +23 -9
  3. package/src/api/client.deleteResource.test.tsx +111 -0
  4. package/src/api/client.resourceAudit.test.tsx +57 -0
  5. package/src/api/client.resourcePath.test.ts +107 -0
  6. package/src/api/client.ts +136 -37
  7. package/src/api/diagnose.test.ts +33 -2
  8. package/src/api/diagnose.ts +93 -3
  9. package/src/api/radarFeatures.ts +1 -0
  10. package/src/components/capacity/CapacityDemand.tsx +6 -3
  11. package/src/components/capacity/CapacityOverview.tsx +14 -7
  12. package/src/components/capacity/CapacityPoolDetail.tsx +7 -5
  13. package/src/components/capacity/ClusterSchedulingCard.tsx +3 -3
  14. package/src/components/capacity/shared.tsx +9 -5
  15. package/src/components/cnpg/CNPGOverview.tsx +4 -1
  16. package/src/components/cnpg/actions/useCNPGWriteGuard.tsx +1 -0
  17. package/src/components/diagnose/AIMarkdown.tsx +1 -1
  18. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  19. package/src/components/diagnose/AgentControls.tsx +53 -6
  20. package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
  21. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  22. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  23. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  24. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  25. package/src/components/diagnose/ApplyDialog.test.tsx +10 -0
  26. package/src/components/diagnose/ApplyDialog.tsx +8 -1
  27. package/src/components/diagnose/AssessmentCard.tsx +99 -8
  28. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  29. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  30. package/src/components/diagnose/DiagnoseContext.tsx +205 -9
  31. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  32. package/src/components/diagnose/DiagnoseSurface.tsx +98 -21
  33. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  34. package/src/components/diagnose/Home.test.tsx +182 -5
  35. package/src/components/diagnose/Home.tsx +168 -36
  36. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  37. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  38. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  39. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +119 -2
  40. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  41. package/src/components/diagnose/InvestigationEvidenceSections.tsx +11 -6
  42. package/src/components/diagnose/InvestigationView.tsx +203 -42
  43. package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
  44. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  45. package/src/components/diagnose/QuestionComposer.tsx +487 -0
  46. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  47. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  48. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  49. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  50. package/src/components/diagnose/assessmentCopy.ts +16 -0
  51. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  52. package/src/components/diagnose/investigationCase.ts +33 -1
  53. package/src/components/diagnose/investigationEvidence/adapters/changes.ts +36 -1
  54. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  55. package/src/components/diagnose/investigationEvidence/adapters/crossplane.test.tsx +85 -0
  56. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -0
  57. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +1 -0
  58. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  59. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +42 -1
  60. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +29 -2
  61. package/src/components/diagnose/investigationEvidence/adapters/testdata/crossplane-paused-get-resource.json +28 -0
  62. package/src/components/diagnose/investigationEvidence/bodies/index.tsx +2 -0
  63. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  64. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  65. package/src/components/diagnose/investigationEvidence/bodies/workload.tsx +5 -1
  66. package/src/components/diagnose/investigationEvidence/builder.ts +3 -1
  67. package/src/components/diagnose/investigationEvidence/cardParts.tsx +7 -2
  68. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  69. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  70. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  71. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  72. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  73. package/src/components/diagnose/investigationEvidence/observations.ts +7 -3
  74. package/src/components/diagnose/investigationEvidence/projection.test.ts +57 -3
  75. package/src/components/diagnose/investigationEvidence/types.ts +2 -0
  76. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  77. package/src/components/diagnose/investigationEvidencePresentation.test.ts +36 -2
  78. package/src/components/diagnose/investigationEvidencePresentation.ts +33 -8
  79. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  80. package/src/components/diagnose/investigationFocus.ts +132 -0
  81. package/src/components/diagnose/parts.test.tsx +20 -0
  82. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  83. package/src/components/diagnose/questionSuggestions.ts +150 -0
  84. package/src/components/diagnose/storyParts.test.tsx +66 -0
  85. package/src/components/diagnose/target.test.ts +143 -2
  86. package/src/components/diagnose/target.ts +109 -7
  87. package/src/components/diagnose/testdata/story-runs.json +474 -0
  88. package/src/components/diagnose/verdictText.test.tsx +87 -0
  89. package/src/components/diagnose/verdictText.ts +68 -0
  90. package/src/components/helm/ChartBrowser.tsx +4 -4
  91. package/src/components/helm/HelmReleaseDrawer.tsx +6 -2
  92. package/src/components/helm/HelmView.tsx +34 -23
  93. package/src/components/helm/InstallWizard.tsx +6 -2
  94. package/src/components/helm/ValuesViewer.test.tsx +1 -0
  95. package/src/components/helm/ValuesViewer.tsx +4 -2
  96. package/src/components/home/ClusterHealthCard.tsx +40 -59
  97. package/src/components/home/HomeAgentBlock.test.tsx +113 -0
  98. package/src/components/home/HomeAgentBlock.tsx +94 -0
  99. package/src/components/home/HomeView.tsx +5 -6
  100. package/src/components/home/MCPSetupDialog.test.tsx +27 -2
  101. package/src/components/home/MCPSetupDialog.tsx +14 -2
  102. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  103. package/src/components/home/RadarVersionLine.tsx +3 -28
  104. package/src/components/home/mcpToolCatalog.ts +29 -2
  105. package/src/components/issues/IssuesPane.render.test.tsx +5 -5
  106. package/src/components/nav/PrimaryNavRail.tsx +34 -2
  107. package/src/components/product-hunt/ProductHuntNotice.render.test.tsx +120 -0
  108. package/src/components/product-hunt/ProductHuntNotice.test.ts +121 -0
  109. package/src/components/product-hunt/ProductHuntNotice.tsx +202 -0
  110. package/src/components/product-hunt/launchWindow.ts +78 -0
  111. package/src/components/product-hunt/useProductHuntRailEntry.test.tsx +76 -0
  112. package/src/components/product-hunt/useProductHuntRailEntry.ts +27 -0
  113. package/src/components/resources/CompositeRenderer.tsx +4 -0
  114. package/src/components/resources/ResourcesView.tsx +1 -1
  115. package/src/components/settings/LocalConnectionSettings.tsx +1 -0
  116. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  117. package/src/components/ui/Omnibar.tsx +47 -3
  118. package/src/components/ui/RadarOmnibar.test.tsx +19 -0
  119. package/src/components/ui/RadarOmnibar.tsx +12 -0
  120. package/src/components/ui/SearchSyntaxHelp.test.tsx +39 -0
  121. package/src/components/ui/SearchSyntaxHelp.tsx +23 -2
  122. package/src/components/ui/UpdateNotification.test.tsx +2 -0
  123. package/src/components/ui/UpdateNotification.tsx +32 -5
  124. package/src/components/usage-data/UsageDataPrompt.tsx +19 -1
  125. package/src/components/whats-new/WhatsNewDialog.test.tsx +3 -3
  126. package/src/components/whats-new/releaseNotes.ts +60 -1
  127. package/src/components/workload/WorkloadView.tsx +10 -4
  128. package/src/components/workspace/layout.tsx +2 -1
  129. package/src/contexts/CapabilitiesContext.tsx +1 -0
  130. package/src/hooks/useAgentSignin.test.tsx +190 -0
  131. package/src/hooks/useAgentSignin.ts +160 -0
  132. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
  133. package/src/hooks/useGitOpsWriteGuard.test.tsx +126 -2
  134. package/src/hooks/useGitOpsWriteGuard.ts +25 -3
  135. package/src/hooks/useResolvedGitOpsOwner.ts +14 -9
  136. package/src/index.css +85 -0
@@ -70,6 +70,32 @@ export function adaptChanges(
70
70
 
71
71
  const CLUSTER_SCOPED_LABEL = "Cluster-scoped admission changes";
72
72
 
73
+ // The sentences internal/meaningfulchanges/cluster_scoped.go writes when the
74
+ // window only starts before Radar's recorded history: Radar started, began
75
+ // watching a kind, or evicted older events. The producer joins them into
76
+ // `incomplete` with failures (a denied kind, an uncached scope, a failed
77
+ // recording), which stay open questions; only these exact bounds are history.
78
+ const ADMISSION_HISTORY_SENTENCES = [
79
+ /^Radar has recorded changes only since \S+; earlier changes in the window are unknown\.$/,
80
+ /^Radar has watched \w+ only since \S+; earlier changes in the window are unknown\.$/,
81
+ /^Radar has evicted older change history; earlier changes in the window are unknown\.$/,
82
+ ];
83
+
84
+ /** Splits the producer's `incomplete` text into history bounds and everything else. */
85
+ function splitAdmissionIncomplete(text: string): {
86
+ history: string;
87
+ other: string;
88
+ } {
89
+ const history: string[] = [];
90
+ const other: string[] = [];
91
+ for (const sentence of text.trim().split(/(?<=\.)\s+/)) {
92
+ if (ADMISSION_HISTORY_SENTENCES.some((pattern) => pattern.test(sentence)))
93
+ history.push(sentence);
94
+ else other.push(sentence);
95
+ }
96
+ return { history: history.join(" "), other: other.join(" ") };
97
+ }
98
+
73
99
  // Admission configuration changes that apply, or may apply, to the queried
74
100
  // namespace. Each row's summary carries why it is listed, because the
75
101
  // applicability is the point: the row itself is a cluster-scoped object.
@@ -106,7 +132,16 @@ export function addClusterScopedChanges(
106
132
  builder.limit(source, CLUSTER_SCOPED_LABEL, value.error, "error");
107
133
  }
108
134
  if (nonEmptyString(value.incomplete)) {
109
- builder.limit(source, CLUSTER_SCOPED_LABEL, value.incomplete, "unknown");
135
+ const { history, other } = splitAdmissionIncomplete(value.incomplete);
136
+ if (other) builder.limit(source, CLUSTER_SCOPED_LABEL, other, "unknown");
137
+ if (history)
138
+ builder.limit(
139
+ source,
140
+ CLUSTER_SCOPED_LABEL,
141
+ history,
142
+ "unknown",
143
+ "history",
144
+ );
110
145
  }
111
146
  const notListed = stringArray(value.not_listed) ?? [];
112
147
  if (notListed.length > 0 || value.truncated === true) {
@@ -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
+ });
@@ -0,0 +1,85 @@
1
+ import { renderToStaticMarkup } from "react-dom/server";
2
+ import { expect, it } from "vitest";
3
+ import paused from "./testdata/crossplane-paused-get-resource.json";
4
+ import { groupsOf, project, tool } from "../evidenceFixtures";
5
+ import { ResourceBody } from "../bodies/workload";
6
+ import { evidenceHasDetails } from "../bodies";
7
+ import { conditionStatusTone } from "../cardParts";
8
+
9
+ function card(payload: typeof paused) {
10
+ return groupsOf(project([tool("captured-pause", "get_resource", payload)]).groups, "resource")[0].latest;
11
+ }
12
+
13
+ it("keeps a captured get_resource pause neutral with its raw observation and visible context", () => {
14
+ const captured = card(paused);
15
+ expect(captured.tone).toBe("neutral");
16
+ expect(captured.data.type).toBe("resource");
17
+ if (captured.data.type !== "resource") throw new Error("Expected resource evidence");
18
+ expect(evidenceHasDetails(captured.data)).toBe(true);
19
+ const html = renderToStaticMarkup(<ResourceBody data={captured.data} />);
20
+ expect(html).toContain("Paused");
21
+ expect(html).toContain("controller last reported reconciliation paused");
22
+ expect(html).toContain("Synced=False");
23
+ expect(html).toContain("ReconcilePaused");
24
+ expect(html).toContain("Readiness and errors are last reported");
25
+ expect(conditionStatusTone(paused.resource.status.conditions[1], captured.data.resource)).toBe("neutral");
26
+ });
27
+
28
+ it("keeps a captured independent readiness error adverse and visible alongside pause", () => {
29
+ const payload = structuredClone(paused);
30
+ const failed = { type: "Ready", status: "False", reason: "Unavailable", message: "Fixture access denied" };
31
+ payload.resource.status.conditions[0] = failed;
32
+ payload.resourceContext.statusSummary.conditions[0] = failed;
33
+ const captured = card(payload);
34
+ expect(captured.tone).toBe("warning");
35
+ if (captured.data.type !== "resource") throw new Error("Expected resource evidence");
36
+ const html = renderToStaticMarkup(<ResourceBody data={captured.data} />);
37
+ expect(html).toContain("Ready=False");
38
+ expect(html).toContain("Fixture access denied");
39
+ expect(html).toContain("Paused");
40
+ expect(conditionStatusTone(failed, captured.data.resource)).toBe("unhealthy");
41
+ });
42
+
43
+ it("keeps a requested pause with a reconciliation error adverse", () => {
44
+ const payload = structuredClone(paused);
45
+ payload.resource.status.conditions[1].reason = "ReconcileError";
46
+ payload.resourceContext.statusSummary.conditions[1].reason = "ReconcileError";
47
+ const captured = card(payload);
48
+ expect(captured.tone).toBe("warning");
49
+ if (captured.data.type !== "resource") throw new Error("Expected resource evidence");
50
+ const html = renderToStaticMarkup(<ResourceBody data={captured.data} />);
51
+ expect(html).toContain("Pause requested");
52
+ expect(html).toContain("recorded conditions do not confirm the pause");
53
+ expect(html).toContain("ReconcileError");
54
+ });
55
+
56
+ it("keeps uncorroborated controller pause adverse without inventing a resume failure", () => {
57
+ const payload = structuredClone(paused);
58
+ payload.resource.metadata.annotations["crossplane.io/paused"] = "false";
59
+ const captured = card(payload);
60
+ expect(captured.tone).toBe("warning");
61
+ if (captured.data.type !== "resource") throw new Error("Expected resource evidence");
62
+ const html = renderToStaticMarkup(<ResourceBody data={captured.data} />);
63
+ expect(html).toContain("ReconcilePaused");
64
+ expect(html).not.toContain("controller last reported reconciliation paused");
65
+ expect(conditionStatusTone(payload.resource.status.conditions[1], captured.data.resource)).toBe("unhealthy");
66
+ });
67
+
68
+
69
+ it("keeps captured pause context before a resource has composition references", () => {
70
+ const payload = { ...paused, resource: { ...paused.resource, kind: "EarlyXR", spec: {} } };
71
+ const captured = groupsOf(project([tool("early-pause", "get_resource", payload)]).groups, "resource")[0].latest;
72
+ expect(captured.tone).toBe("neutral");
73
+ if (captured.data.type !== "resource") throw new Error("Expected resource evidence");
74
+ expect(renderToStaticMarkup(<ResourceBody data={captured.data} />)).toContain("controller last reported reconciliation paused");
75
+ });
76
+
77
+ it("keeps the captured deletion caution with recorded pause context", () => {
78
+ const payload = { ...paused, resource: { ...paused.resource, metadata: { ...paused.resource.metadata, deletionTimestamp: "2026-10-26T08:00:00Z" } } };
79
+ const captured = card(payload);
80
+ expect(captured.tone).toBe("neutral");
81
+ if (captured.data.type !== "resource") throw new Error("Expected resource evidence");
82
+ const html = renderToStaticMarkup(<ResourceBody data={captured.data} />);
83
+ expect(html).toContain("Deletion has been requested. Paused reconciliation may defer");
84
+ expect(html).toContain("controller last reported reconciliation paused");
85
+ });
@@ -762,6 +762,11 @@ export function adaptDiagnose(
762
762
  name: resource.metadata.name,
763
763
  },
764
764
  bundleRelevance,
765
+ Array.isArray(value.podNames) &&
766
+ value.podNames.every(nonEmptyString) &&
767
+ value.podNamesTruncated !== true
768
+ ? (value.podNames as string[])
769
+ : undefined,
765
770
  );
766
771
  if (value.recentChangesSaturated === true) {
767
772
  builder.limit(
@@ -837,6 +842,8 @@ function addDiagnoseMetrics(
837
842
  raw: unknown,
838
843
  subject: DiagnosisResourceRef,
839
844
  relevance: InvestigationEvidenceRelevance,
845
+ // The bundle's pod list comes from the same pod set its charts sum.
846
+ podNames: string[] | undefined,
840
847
  ): void {
841
848
  if (raw === undefined) return;
842
849
  const value = record(raw);
@@ -907,6 +914,7 @@ function addDiagnoseMetrics(
907
914
  truncated: false,
908
915
  subject,
909
916
  pods: value.pods,
917
+ ...(podNames ? { podNames } : {}),
910
918
  partial,
911
919
  };
912
920
  builder.observe(
@@ -148,6 +148,7 @@ export function adaptIssues(
148
148
  "Issue-related changes",
149
149
  "Radar's change history is incomplete for part of the window, so earlier changes may be missing.",
150
150
  "unknown",
151
+ "history",
151
152
  );
152
153
  }
153
154
  if (nonEmptyString(value.recent_changes_error)) {
@@ -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";
@@ -974,7 +975,8 @@ describe("query_prometheus evidence", () => {
974
975
  ]);
975
976
  expect(groupsOf(projection.groups, "metrics")).toHaveLength(0);
976
977
  expect(projection.limitations).toHaveLength(1);
977
- expect(projection.limitations[0].kind).toBe("truncated");
978
+ expect(projection.limitations[0].kind).toBe("unknown");
979
+ expect(projection.limitations[0].presentation).toBeUndefined();
978
980
  expect(projection.limitations[0].message).toContain("812 series");
979
981
  expect(projection.limitations[0].message).toContain(
980
982
  "812 distinct pod values",
@@ -1639,3 +1641,42 @@ describe("query_prometheus evidence", () => {
1639
1641
  expect(groups[0].observations[1].changedFromPrevious).toBe(true);
1640
1642
  });
1641
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
@@ -747,7 +773,8 @@ export function adaptQueryPrometheus(
747
773
  source,
748
774
  "Prometheus query",
749
775
  `The result of \`${value.query}\` was too large to keep${parts.length ? ` (${parts.join(", ")})` : ""}, so Radar cannot chart it.${note ? ` ${note}` : ""}`,
750
- "truncated",
776
+ // No series is kept, so this is an unknown, not a sample of the answer.
777
+ "unknown",
751
778
  );
752
779
  return;
753
780
  }
@@ -0,0 +1,28 @@
1
+ {
2
+ "resource": {
3
+ "apiVersion": "s3.example.crossplane.io/v1",
4
+ "kind": "Bucket",
5
+ "metadata": {
6
+ "name": "archive",
7
+ "namespace": "shop",
8
+ "annotations": { "crossplane.io/paused": "true" }
9
+ },
10
+ "spec": { "providerConfigRef": { "name": "fixture" } },
11
+ "status": {
12
+ "conditions": [
13
+ { "type": "Ready", "status": "True", "reason": "Available" },
14
+ { "type": "Synced", "status": "False", "reason": "ReconcilePaused", "message": "Fixture controller pause observation" }
15
+ ]
16
+ }
17
+ },
18
+ "resourceContext": {
19
+ "tier": "basic",
20
+ "statusSummary": {
21
+ "conditions": [
22
+ { "type": "Ready", "status": "True", "reason": "Available" },
23
+ { "type": "Synced", "status": "False", "reason": "ReconcilePaused", "message": "Fixture controller pause observation" }
24
+ ]
25
+ }
26
+ },
27
+ "warnings": []
28
+ }
@@ -1,3 +1,4 @@
1
+ import { getCrossplanePauseState, isManagedResource, isComposite } from "@skyhook-io/k8s-ui/components/resources/resource-utils-crossplane";
1
2
  import type { MetricsChangeCoverage } from "../../investigationMetrics";
2
3
  import type {
3
4
  InvestigationEvidenceData,
@@ -109,6 +110,7 @@ export function evidenceHasDetails(
109
110
  case "resource": {
110
111
  const replicas = data.resourceContext?.workloadSummary?.replicas;
111
112
  return Boolean(
113
+ ((isManagedResource(data.resource) || isComposite(data.resource) || getCrossplanePauseState(data.resource) === "acknowledged") && getCrossplanePauseState(data.resource)) ||
112
114
  investigationResourceEvidenceHasDetails(data.resource) ||
113
115
  replicas?.desired !== undefined ||
114
116
  data.resourceContext?.statusSummary?.conditions?.length ||
@@ -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