Repository navigation
Fix 429 'Maximum response size' errors and surface query failures - #26
Conversation
Large projects fail the commands/calls query with "429 Maximum response
size of 200000000 bytes reached". Add msstats.list_time_series, which
halves the time window on a step boundary when that error is returned
and merges the results. Other errors are re-raised unchanged.
- msstats.py: use the helper for the commands query; return {} instead
of (project_id, {}) on error so create_workbooks no longer crashes;
stop memory loops from reusing command results after a failed query
- memorystore.py: use the helper in _list_ts; report every failed query
instead of silently ignoring it, still write the CSV, and exit 1 when
any query failed
- README.md: note that oversized queries are split automatically
- test_msstats.py: cover splitting, error returns and error reporting
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fix for large deployments that hit Cloud Monitoring's 200MB response limit. When a query hits the limit, the script now automatically splits its time range in half, and keeps splitting until each piece fits, then merges the results. Smaller deployments are unaffected and still make a single request. Also fixes error handling in both scripts: msstats.py no longer crashes after a failed query, and Potential impact: Changes are in |
|
P2 follow-up: the XLSX export in I reproduced both cases with simulated responses. This is a pre-existing gap, so I don't see it as a blocker for the commands-query fix in this PR; the follow-up is tracked in #27. Validation: all 36 existing tests passed, along with additional simulated checks for split CSV/XLSX exports across Redis, Valkey, and Redis Cluster. Live queries against the configured GCP project succeeded but returned no Memorystore data in the one-hour window, so recovery from a real oversized response is still unverified. |
Problem
A prospect running
msstats.pyagainst a large production project got:The
commands/callsquery fetches 7 days of 60s rates for every instance × node × command in one request. On larger projects this exceeds Cloud Monitoring's 200 MB limit, which applies to the whole query, so paging doesn't help. After the error:msstats.pycrashed increate_workbooks(the error path returned a tuple instead of a dict).memorystore.pyswallowed the error and wrote a CSV with no throughput or command-category data, with no warning.Changes
msstats.list_time_serieshelper, also used bymemorystore.py. On the "Maximum response size" 429 it halves the time window on a--stepboundary and merges the results, oldest first. Projects that work today still make a single request. Other errors, including quota 429s, are re-raised unchanged.msstats.py{}instead of(project_id, {}), so a failed query no longer crashes the script.memorystore.py: every failed query is printed as an error instead of silently ignored. The CSV is still written exactly as before, and the script exits1if any query failed.--stepand--durationare optional.Behavior changes
memorystore.pyexits1(was0) when any Monitoring query fails. The CSV contents are unchanged. Nothing in the repo reads the exit code (batch_run_memorystore.shignores it).msstats.pynow reports the error and writes an empty workbook instead of crashing with a traceback. Its exit code is unchanged.Testing
pytest test_msstats.py: 36 passed (9 new).black --check *.py: clean.Out of scope (follow-ups)
get_project_from_service_account_and_authenticatereturns before settingGOOGLE_APPLICATION_CREDENTIALS, so service-account JSON files are never actually used../batch_run_msstats.shtwice (the second should bebatch_run_memorystore.sh).🤖 Generated with Claude Code