Repository navigation
Add include_variables option to calculate analytics requests - #1704
Merged
Merged
Conversation
With include_variables=false, GET /analytics/calculate/requests leaves the variables key out of each request record and skips the query over calculate_request_variables. Callers that only count requests, such as billing, no longer download variable usage they never read. The default stays true, so existing responses are unchanged. The boolean parser now names the parameter that failed to parse instead of always naming `unique`. Fixes #1703 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The omit test now covers false, 0, no and FALSE, and checks each record against the default record without its variables key and the envelope against the default envelope. The default and invalid-value tests cover the remaining spellings, an empty value, and an invalid value with unique=true. The OpenAPI note says the option is ignored when unique is true but is still validated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An empty commit: GitHub did not attach the previous push to the pull request. Co-Authored-By: Claude Opus 5.5 <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.
Fixes #1703
Modal Version Release
None. This is a code-only change with no US or UK package version change, so the release workflow's code-only deploy redeploys both the
currentandfrontierworkers. Analytics requests carry noversionand are routed tocurrent.Summary
Adds an optional
include_variablesquery parameter toGET /analytics/calculate/requests. The default istrue, so existing callers get the same response as today.With
include_variables=false:variableskey (the key is absent rather than an empty list, which already means "no variables were recorded");calculate_request_variables;The option is ignored when
unique=true, though an invalid value still returns 400._parse_boolnow takes the parameter name, so an invalid value reportsinclude_variables(orunique) instead of always namingunique.Why
Billing counts requests per month and reads only
request_uuid,created_at,client_idandresponse_status_code. Each record is about 526 bytes plus about 246 bytes per variable row. For a client that sends about 20 variables per request, a 9,500-request month is about 52 MB, over Cloud Run's 32 MiB buffered-response limit, with 17–32 seconds of server time. Without the variable lists the same page is roughly 5 MB, and the second query is skipped.#1702 (chunked transfer for responses over 16 MiB) stays a separate safeguard. This PR doesn't depend on it.
Compatibility
The endpoint ignores query options it doesn't know, so a caller can start sending
include_variables=falsebefore this deploys. It will receive the full response until then.Testing
New cases in
tests/unit/endpoints/test_analytics_endpoint.py:include_variables=false(and0,no,FALSE) returns each record exactly as the default response does, minusvariables, keepsresponse_status_codefor failed requests, never calls the variable-row lookup, and keeps the default envelope keys;include_variables=true,1,yesandTRUEstill return variables;unique=true&include_variables=falsestill returns unique keys;include_variablesreturns 400 naming that parameter, also withunique=true, and an invaliduniquestill namesunique.Local checks run:
test_openapi_document_is_valid, selected by node ID: all pass;ruff format --checkandruff checkon the changed test file: pass;openapi_spec_validator.The branch has
mainmerged in (no conflicts; none ofmain's newer commits touch the analytics endpoint, its OpenAPI entry or its tests).make testandmake test-with-authweren't run locally; this PR relies on CI for the full suites.🤖 Generated with Claude Code