Runtime bump, CI Machete move, and real response_size metric - #230
Merged
Conversation
The metrics middleware read response_size from the response Content-Length header, but axum wraps handler responses in a streaming body with no such header at that point, so it was ~always 0. Add CountingBody, an http_body::Body wrapper that tallies data-frame bytes as they stream (never buffers) and fires a callback with the total at end-of-stream or on early drop. The metrics middleware wraps the response body and logs "request completed" (with the real response_size) from that callback. Works for JSON, downloads, and SSE alike; request_size is unchanged (Content-Length is correct for request bodies). Also bump the nvisy-engine/runtime git dep to latest main (bd96ed9 -> 3e805a7). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Match the runtime repo's layout: the unused-dependency check (cargo-machete) belongs alongside the other build-quality gates (fmt, clippy, docs), not in the Security workflow next to cargo-deny and secret scanning. Security keeps deny and the secret scan. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Housekeeping across three fronts: bump the runtime engine, tidy CI to match runtime's layout, and fix a long-standing metrics inaccuracy.
Runtime bump
Bump the
nvisy-engine/ runtime git dep to latestmain(bd96ed9→3e805a7). No code changes required — check, clippy, and tests all pass against the new revision.CI: move Machete from Security → Build
The unused-dependency check (
cargo-machete) now lives in the Build workflow alongside the other build-quality gates (fmt, clippy, docs), matching the runtime repo's layout, instead of sitting in the Security workflow next tocargo-denyand secret scanning. Security keepsdenyand the secret scan.Fix:
response_sizemetric was always 0The metrics middleware read
response_sizefrom the response'sContent-Lengthheader, but axum wraps handler responses in a streaming body that carries no such header at the point the middleware runs — so every response loggedresponse_size=0, even a 200 JSON one.Add
CountingBody, anhttp_body::Bodywrapper that tallies data-frame bytes as they stream (never buffers) and fires a callback with the total at end-of-stream, or on early drop (client disconnect). The metrics middleware wraps the response body and emits the"request completed"line — now with the real byte count — from that callback. Correct for JSON, file/audit downloads, and SSE streams alike.request_sizeis unchanged (the client'sContent-Lengthis already correct for request bodies; 0 for bodyless GETs).Behavior note: for a streamed response the
"request completed"log now fires when the body finishes (for a long-lived SSE connection, when it closes) rather than at handler return — which is genuinely when the response completes.Testing
Full gate green:
cargo check,cargo clippy -D warnings,cargo test— all pass with the bumped runtime.cargo machetepasses locally (the newhttp-bodydep is used). Three unit tests coverCountingBody(completion count, empty body, early drop).🤖 Generated with Claude Code