Skip to content

Comments

feat: Output Formatters for Metrics (TASK-402)#97

Merged
copyleftdev merged 1 commit intomainfrom
feat/TASK-402-output-formatters
Jan 11, 2026
Merged

feat: Output Formatters for Metrics (TASK-402)#97
copyleftdev merged 1 commit intomainfrom
feat/TASK-402-output-formatters

Conversation

@copyleftdev
Copy link
Owner

Problem

The existing output formatters in src/output.zig only support a basic TestResult struct with limited fields. The full Metrics structure from TASK-401 contains comprehensive data (requests, latency percentiles, throughput, connections, errors) that needs to be formatted for human-readable summaries, machine-readable JSON, CSV time-series, and comparison diffs.

Solution

Enhanced src/output.zig with formatters for the full Metrics structure:

New Formatters:

  • formatSummaryText() - Human-readable summary with sections for requests, latency (ms), throughput (RPS), errors, and connections
  • formatMetricsJSON() - Machine-readable JSON with pretty-print and compact modes, includes by_method and by_status breakdowns
  • formatTimeSeriesHeader() / formatTimeSeriesRow() - CSV time-series format for streaming interval data
  • formatDiff() - Compare two metric runs with improvement/regression indicators

Helper Functions:

  • nsToMs() - Convert nanoseconds to milliseconds
  • formatWithCommas() - Number formatting with thousand separators (e.g., 1,234,567)
  • formatPercent() - Percentage formatting with 1 decimal place
  • formatDelta() - Delta with direction indicator for comparisons

New Types:

  • OutputConfig - Configuration struct for output options
  • IntervalMetrics - Data structure for time-series data points

Convenience Functions:

  • metricsToJSON() - Allocate JSON string from Metrics
  • metricsToSummary() - Allocate summary string from Metrics

Testing

All 23 tests passing:

  • 6 legacy TestResult tests (backward compatibility)
  • 17 new Metrics formatter tests covering:
    • Helper function unit tests (nsToMs, formatWithCommas, formatPercent)
    • Summary text generation (basic and empty metrics)
    • JSON output structure and by_method breakdown
    • Compact JSON mode (no newlines)
    • CSV time-series header and row formatting
    • Diff output with improvements and regressions
    • Convenience function allocation tests
zig test src/output.zig
# All 23 tests passed.

🤖 Generated with Claude Code

Enhance output formatting to support full Metrics structure with
multiple output formats per OUTPUT_FORMAT.md specification.

New formatters:
- formatSummaryText: Human-readable summary with sections for
  requests, latency, throughput, errors, and connections
- formatMetricsJSON: Machine-readable JSON with pretty/compact modes
- formatTimeSeriesHeader/Row: CSV time-series for streaming data
- formatDiff: Compare two runs with improvement/regression indicators

Helper functions:
- nsToMs: Convert nanoseconds to milliseconds
- formatWithCommas: Number formatting with thousand separators
- formatPercent: Percentage formatting with 1 decimal
- formatDelta: Delta with direction indicator

New types:
- OutputConfig: Configuration for output formatting
- IntervalMetrics: Data structure for time-series points

All 23 tests passing (6 legacy + 17 new).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@copyleftdev copyleftdev merged commit 4b6d090 into main Jan 11, 2026
1 check passed
@copyleftdev copyleftdev deleted the feat/TASK-402-output-formatters branch January 11, 2026 16:46
@copyleftdev copyleftdev mentioned this pull request Jan 11, 2026
22 tasks
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