Make hammer agent-friendly: zero-config URL mode, JSON stdout, SLO exit codes#6
Merged
Merged
Conversation
…it codes Reshape hammer so any agent (or CI job) can run a meaningful load test in one command, parse the result without scraping human text, and branch on a stable exit code — while staying a single, dependency-free binary and keeping the existing profile format fully backward-compatible. New capabilities: - Zero-config one-shot mode: -url with -method/-body/-header/-content-type builds an in-memory single-call profile (templating still works), so no profile file is needed for the common case. - Profile from stdin: -profile - reads the Call stream from stdin. - Machine-readable output: -output json prints the full structured report to stdout while all logs stay on stderr, so stdout is always clean to pipe. - SLO assertions + exit codes: -max-error-rate / -max-p50 / -max-p95 / -max-p99 produce a pass/fail checks block and drive the process exit code (0 ok, 1 SLO violated, 2 usage, 3 setup). - Quieter automation: -quiet silences the live monitor; the /stats HTTP endpoint is now opt-in (default disabled) so runs don't bind a surprise port. - Richer report: error_rate, achieved_rps, and a checks section added to the JSON report; help banner documents usage, exit codes, and examples. Implementation notes: - profile: factor per-call init into Profile.add; add LoadFromReader (stdin) and SingleCall (URL mode) on top of it. - main: split into run() int so exit codes are explicit and deferred cleanup still runs; report() now writes to an io.Writer and appends check results. - Tests for SingleCall/LoadFromReader, header parsing, error-rate, threshold evaluation, and the new derived JSON fields. README rewritten with a dedicated "For agents" section. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E11t2fuxGyKayRSL3Yu5SE
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.
Reshape
hammerso any agent (or CI job) can run a meaningful load test in one command, parse the result without scraping human text, and branch on a stable exit code — while staying a single, dependency-free binary and keeping the existing profile format fully backward-compatible.What's new
1. Zero-config one-shot mode — no profile file needed:
Templating (
{{ uuid }},{{ randInt N }}) still works in-url/-body.2. Machine-readable stdout —
-output jsonemits the whole report to stdout; all logs stay on stderr, so stdout is always clean to pipe intojq.3. SLO assertions + meaningful exit codes —
-max-error-rate,-max-p50/p95/p99produce achecksblock and drive the exit code:0123So
hammer -url … -max-p99 500ms -max-error-rate 0 || alertjust works.4. Profile from stdin —
… | hammer -profile -for generated traffic mixes, no temp file.5. Quieter for automation —
-quietsilences the live monitor; the/statsHTTP endpoint is now opt-in (was:9001by default) so runs never bind a surprise port in CI/sandboxes.6. Richer report — added
error_rate,achieved_rps, andchecksto the JSON, plus a self-documenting-hbanner with examples and exit codes.Implementation notes
profile/: factored per-call init intoProfile.add, then addedLoadFromReader(stdin) andSingleCall(URL mode) on top of it — shared validation/templating path.hammer.go: splitmainintorun() intso exit codes are explicit and deferred cleanup still runs;report()now writes to anio.Writerand appends check results.SingleCall/LoadFromReader, header parsing, error-rate, threshold evaluation, and the new derived JSON fields. README rewritten with a dedicated For agents section.Compatibility
Everything is additive except one deliberate, documented default change:
-stats-addrnow defaults to disabled (was:9001). The profile format, existing flags, and JSON fields are unchanged.Verification
go build ./...,go vet ./..., andgo test -race ./...all pass; every new flow was exercised end-to-end against the local test server (zero-config mode, JSON-to-stdout, stdin profile, POST with headers, and exit codes for pass/fail/usage/setup).🤖 Generated with Claude Code
Generated by Claude Code