Skip to content

Add include_variables option to calculate analytics requests - #1704

Merged
anth-volk merged 4 commits into
mainfrom
feat/analytics-omit-variables
Nov 24, 2026
Merged

anth-volk merged 4 commits into
mainfrom
feat/analytics-omit-variables

Conversation

@anth-volk

@anth-volk anth-volk commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

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 current and frontier workers. Analytics requests carry no version and are routed to current.

Summary

Adds an optional include_variables query parameter to GET /analytics/calculate/requests. The default is true, so existing callers get the same response as today.

With include_variables=false:

  • each request record leaves out its variables key (the key is absent rather than an empty list, which already means "no variables were recorded");
  • the endpoint skips the query over calculate_request_variables;
  • the response envelope is unchanged: no new top-level keys.

The option is ignored when unique=true, though an invalid value still returns 400.

_parse_bool now takes the parameter name, so an invalid value reports include_variables (or unique) instead of always naming unique.

Why

Billing counts requests per month and reads only request_uuid, created_at, client_id and response_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=false before this deploys. It will receive the full response until then.

Testing

New cases in tests/unit/endpoints/test_analytics_endpoint.py:

  • include_variables=false (and 0, no, FALSE) returns each record exactly as the default response does, minus variables, keeps response_status_code for failed requests, never calls the variable-row lookup, and keeps the default envelope keys;
  • the default, include_variables=true, 1, yes and TRUE still return variables;
  • unique=true&include_variables=false still returns unique keys;
  • an invalid or empty include_variables returns 400 naming that parameter, also with unique=true, and an invalid unique still names unique.

Local checks run:

  • the five new test functions (14 cases) and test_openapi_document_is_valid, selected by node ID: all pass;
  • ruff format --check and ruff check on the changed test file: pass;
  • the edited OpenAPI document validated with openapi_spec_validator.

The branch has main merged in (no conflicts; none of main's newer commits touch the analytics endpoint, its OpenAPI entry or its tests).

make test and make test-with-auth weren't run locally; this PR relies on CI for the full suites.

🤖 Generated with Claude Code

anth-volk and others added 4 commits November 4, 2026 15:23
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>
@anth-volk
anth-volk marked this pull request as ready for review November 24, 2026 21:31
@anth-volk
anth-volk merged commit ef7666d into main Nov 24, 2026
6 checks passed
@anth-volk
anth-volk deleted the feat/analytics-omit-variables branch November 24, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let analytics request callers leave out per-request variable lists

1 participant