Skip to content

refactor: split format/buffers.go model from render (#4661) - #4687

Merged
psaab merged 1 commit into
masterfrom
refactor/4661-buffers-split
Jul 8, 2026
Merged

psaab merged 1 commit into
masterfrom
refactor/4661-buffers-split

Conversation

@psaab

@psaab psaab commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #4661.

Extracts the show system buffers row/taxonomy model out of
format/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.

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 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.

Layout after the split

  • buffers_model.go (new): taxonomy label constants, internal
    sample/row/counter/binding-key types, buildSystemBufferModel, the row
    builders, the WARNING/CRITICAL usage classifier, helper-status sampling +
    per-binding fallback, and scope helpers.
  • buffers.go (773 → 160 LOC): section-heading constants, exported REST
    row types, exported API, and FormatSystemBuffers 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 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/master worktree; the
refactored code then reproduced it byte-for-byte (passes without -update).
Reuses the package-level updateGolden flag from status_golden_test.go.

Validation

  • go build ./... clean
  • go vet ./pkg/dataplane/userspace/format/ clean
  • gofmt clean
  • go 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 the
split is behavior-identical.

🤖 Generated with Claude Code

https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi

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
Copilot AI review requested due to automatic review settings July 8, 2026 20:20
@psaab
psaab merged commit b40b592 into master Jul 8, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go model builder (buildSystemBufferModel).
  • Reduces buffers.go to exported structured types/APIs plus a build-then-render FormatSystemBuffers with 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.

@psaab
psaab deleted the refactor/4661-buffers-split branch September 7, 2026 14:56
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.

refactor: format/buffers.go (773 LOC) — shared row model (CLI/gRPC/REST buffer-status parity)

2 participants