Skip to content

feat(events-export): EXD-T01/T02 — the producer and the config (V405) - #404

Merged
randomizedcoder merged 1 commit into
mainfrom
goip/events-export-exd
Dec 6, 2026
Merged

randomizedcoder merged 1 commit into
mainfrom
goip/events-export-exd

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

What

Tier EXD's first two tasks (per docs/netlink/events-export.md): the producer and the config. The design was recorded in PR #395 against three measured constraints — this lands it.

rtnlmon's header-carrying dispatch

HandlerHdr (EventHdr(hdr, ev)) — an optional interface, detected once; the walk already holds the nlmsghdr at the dispatch point, so the wrapper's nlmsg_seq/nlmsg_pid (the originating process's echo, the §13 note's own trap) reach the export instead of vanishing at Handler.Event. The plain Handler dispatches unchanged. The rule groups (GroupIPv4Rule/GroupIPv6Rule) are valid but contribute no snapshot dump — nothing folds rules.

The producer (pkg/xtcp/events_export.go)

One rtnlmon listener per monitored namespace feeds a shared envelope (EXM: one notification per datagram — the flush policy is the batching, low volume shares it). The handler no-ops Run's startup Snapshot (drain-then-dump is resync state, not events; non-start reasons count so an overrun's drops are visible), converts each event (the nsid snapshot read at event time), and appends. Flush on rows cap / bytes cap / the interval / shutdown writes the ProtobufList wire — recordfmt.AppendDelimited, the generic twin of the record path's AppendEnvelopeProtobufList, plus NextDelimited, the read-back reader. The interval chain is epoch-guarded: a stale timer callback no-ops instead of stacking a second timer forever (TestEventsExportStaleTimerNoOp).

The composition: listenNamespace is netNamespaceInstance's wait — the events listener takes the thread when -localityEvents is off (the default); both on → the fold keeps the thread (unchanged) and the export gets a second in-namespace thread through a dup'd ns fd (the setns/restore dance mirrors netNamespaceInstance's). The root namespace's listener runs beside openDefaultNetLinkSocket's, like the locality's.

The config (T02)

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 file sink is v1's own — the destinations' factories are single-dest (the #395 design's recorded constraint); the factory generalization is EXC's measured need. The first cut's min_len: 6 on events_dest rejected the empty default (caught by TestRunMain_debugWritersNotCompiledIn); the field now validates max-len only and enable-without-dest is the startup error.

Tests

TestRunHandlerHdr (header fidelity through the dispatch, pinned from a corpus datagram retagged with a distinctive echo — NLM_F_ECHO, since NLM_F_MULTI is filtered), TestPlanDumpsRuleGroups, TestEventsExportFlush{RowsCap,BytesCap,Interval,Shutdown}, TestEventsExportStaleTimerNoOp, TestEventsExportHandler (the glue: header fields, the nsid lookup, the unreachable Event), TestEventsNetnsLabel, TestEventsExportWaitDispatch (the three compositions), TestDelimitedRoundTrip/TestNextDelimitedErrors.

Gates

Both full suites (the known TestSockstatReader io_uring flake fired once at host load 37.5 — A/B-proven environmental: the write suite and the interleaved re-runs green at the same load), go vet both modes, gofmt, lint-baseline, nix-fmt, test-goip-docs, netlink-audit, test-goip-monitorfile, buf lint. Ledger: V405 in events-export-status.md.

🤖 Generated with pi

The -eventsEnable producer (docs/netlink/events-export.md, Tier EXD):
one rtnlmon listener per monitored namespace feeds a shared envelope
that flushes on EXM's caps.

rtnlmon gains the header-carrying dispatch: HandlerHdr (EventHdr(hdr,
ev)) is detected once and handed the nlmsghdr the walk already holds
at the dispatch point, so the wrapper's nlmsg_seq/nlmsg_pid - the
originating process's echo, the 13 note's own trap - reach the export
instead of vanishing at Handler.Event. The plain Handler dispatches
unchanged. The rule groups (GroupIPv4Rule/GroupIPv6Rule) are valid but
contribute no snapshot dump: nothing folds rules.

The producer (pkg/xtcp/events_export.go): the handler no-ops Run's
startup Snapshot (drain-then-dump is resync state, not events; the
non-start reasons count so an overrun's drops are visible), converts
each event with the nsid snapshot read at event time, and appends to
the shared envelope. Flush on rows cap, bytes cap, the interval and
shutdown writes the ProtobufList wire - recordfmt.AppendDelimited, the
generic twin of the record path's AppendEnvelopeProtobufList, plus
NextDelimited, the read-back reader. The interval chain is guarded by
an epoch: a stale timer callback (fired while a cap flush held the
mutex) no-ops instead of stacking a second timer forever.

The composition: listenNamespace is netNamespaceInstance's wait - the
events listener takes the thread when -localityEvents is off (the
default); when both are on, the fold keeps the thread (unchanged) and
the export gets a second in-namespace thread through a dup'd ns fd
(the setns/restore dance mirrors netNamespaceInstance's, including the
forbidigo-justified Unlock). The root namespace's listener runs beside
openDefaultNetLinkSocket's, like the locality's.

The config: events_enable/events_dest/events_flush_* at 260-264
(0 = the EXM constants), the five -events* flags, env fallbacks. The
file sink is v1's own - the destinations' factories are single-dest
(the EXD design's recorded constraint); the factory generalization is
EXC's measured need. The first cut's min_len: 6 on events_dest
rejected the empty default and was caught by
TestRunMain_debugWritersNotCompiledIn; the field now validates
max-len only and enable-without-dest is the startup error.

Gates: both full suites (the known TestSockstatReader io_uring flake
red once at host load 37.5, A/B-proven environmental: the write suite
and the interleaved re-runs green at the same load), vet both modes,
gofmt, lint-baseline, nix-fmt, test-goip-docs, netlink-audit,
test-goip-monitorfile, buf lint.

Generated with [pi](https://github.com/badlogic/pi-mono)
@randomizedcoder
randomizedcoder merged commit 59f8f9d into main Dec 6, 2026
1 check passed
@randomizedcoder
randomizedcoder deleted the goip/events-export-exd branch December 6, 2026 01:57
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