refactor: split format/buffers.go model from render (#4661) - #4687
Merged
Merged
Conversation
Extract the show-system-buffers row/taxonomy MODEL out of buffers.go into a new buffers_model.go, mirroring the #4656 status_sections.go and #4657 cos_sections.go model-then-render split. Pure code motion; the rendered output is byte-identical. The prior CLI/gRPC/REST buffer-status parity bugs stemmed from the two renderers building the row set independently: FormatSystemBuffers (text, used by CLI + gRPC) and StructuredSystemBufferRows (structured, used by the REST endpoint) each ran the same three-call sample/row/counter build. This factors that duplicated build into one shared buildSystemBufferModel returning a systemBufferModel (rows + counterRows + knownUMEM/knownTX), so a row or counter added to the taxonomy surfaces in every renderer at once and cannot drift. buffers_model.go now owns the taxonomy label constants, the internal sample/row/counter/binding-key types, buildSystemBufferModel, the row builders (systemBufferRows / systemBufferCoSRows / systemBufferFlowCacheAggregate / systemBufferCounterRows), the WARNING/CRITICAL usage classifier (systemBufferUsage), the helper-status sampling and per-binding fallback (systemBufferSamples / applyBindingStatusFallback), and the scope helpers. buffers.go keeps the two section-heading constants, the exported REST row types, the exported API (SystemBufferUtilizationRows / StructuredSystemBufferRows + the exportedSystemBuffer* mappers), and FormatSystemBuffers, now reduced to a build-then-render orchestrator over two new per-section render helpers (writeSystemBufferUtilizationSection / writeSystemBufferCountersSection). The counter-section leading-blank-line spacing (HasSuffix "\n\n") is preserved. No symbol collision with status_sections.go / cos_sections.go. Byte-identity gate: TestFormatSystemBuffersGolden pins the full output of both render modes (detail=false/true) plus the "unavailable" branch for a fixture that exercises UMEM/TX/CoS aggregate+detail rows, bounded session/flow-cache/neighbor rows, the WARNING/CRITICAL classes, the high-utilization warning count, and every status counter with its per-binding detail rows. The golden fixture was generated by running the same test on a pristine pre-refactor origin/master worktree; the refactored code then reproduced it byte-for-byte (test passes without -update). It reuses the package-level updateGolden flag from status_golden_test.go. Validation: go build ./... clean, go vet clean, gofmt clean, go test ./pkg/dataplane/userspace/format/ green. No module-doc change needed: the format package has no README (matches #4656/#4657, which touched only _Log.md plus the golden test/fixture), and the split is behavior-identical. Closes #4661 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors show system buffers formatting to share a single, renderer-agnostic row/counter model between the text (CLI/gRPC) and structured (REST) outputs, eliminating prior drift risk while keeping output byte-identical.
Changes:
- Extracts the buffer row/counter taxonomy + sampling/aggregation logic into a new
buffers_model.gomodel builder (buildSystemBufferModel). - Reduces
buffers.goto exported structured types/APIs plus a build-then-renderFormatSystemBufferswith per-section render helpers. - Adds a golden test + fixture to gate byte-for-byte output stability across detail modes and the “unavailable” branch.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/dataplane/userspace/format/buffers.go | Converts text/structured renderers to consume a shared model and splits rendering into utilization/counters helpers. |
| pkg/dataplane/userspace/format/buffers_model.go | New SSOT model: taxonomy labels, sampling, aggregation, row/counter construction, and usage classification. |
| pkg/dataplane/userspace/format/buffers_golden_test.go | Adds a golden test to enforce byte-identical output across render modes/branches. |
| pkg/dataplane/userspace/format/testdata/system_buffers.golden | New golden fixture capturing expected output for the new test gate. |
| _Log.md | Logs the refactor per repository logging rules. |
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.
Summary
Closes #4661.
Extracts the
show system buffersrow/taxonomy model out offormat/buffers.gointo a newbuffers_model.go, mirroring the #4656status_sections.goand #4657cos_sections.gomodel-then-render split.Pure code motion — the rendered output is byte-identical.
Why
Prior CLI/gRPC/REST buffer-status parity bugs came from the two renderers
building the row set independently:
FormatSystemBuffers(text) — used by CLI (cli_show_system.go) and gRPC (server_show_system.go)StructuredSystemBufferRows(structured) — used by the REST endpoint (api/system.go)Both ran the same three-call sample/row/counter build. This factors that
duplicated build into one shared
buildSystemBufferModelreturning asystemBufferModel(rows + counterRows + knownUMEM/knownTX), so a row orcounter added to the taxonomy surfaces in every renderer at once and cannot
drift.
Layout after the split
buffers_model.go(new): taxonomy label constants, internalsample/row/counter/binding-key types,
buildSystemBufferModel, the rowbuilders, the WARNING/CRITICAL usage classifier, helper-status sampling +
per-binding fallback, and scope helpers.
buffers.go(773 → 160 LOC): section-heading constants, exported RESTrow types, exported API, and
FormatSystemBuffersreduced to abuild-then-render orchestrator over two new per-section render helpers
(
writeSystemBufferUtilizationSection/writeSystemBufferCountersSection).The counter-section leading-blank-line spacing (
HasSuffix "\n\n") ispreserved. No symbol collision with
status_sections.go/cos_sections.go.Byte-identity gate
TestFormatSystemBuffersGoldenpins the full output of both render modes(detail=false/true) plus the "unavailable" branch for a fixture exercising
UMEM/TX/CoS aggregate+detail rows, bounded session/flow-cache/neighbor rows,
the WARNING/CRITICAL classes, the high-util warning count, and every status
counter with per-binding detail. The golden fixture was generated by running
the same test on a pristine pre-refactor
origin/masterworktree; therefactored code then reproduced it byte-for-byte (passes without
-update).Reuses the package-level
updateGoldenflag fromstatus_golden_test.go.Validation
go build ./...cleango vet ./pkg/dataplane/userspace/format/cleangofmtcleango test ./pkg/dataplane/userspace/format/green (incl. the new golden + all existing substring tests)No module-doc change needed: the format package has no README (matches
#4656/#4657, which touched only
_Log.md+ the golden test/fixture), and thesplit is behavior-identical.
🤖 Generated with Claude Code
https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi