Repository navigation
feat: add JSON output to coder ping - #30148
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7803439d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if jsonOutput { | ||
| diagOut = inv.Stderr |
There was a problem hiding this comment.
Send verbose logs to stderr in JSON mode
When --verbose or CODER_VERBOSE is enabled with -o json, this redirects only explicit diagnostic writes. The logger configured below still appends sloghuman.Sink(inv.Stdout), and DialAgent emits debug messages through it, so stdout contains log lines in addition to the JSON document and cannot be parsed as JSON. Route that logger to stderr when JSON output is selected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b4f4580: the verbose logger now writes to diagOut, which is stderr in -o json mode, so --verbose no longer corrupts the JSON document.
Generated by Coder Agents on behalf of @nickvigilante.
| pongs = append(pongs, PingJSONPong{ | ||
| Sequence: n, | ||
| Time: &pongTime, | ||
| LatencyMS: &latencyMS, | ||
| Direct: &direct, | ||
| DERPRegion: derpRegionName, | ||
| }) |
There was a problem hiding this comment.
Only collect pong records for JSON output
In the default table mode, every successful attempt is now retained in pongs even though the slice is never used. Because coder ping runs indefinitely unless --num is provided, this makes the normal ping-like command consume memory continuously, especially with a small --wait; guard all of the pong appends behind jsonOutput so table mode retains its previous constant-memory behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b4f4580: every pongs append (timeout, no matching peer, failure, success) is now gated on jsonOutput, so a long-running coder ping in table mode no longer grows memory without bound.
Generated by Coder Agents on behalf of @nickvigilante.
| pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, dur.String()), | ||
| ) | ||
|
|
||
| latencyMS := float64(dur) / float64(time.Millisecond) |
There was a problem hiding this comment.
Keep raw latency for JSON output
For successful pings, dur is rounded to the nearest millisecond before this conversion, so latency_ms is always integral despite being a float and can report a sub-millisecond ping as zero. The summary is calculated from the unrounded pong.LatencySeconds, which also makes an individual pong disagree with min_ms, avg_ms, and max_ms; preserve the raw duration for JSON and round only the human-readable display value.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b4f4580: the human-readable line uses a separately rounded duration, and latency_ms uses the raw value, so sub-millisecond pings no longer report 0 and the value agrees with min_ms, avg_ms, and max_ms.
Generated by Coder Agents on behalf of @nickvigilante.
@matifali Standard b4f4580 also fixes the three JSON correctness issues Codex flagged. Generated by Coder Agents on behalf of @nickvigilante. |
|
The main concern is around the sticky nature of this command. How would that fit into a json? Which when interrupted prints aggregated stats, |
|
But when run with |
@matifali Good catch. A single JSON document doesn't fit the default continuous mode: stdout stayed empty until Ctrl+C, and every pong was held in memory until then. Generated by Coder Agents on behalf of @nickvigilante. |
61b39ef to
8e62769
Compare
`coder ping` printed per-pong lines and a summary table with no structured output, so monitoring scripts had to parse text. Linear: CLI-32
Route verbose diagnostic logs to stderr in JSON mode, only collect pong records when JSON output is requested to keep table mode at constant memory, and preserve the unrounded latency for JSON so it matches the summary statistics and does not report sub-millisecond pings as zero.
coder ping continues until interrupted unless --num is set, and JSON output is a single document printed when pinging ends. Without --num, stdout stayed empty until Ctrl+C and every pong was held in memory. Fail early instead, so scripts get a clear error rather than a command that never prints.
Addresses review feedback that the JSON path hand-rolled its own --output enum and encoder, and threaded jsonOutput checks through the ping loop. The command now uses the shared table/json formatter like speedtest, with one recordPong helper and one finishEarly helper replacing the scattered branches. This also adds the standard --column flag for table output and writes the summary rule to the invocation's stdout instead of os.Stdout.
8e62769 to
0e31663
Compare
coder pingprinted per-pong lines and a summary table with no structured output, so monitoring scripts had to parse text.It now accepts
-o table|json(defaulttable, today's output) through the shared CLI output formatter.JSON is a single document at the end with each attempt (sequence, time, latency, direct or DERP region, error) and the summary.
Behavior change: Additive.
Default output is unchanged.
-o jsonrequires--numand fails early without it, because pings otherwise continue until interrupted.In JSON mode, the per-pong and diagnostic lines that normally go to stdout go to stderr, so stdout contains only the JSON document.
Decisions
--numwith-o json. In the default continuous mode, a single document would leave stdout empty until Ctrl+C and hold every pong in memory. Newline-delimited JSON per pong is a possible follow-up if continuous machine-readable output is needed.*_msfloats becausetime.Durationdoesn't marshal to a portable unit.cliui.NewOutputFormatter(table and JSON), matchingcoder speedtest. This also adds the standard-c, --columnflag for the summary table.CI note
Storybookfailed once on 61b39ef inside Pixel (build finished with status failed). This PR changes no frontend files; the job passed on rerun.test-go-pg (ubuntu-latest)failed on 8e62769 in run 38948569950 onTestChatTurnStopsAtStepLimit/Defaultincoderd/x/chatd. This PR doesn't touchcoderd/x/chatd, so the failed job was re-run.Closes CLI-32
This PR was generated by Coder Agents on behalf of @nickvigilante.