Skip to content

feat: add --csv-header option to encode command#743

Draft
ljluestc wants to merge 2 commits intotsenart:masterfrom
ljluestc:feature/add-csv-headers-option
Draft

feat: add --csv-header option to encode command#743
ljluestc wants to merge 2 commits intotsenart:masterfrom
ljluestc:feature/add-csv-headers-option

Conversation

@ljluestc
Copy link
Copy Markdown

Add --csv-header option to encode command

Background

This PR addresses issue #588 where users requested a way to include headers in CSV output for better readability and easier processing with downstream tools. Currently, vegeta encode outputs raw CSV data without headers, requiring manual workarounds.

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR adds a --csv-header flag to the vegeta encode command, allowing users to output CSV files with a header row.

Implementation Details:

  • Refactored lib/results.go:
    • Exposed CSVHeader (lowercase) for consistency.
    • Added WriteCSVHeader(w io.Writer) error helper function.
  • Updated encode.go:
    • Added --csv-header flag.
    • Integrated WriteCSVHeader in the encoding loop.
  • Updated lib/results_test.go:
    • Added TestWriteCSVHeader to verify the header content matches expectations.

Which issue(s) this PR fixes:
Fixes #588

Special notes for your reviewer:
Verification Results

Automated Tests
Ran go test ./... and make test (implicit via go test):

  • TestWriteCSVHeader passed.
  • Regression tests passed.

Manual Verification
Executed:

echo "GET http://:80" | go run . attack -rate=1 -duration=1s | go run . encode -to csv -csv-header

Output:

timestamp,code,latency,bytes_out,bytes_in,error,body,attack,seq,method,url,headers
1769322193920100568,0,209402,0,0,"Get ""http://:80"": lookup : no such host",,,0,GET,http://:80,

Does this PR introduce a user-facing change?:

Added --csv-header flag to encode command to output CSV headers.

Checklist

  • Git commit messages conform to community standards.
  • Each Git commit represents meaningful milestones or atomic units of work.
  • Changed or added code is covered by appropriate tests.

Background

This PR addresses issue #588 where users requested a way to include headers in CSV output for better readability and easier processing with downstream tools. Currently, vegeta encode outputs raw CSV data without headers, requiring manual workarounds.

Checklist

  • Git commit messages conform to community standards.
  • Each Git commit represents meaningful milestones or atomic units of work.
  • Changed or added code is covered by appropriate tests.

@ljluestc ljluestc force-pushed the feature/add-csv-headers-option branch from 76d9388 to 70e71bf Compare January 25, 2026 07:04
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.

Provide an option to output CSV headers with encode command

1 participant