feat: shared pkg/recordfmt + xtcp2client -format (re-land to main)#43
Merged
Conversation
…output Extract the record formatting (json/jsonl/csv/tsv/humanize + protobufList/ text/msgpack) and humanizing (IPs, TCP state, congestion enum, timestamp) out of pkg/xtcp into a new pure library, pkg/recordfmt, used by both the daemon and the gRPC client so they format identically. pkg/recordfmt: - humanize.go, columns.go (reflection-derived columns + selection), marshal.go (per-record incl. MarshalHumanizedJSON), marshal_envelope.go (batch + pool-friendly AppendEnvelopeProtobufList). Pure: returns ([]byte, error), no prometheus/pool/logging — callers own those. Format-name constants are the single source of truth. pkg/xtcp: marshallers.go / marshallers_text.go become thin wrappers that keep the registries, destBytesPool reuse for protobufList, and prometheus error counting, delegating byte production to recordfmt. New `humanize` marshaller (humanized JSONL) for parity. humanize.go and flat_record_row.go removed (moved). Existing daemon tests unchanged and green. cmd/xtcp2client: now actually outputs records. New -format json|csv|tsv| humanize|null (+ -columns for csv/tsv); -json kept as a deprecated alias. A concurrency-safe recordPrinter writes via recordfmt, csv/tsv header once. Verified end-to-end against a live daemon: each client -format prints real humanized host sockets (172.16.50.219 / LISTEN / CUBIC); daemon -marshal humanize emits humanized JSONL. nix lint + unit + cmd tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-lands PR #40 onto
main. #40 was merged into its stacked basefeat/output-formats-destinationsafter that branch had already merged tomain(via #38), so the commit never reachedmain. This PR targetsmaindirectly.Contents (the one feature commit): the pure
pkg/recordfmtshared library (humanize, columns, per-record + per-envelope marshallers incl.MarshalHumanizedJSON), the daemon rewired to delegate to it (behavior-preserving; adds thehumanizemarshaller), andxtcp2client -format json|csv|tsv|humanize|null(+-columns).Verified locally: merges cleanly into current
main;nixlint + unit + cmd tests passed pre-merge; end-to-end client formats confirmed against a live daemon.🤖 Generated with Claude Code