eBPF-based security platform
tools/xtop: rank a member with an unknown head before the caught-up ones
John Fastabend7acdf3f2b112
diff --git a/Documentation/operate/backend/xtop.rst b/Documentation/operate/backend/xtop.rstindex e946abac..4243d7be 100644--- a/Documentation/operate/backend/xtop.rst+++ b/Documentation/operate/backend/xtop.rst@@ -109,7 +109,8 @@ key the operator has recorded as a TPM's.record. ``—`` for a node that reports no image.* - ``TREE``- ``✓ #<head>`` at the head of its tree, ``#<last>/#<head>``- behind it, ``no tree`` when it follows none.+ behind it, ``#<last>`` when the head of its tree is not known,+ ``no tree`` when it follows none.* - ``SHIELDS``- From ``node_vulns``, counted by upatch: ``✓`` loaded andshielding (``shielded``), ``…`` coming (``shield_pending``),@@ -144,9 +145,9 @@ the nodes with one.labels of its members beside it, ``?`` for a member without one. Agroup's status is its worst member's, its health the percent of itsmembers ``healthy``, its kernel ``mixed`` when its members differ, its-tree the member furthest behind, its shields the sums over its members,-and its exposure that of its most exposed member. Enter on an image-shows its nodes.+tree the member furthest behind, or one whose head is not known when+none is behind, its shields the sums over its members, and its exposure+that of its most exposed member. Enter on an image shows its nodes.Detector hits are not shown: the collector of:src:`tools/backend/otelcol.yaml` takes in no map snapshot metrics.diff --git a/tools/xtop/src/lib/fleet.ts b/tools/xtop/src/lib/fleet.tsindex c75d89cd..6bc9b338 100644--- a/tools/xtop/src/lib/fleet.ts+++ b/tools/xtop/src/lib/fleet.ts@@ -128,13 +128,21 @@ export function healthPercent(nodes: readonly Pick<FleetNode, "status">[]): numbreturn Math.round((100 * nodes.filter((n) => n.status === "healthy").length) / nodes.length);}-/** head − last, 0 for a member that reports no head: how far behind its own tree a member is. */-const lagOf = (m: FleetNode) => (m.tree.headSeq === null ? 0 : m.tree.headSeq - m.tree.lastSeq!);+/**+ * Where a member with no known head ranks: after every member known to+ * be behind, which is a whole step or more, and before one caught up.+ */+const UNKNOWN_LAG = 0.5;++/** head − last: how far behind its own tree a member is. */+const lagOf = (m: FleetNode) => (m.tree.headSeq === null ? UNKNOWN_LAG : m.tree.headSeq - m.tree.lastSeq!);/*** The tree position of the member furthest behind its own tree, all-null* when none follows one. Members of an image can follow independent- * trees, so their positions never mix into one pair.+ * trees, so their positions never mix into one pair. A member whose+ * head is unknown counts ahead of the caught-up ones, so that the group+ * never reports a head every member reached while one may not have.*/function behindTree(members: readonly FleetNode[]): ImageGroup["tree"] {const worst = membersdiff --git a/tools/xtop/test/fleet.test.ts b/tools/xtop/test/fleet.test.tsindex e6a748a9..81a5efad 100644--- a/tools/xtop/test/fleet.test.ts+++ b/tools/xtop/test/fleet.test.ts@@ -249,6 +249,29 @@ describe("groupByImage", () => {]);expect(mixed[0]!.tree).toEqual({ lastSeq: 5, headSeq: 5 });});++ test("reports a member with an unknown head before the caught-up ones", () => {+ const member = (over: Partial<NodeRow>) => toFleetNode(row({ ...over }));+ // The caught-up member has the smaller last, which the tie-break prefers.+ const unknown = groupByImage([+ member({ ak_name: "000b001", last_seq: 3, head_seq: 3 }),+ member({ ak_name: "000b002", last_seq: 7, head_seq: null }),+ ]);+ expect(unknown[0]!.tree).toEqual({ lastSeq: 7, headSeq: null });+ // A member known to be behind still comes first, in either order.+ const behind = groupByImage([+ member({ ak_name: "000b001", last_seq: 7, head_seq: null }),+ member({ ak_name: "000b002", last_seq: 2, head_seq: 3 }),+ member({ ak_name: "000b003", last_seq: 5, head_seq: 5 }),+ ]);+ expect(behind[0]!.tree).toEqual({ lastSeq: 2, headSeq: 3 });+ // Among unknown heads the smaller last, as among known ones.+ const both = groupByImage([+ member({ ak_name: "000b001", last_seq: 7, head_seq: null }),+ member({ ak_name: "000b002", last_seq: 4, head_seq: null }),+ ]);+ expect(both[0]!.tree).toEqual({ lastSeq: 4, headSeq: null });+ });});describe("toFleetReport", () => {