Skip to content

feat(goldenrec): shape profiles — compare a capture whose workload differs - #323

Merged
randomizedcoder merged 8 commits into
mainfrom
feat/golden-shape
Nov 24, 2026
Merged

randomizedcoder merged 8 commits into
mainfrom
feat/golden-shape

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

A capture from another host can't be diffed row by row against the golden fixture, because its workload differs. Its shape can. This adds a shape profile and a shape diff to xtcp2-golden. Done test-first.

Feature

  • xtcp2-golden profile IN: JSON with the row count, and per column the class, nonzero count and distinct count (capped at 64+). Also rows per family and per kind of namespace (container, host, docker, anon, named, unknown)
  • xtcp2-golden shape-diff A B: A and B are each a .parquet or a profile.json. Reports populated-only-in, value-only-in, column-only-in, family-missing, kind-missing, no-rows, and ignores row counts and distinct-count size. Exits 0/1/2 like diff
  • Profiles are meant to leave the host they were taken on, so they record no identity: values are listed only for columns on an explicit allowlist (profileListed: socket enums, congestion control, NIC driver, vendor, device and speed). ASNs, uids, class ids, container names and images, and interface names are only counted
  • nsid_assigned (from fix(xtcp2): nsid_assigned — tell the kernel's first nsid (0) apart from none #322) is listed and nsid is counted

Tests

  • TestProfile, TestProfileKinds, TestDiffProfiles, TestProfileListed, TestRunProfileShapeDiff: table-driven, all four categories
  • TestProfileListedDecided: every column of a valued class needs an explicit list-or-count decision, so a new column never lists its values by default
  • TestProfileNsidAssigned: nsid_assigned values listed, the ids only counted
  • The 7_3_1 fixture profiled against itself: exit 0 (48 rows, families 2 and 10, container/host/named namespaces)

Red (tests commit, before the feature)

pkg/goldenrec/profile_test.go:19:9: undefined: ColumnProfile
cmd/xtcp2-golden/shape_test.go:34:22: undefined: goldenrec.ProfileOf
FAIL	github.com/randomizedcoder/xtcp2/cmd/xtcp2-golden [build failed]

After merging #322, before Assigned was a valued class:

--- FAIL: TestProfileNsidAssigned/both_states
--- FAIL: TestProfileNsidAssigned/ids_counted
--- FAIL: TestProfileNsidAssigned/none_assigned

Green

go test ./... and the nix checks (gofmt, go-vet, nix-fmt, lint-baseline, golangci ×3, redteam-lint, golden-records, test-fuzz-all) pass.

🤖 Generated with Claude Code

randomizedcoder and others added 8 commits November 23, 2026 22:39
…exists

A golden capture from another host can't be diffed row for row: its
workload differs. What can be compared is its shape: which columns are
populated, which enum values occur, which families and namespace kinds.

- TestProfile, TestProfileKinds: per-column class, nonzero count and
  distinct count (capped at 64+), value sets for enum columns only (a
  container name is counted, never recorded), families, namespace kinds.
- TestDiffProfiles: populated-only-in, value-only-in, column-only-in,
  family-missing, no-rows; row counts and distinct magnitudes ignored.
- TestRunProfileShapeDiff: xtcp2-golden profile and shape-diff, taking a
  .parquet or a profile .json, exit 0/1/2 like diff.

Red: pkg/goldenrec and cmd/xtcp2-golden do not build (ProfileOf,
ColumnProfile, Profile, DiffProfiles undefined).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ffers

- goldenrec.ProfileOf: per column its class, nonzero count, distinct
  count (64+ past 64) and, for numeric/bool Strict columns and a few
  enum-like strings, the value set; rows per family and per kind of
  namespace. No identity: container names, images, labels and the like
  are counted, never listed.
- goldenrec.DiffProfiles: populated-only-in, value-only-in,
  column-only-in, family-missing, kind-missing, no-rows; row counts and
  distinct magnitudes are ignored.
- xtcp2-golden profile IN and shape-diff A B (each a .parquet or a
  profile .json), exit 0/1/2 like diff.
- nix/README (Golden records) and CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A profile leaves the host it was taken on. Listing every numeric Strict
column's values would carry ASNs, uids and cgroup class ids. Values are
now listed only for columns profileListed marks true, and a test makes
every valued column carry an explicit decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
goconst (comprehensive tier) flagged the repeated literals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assigned is a valued class now that it exists on main, and nsid_assigned
is on the listing allowlist; nsid itself stays counted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randomizedcoder
randomizedcoder merged commit f6b6035 into main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant