Record metrics and charge for HTTP route egress#5505
Open
bradleyshep wants to merge 5 commits into
Open
Conversation
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.
Description of Changes
The HTTP
/sqlendpoint charged for its DB work (rows/bytes scanned, writes) but not for egress, the bytes sent back to the client. WebSocket queries already count these, but the HTTP path skipped it, so the same query was billed over WS and free over HTTP. There were also no metrics on the HTTP routes.This PR:
/sql, using the BSATN size of the result rows so the price matches WebSocket queries./v1middleware that records per-route request count, latency, and body sizes. Body sizes count bytes actually transferred through a smallBodywrapper rather than trusting the Content-Length header, so chunked and streamed bodies are counted and spoofed headers are not. Non-standard HTTP methods are bucketed into anOTHERlabel to keep cardinality bounded.Adds
http-bodyas a direct dependency (already in the tree via axum/hyper).Not covered here: CORS preflights and unmatched 404s are not counted (they short-circuit before the middleware), and routes other than
/sqlare not billed egress yet.API and ABI breaking changes
None. The
/sqlresponse is unchanged, only internal metrics were added.Expected complexity level and risk
Testing
SELECTchargesbytes_sent_to_clientsequal to the rows' BSATN size.SELECTover HTTP bumps the egress counter by the exact BSATN size and thespacetime_http_*counters by the exact wire bytes (checked against curl's size_download).curl -X BANANA) lands in theOTHERbucket, and a chunked request body (no Content-Length) is counted.