Skip to content

format/status: split FormatStatusSummary aggregation from rendering#4679

Merged
psaab merged 1 commit into
masterfrom
refactor/4656-status-split
Jul 8, 2026
Merged

format/status: split FormatStatusSummary aggregation from rendering#4679
psaab merged 1 commit into
masterfrom
refactor/4656-status-split

Conversation

@psaab

@psaab psaab commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Closes #4656.

What

Pure code-motion refactor of FormatStatusSummary
(pkg/dataplane/userspace/format/status.go), which was a ~600-line
god-function (lines 103-711) doing both the single accumulation pass over
the status snapshot and the per-section rendering inline
(codex-review-174 #13, cold-path class-A).

  • Aggregation pass extracted into aggregateStatusSummary(status) statusSummaryAggregates
    (the struct holds every counter previously kept in ~90 locals plus the two
    derived residuals).
  • Each cohesive rendering block moved into a dedicated writeXxxSection
    helper: overview, event stream, security counters, NAT, source-NAT pools,
    TX+CoS summary, three-color policers, TX-path counters, slow path, worker
    runtime. New helpers live in status_sections.go.
  • FormatStatusSummary is now a 22-line orchestrator calling the helpers in
    the original top-to-bottom order.

Guardrails (from the issue) — all preserved

  • ONE pass over bindings: aggregateStatusSummary is the only place that
    walks status.Bindings (and Queues, and CoSInterfaces); render helpers
    read the returned struct and never re-iterate. No extra status fetches.
  • Deterministic order: same section sequence, same sorts on the source-NAT
    pool and three-color policer tables.
  • Omit-zero: every conditional suppression (SYN-cookie, generated-reply
    drops/sent/budget/rate-limit, CoS block, optional slow-path lines,
    worker-runtime dead/idle rows) moved verbatim.

Byte-identity gate

New TestFormatStatusSummaryGolden compares the full rendered output against
testdata/status_summary.golden, generated from the pre-refactor code over a
fixture that exercises every conditional section (wall-clock-relative fields
left zero so the golden is stable). The golden passes byte-for-byte after the
split — proof the output text is unchanged. Existing substring assertions in
status_test.go also stay green.

Validation

  • go build ./... clean
  • go vet ./pkg/dataplane/userspace/format/ clean
  • gofmt -w applied
  • go test ./pkg/dataplane/userspace/... green (16 status-summary tests incl. the golden gate)

🤖 Generated with Claude Code

https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi

FormatStatusSummary was a ~600-line function (status.go:103-711) doing
both the single accumulation pass over the status snapshot and the
per-section rendering inline. codex-review-174 #13 (#4656) flagged it as
a cold-path god-function: hard to read, and the aggregation and rendering
concerns were fully interleaved.

This is a pure code-motion refactor with byte-identical output. The
aggregation pass is extracted into aggregateStatusSummary, which returns
a statusSummaryAggregates struct holding every counter previously kept in
~90 local variables plus the two derived residuals
(currentRuntimeCoSAdmissionDrops, nonAdmissionTXErrors). Each cohesive
rendering block moves into a dedicated writeXxxSection helper (overview,
event stream, security counters, NAT, source-NAT pools, TX+CoS summary,
three-color policers, TX-path counters, slow path, worker runtime). The
new helpers live in status_sections.go; FormatStatusSummary is now a
short orchestrator that calls them in the original top-to-bottom order.

Guardrails held exactly as required by the issue:
  - ONE pass over status.Bindings. aggregateStatusSummary is the only
    place that walks Bindings (and Queues, and CoSInterfaces); the render
    helpers read the returned struct and never re-iterate. No extra
    status fetches were introduced.
  - Deterministic order preserved (same section sequence, same sorts on
    the source-NAT pool and three-color policer tables).
  - Omit-zero / conditional suppression preserved verbatim (SYN-cookie,
    generated-reply drops/sent/budget/rate-limit, CoS block, slow-path
    optional lines, worker-runtime dead/idle rows).

Byte-identity is proven by a new golden test: TestFormatStatusSummary
Golden compares the full rendered output against
testdata/status_summary.golden, which was generated from the pre-refactor
code over a fixture that exercises every conditional section (wall-clock-
relative fields are deliberately left zero so the golden is stable). The
golden passes byte-for-byte after the split; the existing substring
assertions in status_test.go also remain green.

Validation: go build ./... clean, go vet clean, gofmt -w applied,
go test ./pkg/dataplane/userspace/... green (16 status-summary tests
including the golden gate).

Closes #4656

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 15:49
@psaab
psaab merged commit ad341f6 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 the userspace dataplane FormatStatusSummary formatter by separating the single-pass snapshot aggregation from the per-section rendering, while adding a golden-output test to ensure byte-for-byte output stability.

Changes:

  • Extracted the counter accumulation work into aggregateStatusSummary(status) statusSummaryAggregates.
  • Moved each formatting block into focused writeXxxSection helpers in a new status_sections.go.
  • Added a golden test (TestFormatStatusSummaryGolden) and fixture output to gate output identity across refactors.

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/status.go Shrinks FormatStatusSummary into an orchestrator that aggregates once and delegates rendering to section helpers.
pkg/dataplane/userspace/format/status_sections.go Introduces the aggregate struct + single-pass aggregator and the extracted writeXxxSection render helpers.
pkg/dataplane/userspace/format/status_golden_test.go Adds a deterministic fixture + golden comparison (with -update support) to lock output bytes.
pkg/dataplane/userspace/format/testdata/status_summary.golden Golden output for full rendered status summary.
_Log.md Logs the refactor per repository logging rules.

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/status.go FormatStatusSummary (~600 LOC fn) — separate aggregation from rendering

2 participants