litellm/tests/test_litellm/proxy/utils/prisma_and_spend
Yassin Kortam 40b8300ac2
fix(spend): bound each spend-log write statement by row count as well as bytes (#37758)
The Prisma query engine is a separate process whose resident memory grows with
what it is asked to hold and glibc never returns it, so a pod's memory floor
ratchets up to its worst statement and stays there for the life of the worker.
#34956 bounded a spend-log flush by payload bytes, which caps that floor when
prompts are stored and does nothing when they are not: rows carrying only
attribution metadata run about 1.2 KB, so a 1000-row statement is roughly
1.2 MB, the 2 MB byte budget never binds, and every statement stays at 1000
rows forever.

The engine charges per row as well as per byte. Measured on a container running
the same engine build (5.4.2) against real Postgres, with rows shaped like a
store_prompts_in_spend_logs=false deployment, writing the same 200,000 rows:

  rows/statement   engine RSS still resident after the flush
  1000             179 MB
  500               91 MB
  250               41 MB
  100               19 MB

None of those statements came near the byte budget, so the whole difference is
row count. The floor is a plateau rather than a leak: 1,000,000 rows written at
1000 per statement settles around 229 MB and stops climbing.

Adds SPEND_LOG_WRITE_BATCH_MAX_ROWS, default 100, applied alongside the
existing byte budget so whichever binds first splits the statement. Both are
needed, since bytes are what track a prompt-carrying row and rows are what
track the engine's per-row bookkeeping.

One consequence worth naming: a flush now issues more statements, and a
statement that fails under a poison flood costs one insert before any
isolation runs, so the irreducible floor rises by the statement count. The
isolation budget still caps the amplification on top of that, and the tests
assert the bound derived from the configured row cap rather than a constant.
2026-08-21 09:49:51 -07:00
..
__init__.py test(proxy/utils): pin PrismaClient and spend-update behavior (#29488) 2026-06-02 17:45:28 -07:00
_harness_smoke_test.py test(proxy/utils): pin PrismaClient and spend-update behavior (#29488) 2026-06-02 17:45:28 -07:00
conftest.py fix(spend): stop losing spend log rows when a flush is cancelled (#34826) 2026-08-12 20:10:50 -07:00
test_cache_user_row.py test(proxy/utils): pin PrismaClient and spend-update behavior (#29488) 2026-06-02 17:45:28 -07:00
test_config_param_cache.py test(proxy/utils): pin PrismaClient and spend-update behavior (#29488) 2026-06-02 17:45:28 -07:00
test_password_helpers.py test(proxy/utils): pin PrismaClient and spend-update behavior (#29488) 2026-06-02 17:45:28 -07:00
test_prisma_client_engine_watcher.py fix(proxy): recover Prisma DB reconnect loop when client is disconnected 2026-07-07 09:50:27 +03:00
test_prisma_client_get_data.py fix(proxy): force prisma recreate on postgres cached-plan error (#36428) 2026-08-14 15:04:01 -07:00
test_prisma_client_health.py test(proxy/utils): pin PrismaClient and spend-update behavior (#29488) 2026-06-02 17:45:28 -07:00
test_prisma_client_lifecycle.py feat(proxy): authenticate to Azure Postgres with Microsoft Entra ID tokens 2026-08-20 11:50:16 -07:00
test_prisma_client_reconnect.py fix(proxy): force prisma recreate on postgres cached-plan error (#36428) 2026-08-14 15:04:01 -07:00
test_prisma_client_writes.py fix(proxy): never log raw virtual keys in key insertion debug output (#33268) 2026-07-14 16:32:26 -07:00
test_proxy_update_spend.py fix(spend): bound each spend-log write statement by row count as well as bytes (#37758) 2026-08-21 09:49:51 -07:00
test_send_email.py fix(proxy): support SMTP implicit SSL (port 465) (#30395) 2026-06-13 14:34:43 -07:00
test_spend_functions.py fix(spend): stop losing spend log rows when a flush is cancelled (#34826) 2026-08-12 20:10:50 -07:00