Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs/netlink/events-export-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

- States are `not started`, `in progress`, `blocked`, `done` or `deferred`. There are no percentages.
- A task is `done` only when its gates have passed and the evidence is in the [ledger](#verification-ledger).
- Evidence IDs (`V###` for code and VM runs, `DOC###` for docs) are immutable and append-only. The next free ID is V406; the next free DOC is DOC040 (DOC039 is the gobridge write arc's 26B; DOC038 is the gobridge monitor arc's 25B, renumbered from its landed DOC035 — a collision with the events plan's DOC035 — by the events export arc's index-row fix).
- Evidence IDs (`V###` for code and VM runs, `DOC###` for docs) are immutable and append-only. The next free ID is V407; the next free DOC is DOC040 (DOC039 is the gobridge write arc's 26B; DOC038 is the gobridge monitor arc's 25B, renumbered from its landed DOC035 — a collision with the events plan's DOC035 — by the events export arc's index-row fix).
- Task IDs (`EXM`, `EXP`, `EXD`, `EXC`, `EXU` with `-Tmm` suffixes) are never renumbered.

## Phase states
Expand All @@ -49,7 +49,7 @@
|---|---|---|---|---|
| [Tier EXM](events-export.md#tier-exm-the-policy-measured) | the constants, measured from the corpora | EXM-T02 | done | V403 |
| [Tier EXP](events-export.md#tier-exp-the-proto) | the messages, the generation, the conversion | EXP-T02 | done | V404 |
| [Tier EXD](events-export.md#tier-exd-the-destination) | the producer, the config, the self-test gate | EXD-T03 | in progress (T01/T02 done, V405) | V405 |
| [Tier EXD](events-export.md#tier-exd-the-destination) | the producer, the config, the self-test gate | EXD-T03 | done | V405, V406 |
| [Tier EXC](events-export.md#tier-exc-clickhouse) | the table, the topic, the flavor | EXC-T03 | not started | — |
| [Tier EXU](events-export.md#tier-exu-the-close) | §14 resolved, the deferrals unwound | EXU-T01 | not started | — |

Expand All @@ -63,7 +63,7 @@
| [x] | [EXP-T02](events-export.md#exp-t02-generation-and-conversion) | generation and conversion | done | V404 |
| [x] | [EXD-T01](events-export.md#exd-t01-the-producer) | the producer | done | V405 |
| [x] | [EXD-T02](events-export.md#exd-t02-the-config-and-the-flag) | the config and the flag | done | V405 |
| [ ] | [EXD-T03](events-export.md#exd-t03-the-gate) | the self-test gate | not started | — |
| [x] | [EXD-T03](events-export.md#exd-t03-the-gate) | the self-test gate | done | V406 |
| [ ] | [EXC-T01](events-export.md#exc-t01-the-table) | the table | not started | — |
| [ ] | [EXC-T02](events-export.md#exc-t02-the-epoch-and-the-topic) | the epoch and the topic | not started | — |
| [ ] | [EXC-T03](events-export.md#exc-t03-the-gate) | the flavor | not started | — |
Expand All @@ -73,12 +73,22 @@

| ID | Task | Evidence |
|---|---|---|
| V406 | EXD-T03 | **The gate, live.** The interface-naming flavor's daemon runs `-eventsEnable -eventsDest file:/var/log/xtcp2-events.bin` beside `-localityEvents` (the both-on composition), and the new EVENTS_EXPORT check (`nix/microvms/self-test.nix`, the `EVENTS_EXPORT` sentinel) drives a link add/up/addr/del sequence (`evtcheck0`, 198.51.100.77/32 — unique, so the file's other events cannot satisfy the greps) in the daemon's own namespace, reads the export back with **events-probe** (`tools/events-probe`, riding xtcp2AllPackage like rtnlmon-probe: the ProtobufList read-back via `recordfmt.NextDelimited` + `UnmarshalVT`, printing rtnlmon-probe's own line grammar plus the per-row netns), and asserts the four steps in order, the root listener's `netns=default`, and the interval flush counter. **The live run** (`nix build .#test-microvm-lifecycle-x86_64-interface-naming`, booted and driven here): `EVENTS_EXPORT_PASS (add=35 addr=40 del=50; rows=50; interval flushes=25)` and `OVERALL_PASS`. **Two root causes the gate caught, both now unit-pinned:** (1) the interval chain was armed only inside flushLocked — an exporter whose namespaces produce no startup events (a quiet boot; the veth topology must happen to churn) never arms one, and the 1s bound is dead from the start; the chain now arms at construction (`newEventsExport`), and `TestEventsExportIntervalFromConstruction` pins the fix. (2) the empty interval flush did not count (the return came before the counter), so the flush counter proved nothing on a quiet file; the counter now fires on every trigger, an empty envelope included — the empty cadence is the proof the timer lives. The gate's own lessons: the metrics' labels print sorted (function, type, variable — a `variable=…type=…` grep order never matches; the locality check's greps never place type= after variable= for this reason), the self-test's echo lines never reach the journal (the diagnostics ride the XTCP2_SELF_TEST_* sentinel line itself), and the check does not demand the whole file be `netns=default` — the rows from the flavor's other namespace are the per-namespace listener's, the both-on second in-namespace thread's events, and are the composition working, not a label bug (the run shows 8 of 52 on the non-root namespace). Gates: both full suites, vet both modes, gofmt, lint-baseline, nix-fmt, test-goip-docs, netlink-audit, test-goip-monitorfile, nix-fmt over the flavor edits, and the VM gate itself. |
| V405 | EXD-T01/T02 | **The producer** (`pkg/xtcp/events_export.go`): one `rtnlmon` listener per monitored namespace feeds a shared `eventsExport` — every namespace appends to one envelope (EXM: one notification per datagram, so the flush policy is the batching and low volume shares it), which flushes on the rows cap, the bytes cap, the interval and shutdown, writing the ProtobufList wire (`recordfmt.AppendDelimited`, the generic twin of the record path's `AppendEnvelopeProtobufList`, plus `NextDelimited` the read-back reader). **The header-carrying dispatch:** `rtnlmon.HandlerHdr` (`EventHdr(hdr, ev)`) — `run` detects it once and hands the handler the `nlmsghdr` it already holds at the dispatch point; the plain `Handler` is dispatched unchanged, and the handler's unreachable `Event` fails loudly. **The rule groups** (`GroupIPv4Rule`/`GroupIPv6Rule`) are valid but contribute no snapshot dump — nothing folds rules; the events' handler no-ops `Snapshot` entirely (the startup drain-then-dump is resync state; the non-start reasons count, so an overrun's dropped notifications are visible, never silent). **The epoch guard:** each flush schedules the next interval timer, and a stale callback (a timer that fired while a cap flush held the mutex) no-ops on its epoch — without it a second timer stacks behind the live one and doubles the cadence forever (`TestEventsExportStaleTimerNoOp`). **The both-on composition:** `-localityEvents` keeps the namespace's own wait thread (unchanged) and the export gets a second in-namespace thread through a `Dup` of the ns fd (setns in, run, restore; a failed restore keeps the thread locked so the runtime terminates it — netNamespaceInstance's own documented lesson). The both-off and events-only cases: `listenNamespace` is the one wait-thread dispatcher. **The config:** `events_enable`/`events_dest`/`events_flush_{interval_ms,threshold_rows,threshold_bytes}` at 260-264 (0 = the EXM constants), the five `-events*` flags, env fallbacks, goldens updated (`mainFlagsFieldCountCst` 146→151, `printflags-golden`, `defineflags-golden`). The `min_len: 6` first cut on `events_dest` rejected the empty default and was caught by `TestRunMain_debugWritersNotCompiledIn` — the field validates max-len only, and enable-without-dest is the startup error. **The gate tests:** `TestRunHandlerHdr` (header fidelity through the dispatch, pinned from a corpus datagram retagged with a distinctive echo — `NLM_F_ECHO`, not `NLM_F_MULTI`, which `WalkNotifications` filters), `TestPlanDumpsRuleGroups`, `TestEventsExportFlush{RowsCap,BytesCap,Interval,Shutdown}`, `TestEventsExportStaleTimerNoOp`, `TestEventsExportHandler` (the glue: header fields, nsid lookup, the unreachable Event), `TestEventsNetnsLabel`, `TestEventsExportWaitDispatch`, `TestDelimitedRoundTrip`/`TestNextDelimitedErrors`. Gates: both full suites, vet both modes, gofmt, `lint-baseline`, `test-goip-docs`, `netlink-audit`, `nix-fmt`, `buf lint`. The file sink is v1's own (the factories are single-dest); the factory generalization is EXC's measured need. |
| V404 | EXP | **The proto:** `proto/xtcp_netlink_events/v1/xtcp_netlink_events.proto` — the five family messages in the record proto's own style (the header cites the allocation plan: 2100 ifinfomsg, 2200 ifaddrmsg, 2300 rtmsg, 2400 ndmsg, 2500 fib_rule_hdr; the blocks sit above 2047, so every payload field costs a 3-byte tag — §14 assigns the numbers, and EXM's measured low volume is what makes the cost immaterial). Every field carries a kernel-source comment with the attribute number read from `~/Downloads/linux/include/uapi/linux/{if_link,if_addr,rtnetlink,neighbour,fib_rules}.h` (IFLA_OPERSTATE 16, NDA_FDB_EXT_ATTRS 14, FRA_DSCP_MASK 30, …). Presence is a `has_`-prefixed bool beside the value — the structs' own Has* pairs, load-bearing for the events' render semantics. **The v1 surface:** the header structs and the scalar attributes; the nested payloads (the forty per-kind link nests, RTA_MULTIPATH, RTA_METRICS, the stats blocks) are presence bits, each a later block, never an epoch bump — the file header's scope note names the rule. `NetlinkEvent` carries the nlmsghdr, the timestamp, the netns provenance (the record's own netns/netns_inode/nsid/nsid_assigned contract), the derived action enum, and the oneof. `XtcpNetlinkEventsSchemaVersion = 1` lands in `pkg/xtcp/schema_version.go` beside the record's. **Generated** by `nix run .#regen-protos` (the regen re-resolves the protovalidate dep in `buf.lock` to a newer commit; the events proto imports nothing, so the outputs are lock-independent and the lock is reverted — the drift is the regen path's own behavior, noted for the next arc that regenerates). **The conversion** (`pkg/xtcp/events_export_convert.go`): a pure function per family plus the `ConvertNetlinkEvent` wrapper (any other payload is an error, never a silent drop). **The gate:** `TestEventsExportConvertRoundTrip` walks the 71 event pcaps and the 15 crafted `.nl` files — parse, convert, marshal, unmarshal, `proto.Equal` — **458 link, 165 addr, 303 route, 107 neigh, 10 rule**, the totals pinned; `TestEventsExportConvertSpotPins` compares the struct's own values against the converted fields for one corpus event per family (the round trip alone cannot catch a swapped mapping — both directions would carry the same wrong field). **The wire-contract finding, groundwork for EXC:** the committed `clickhouse_protolist` artifacts pin the ProtobufList framing — `insert4294967295.proto.bin` is `[varint][Record bytes]` (one length-delimited row per row) while `insert1_and_4294967295.bin` is `[varint][Envelope]` (rows wrapped) — and the record's kafka table names the ROW type with the comment "ClickHouse's ProtobufList handles the envelope framing internally". Which schema name the events' engine table names, and how the oneof's payloads map to columns, is EXC-T01's container probe. Gates: both full suites, vet both modes, gofmt, `lint-baseline`, `test-goip-docs`, `netlink-audit`, `nix-fmt`, `buf lint` (STANDARD, clean). |
| V403 | EXM | **Measured:** `TestEventsExportPolicyInputs` (`pkg/xtcpnl/xtcpnl_events_export_policy_test.go`) walks the committed event corpora — the five 7.1.4 oneshot pcaps (a 41-second boot window; the base pcap the union of the four family splits, 355 = 66+125+44+120) and the 66 ev rows at both iproute2 versions — and pins the measured shape: events, datagrams, the per-event body sizes, the peak 100 ms and 1 s windows, the quiet gaps. **The finding that reshaped the tier:** one notification per datagram, every corpus, both kernel eras, every family (max events per datagram = 1, asserted over all 71 pcaps) — the plan's premise that the kernel batches notifications into one recvmsg is falsified; the flush policy is the batching. **The numbers:** the boot flood peaks at 56 events in 100 ms (60 in the worst second); a churn row's whole window peaks at 17; the quiet gaps run to 16.69 s (steady state); the event bodies run 40 bytes (the smallest route/nsid event) to 1548 (a full link event), median 40-116. **The constants** (`pkg/xtcp/events_export_policy.go`): `EventsFlushIntervalCst` = 1 s (the locality consumer's own chosen latency, the §13 close's "within a 1s debounce"; a lone event waits at most this), `EventsFlushThresholdRowsCst` = 64 (above the 56-per-100 ms boot peak, ~4× the churn rows' worst window), `EventsFlushThresholdBytesCst` = 64 KiB (~41 of the widest 1548-byte rows; the record path's rows-primary/bytes-secondary pair). The queue needs no events-specific depth: the destination's default (16 envelopes) holds over 1.5 s of the measured worst flood, and drop-oldest is the record path's answer. The test's walk treats a zero nlmsghdr as end-of-datagram padding (the 7.1.4 oneshot zero-pads its records — measured at base-pcap record 515) and is manual, not `WalkNlMsgsHdr`, because the latter's seq filter drops exactly the userspace-caused notifications (`IsRtnetlinkNotification`'s own documented trap). The crafted monitor files carry no timestamps, so they are EXP's round-trip inputs, not this measurement's. Gates: `go test ./pkg/xtcpnl/ -run TestEventsExportPolicyInputs`, both full suites, vet both modes, gofmt, `lint-baseline`, `test-goip-docs`, `netlink-audit`, `nix-fmt`. |

## Decision log

- **2026-12-05: the gate run caught the producer's zero-start (V406).** The
EXD-T03 gate's first live run exported nothing on a quiet boot — the
interval chain was armed only at a flush, so an exporter with no startup
events never armed a timer, and the 1s bound was dead from the start
(the run's binary at the second boot happened to see the veth topology
churn, reached the rows cap, and worked — the non-determinism is the
quiet boot's, which is exactly what the gate exists to catch). The fix:
arm at construction; the empty interval flushes now count, and
`TestEventsExportIntervalFromConstruction` pins it.
- **2026-12-04: EXD designed against three measured constraints (V404's
groundwork).** (1) `rtnlmon`'s `Handler.Event(ev any)` carries no
nlmsghdr — the wrapper's nlmsg_seq/nlmsg_pid (the originating process's
Expand Down
Binary file added events-probe
Binary file not shown.
6 changes: 6 additions & 0 deletions nix/binaries.nix
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ let
# snapshots and events. Rides xtcp2AllPackage into every lifecycle microvm,
# where the self-test runs it as the RTNL_EVENTS check.
"rtnlmon-probe"
# events-probe: reads the events-export destination file (-eventsEnable
# producer output) back and prints one line per row. Rides xtcp2AllPackage
# into the interface-naming microvm, where the self-test runs it as the
# EVENTS_EXPORT check (events-export.md, EXD-T03).
"events-probe"
# sockfill: holds N loopback TCP pairs (or a never-accepting listener)
# open in its namespace. Rides xtcp2AllPackage into the socket-scale
# microvm, which builds 100k-500k socket tables with it.
Expand Down Expand Up @@ -418,6 +423,7 @@ defaultBinaries
tcp_client
discovery-bench
rtnlmon-probe
events-probe
sockfill
ipfeed-fixture
slowloris
Expand Down
1 change: 1 addition & 0 deletions nix/microvms/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ let
"IFNAME"
"ASN"
"LOCALITY_EVENTS"
"EVENTS_EXPORT"
];
# Checks 5f/5g each poll for up to 2 min (x waitScale). That fits inside
# the default stall watchdog, and the old 600 s absolute cap is now below
Expand Down
15 changes: 15 additions & 0 deletions nix/microvms/mkVm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ let
# LOCALITY_SELF through the -localityEvents listener.
runLocalityEventsCheck = isInterfaceNaming;
localityEventsIf = ifnEgrIf;
# interface-naming flavor only (EXD-T03): the daemon runs -eventsEnable
# beside -localityEvents, and the EVENTS_EXPORT check drives a link
# add/up/addr/del sequence in the daemon's own namespace and reads the
# export back from -eventsDest.
runEventsExportCheck = isInterfaceNaming;
eventsExportPath = eventsExportPath;
inherit
asnDbPath
asnCachePath
Expand Down Expand Up @@ -2436,6 +2442,12 @@ let
# the self-test run as root, so a 0600 file under /var/log is readable.
fileOutputPath = "/var/log/xtcp2.jsonl";

# Where the events export writes when the flavor turns it on: the
# -eventsDest file: path (EXD's v1 sink, beside the record file dest —
# both root-owned 0600 under /var/log, readable by the self-test). The
# interface-naming flavor's EVENTS_EXPORT check reads it back.
eventsExportPath = "/var/log/xtcp2-events.bin";

# socket-sink flavors: stream jsonl records over the raw socket destination
# (tcp/udp/unix/unixgram) to the in-VM ncat receiver. For inet dests,
# `localhost` (dual-stack) resolves to 127.0.0.1 AND ::1 and the sink listens
Expand Down Expand Up @@ -3289,6 +3301,9 @@ in
"-localityEvents"
"-localityRefreshInterval"
"10m"
"-eventsEnable"
"-eventsDest"
"file:${eventsExportPath}"
"-enrichAsn"
"-asnDbPath"
asnDbPath
Expand Down
Loading