Add --format json option for HTTP trigger route output#3429
Add --format json option for HTTP trigger route output#3429itowlson merged 5 commits intospinframework:mainfrom
--format json option for HTTP trigger route output#3429Conversation
…nd summary hooks Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
--format json option for HTTP trigger route output
There was a problem hiding this comment.
Pull request overview
Adds a --format flag to the HTTP trigger to support machine-readable startup output, while shifting various diagnostic messages to stderr to keep stdout clean for structured output consumers.
Changes:
- Introduce
--format {plain,json}for the HTTP trigger and plumbOutputFormatthrough trigger/server construction. - Emit startup route information as JSON when
--format jsonis used (instead of human-readable text). - Move several previously-stdout diagnostic prints (runtime config, stdio logging, KV/SQLite summaries) to stderr and add an integration test that validates JSON stdout.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/testing-framework/src/runtimes/in_process_spin.rs | Updates in-process HTTP trigger initialization to pass the new OutputFormat parameter. |
| tests/integration.rs | Adds an integration test ensuring spin up --format json produces valid JSON with expected route fields. |
| crates/trigger/src/cli/summary.rs | Redirects KV/SQLite “storing default …” summaries from stdout to stderr. |
| crates/trigger/src/cli/stdio.rs | Redirects stdio logging directory message from stdout to stderr. |
| crates/trigger-http/src/server.rs | Implements the JSON vs plain startup output switch and JSON schema emission. |
| crates/trigger-http/src/lib.rs | Defines OutputFormat and adds --format flag to HTTP trigger CLI args; wires it into server startup. |
| crates/runtime-config/src/lib.rs | Redirects runtime config summary from stdout to stderr. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ba0c3d8 to
a5b7235
Compare
a5b7235 to
7b4dba6
Compare
|
Thanks for posting the output @ChihweiLHBird. I'd value @rajatjindal's input on this, but my own thoughts are:
|
itowlson
left a comment
There was a problem hiding this comment.
This looks good to me, just a couple of suggestions in the review plus that (wildcard) thing from discussion. Thanks!
tests/integration.rs
Outdated
|
|
||
| let base_url = parsed["base_url"] | ||
| .as_str() | ||
| .context(format!("JSON output missing 'base_url' string field\nGot: {parsed}"))?; |
There was a problem hiding this comment.
The repeated "Got {parsed}" part of this context could, I think, be added outside the helper (you can dump the stdout string, no need to rely on it being parsed). Like on line 145 check_json().with_context(|| format!("Actual output: {stdout}")?. (You might need to make check_json a true function rather than a closure, and pass the text in, to avoid lifetime issues.)
There was a problem hiding this comment.
I think it works with the closure. I just updated it in df789dd. Is there any lifetime issues I'm not aware of?
…ardcode `/` for root route Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
18d6ca6 to
c46cfbf
Compare
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
itowlson
left a comment
There was a problem hiding this comment.
Looks good to me - thanks! I'll give it a little longer for @rajatjindal to provide feedback, but will then merge.
|
I tried out this PR on my laptop, and it works great. Thank you for making those changes. one thing I realized while testing is that with do you think it will be helpful to print this info on stdout as well as put this in a .spin/routeinfo.json or something like that? IIRC, my original usecase was around implementing GitHub actions for Fermyon Cloud, in which case we will usually do In the current shape, if we were to do a deploy using some cloud plugin, will it still print this json info on console, or that depends on implementation of that specific cloud plugin? |
|
@rajatjindal It will depend on the implementation of the deployment plugin. Deployment plugins don't invoke |
Resolve #949
I am a beginner for Rust, so do let me know if there is any better approach in the code I may take.
Summary
--formatCLI flag to the HTTP trigger that supportsplain(default) andjsonoutput formats--format jsonis specified, route and listener information is printed to stdout as machine-readable JSON instead of human-readable textprintln!calls (runtime config, stdio logging, key-value/SQLite summaries) toeprintln!so stdout remains clean for structured outputTest
http_smoke_test_json_format) that verifies JSON output is valid and contains expected fields (routes, listeners)spin up --format jsonprints JSON to stdoutspin up(no flag) behaves as before with plain text outputSample test outputs
spin up --format jsonNote that
Logging component stdio to ".spin/logs/"is shown on screen but it's not instdout. We can use/path/to/spin/target/release/spin up --format json > out.txtto verify itspin up