Repository navigation
fix(proxy-extras): backport the automatic SpendLogs index build (#43948, #44109, #44203) to stable/1.104.x - #50823
Conversation
…nstead of in migrations (#43948) The two SpendLogs index migrations shipped in v1.103.0 each break one table shape: the plain CREATE INDEX holds a SHARE lock on a large unpartitioned table and the CONCURRENTLY one fails with 0A000 on a partitioned parent. Both files are now inert and the indexes are built by a table-driven, shape-aware step after migrate deploy: CONCURRENTLY on a plain table, ON ONLY the parent plus per-partition CONCURRENTLY and ATTACH PARTITION on a partitioned one. The migration job builds them synchronously and exits non-zero on failure; a serving proxy that ran migrate deploy itself builds them in the background off the readiness path. A valid index of the same definition under another name is renamed and reused, an invalid one is rebuilt, and extra copies are reported with their DROP INDEX statement instead of being dropped. The migration checker rejects any CREATE INDEX on LiteLLM_SpendLogs or LiteLLM_ErrorLogs in future migrations Co-authored-by: yassin <yassin@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit c66c828)
… the migration job builds indexes (#44203) The migration job runs DatabaseURLSettings.apply_to_env(), which rewrites DATABASE_SSLMODE=verify-full plus DATABASE_SSLROOTCERT into Prisma's TLS dialect: sslmode=require&sslcert=<CA>&sslaccept=strict. The request-log index build then hands that same URL to psycopg, and libpq reads sslcert as a client certificate, failing with "certificate present, but not private key file" on every verify-full deployment since #43948. _strip_prisma_query_params now undoes the Prisma dialect before psycopg sees the URL. sslaccept=strict (or any value Prisma treats as strict) becomes sslrootcert=<CA> plus sslmode=verify-full whatever sslmode said, since strict verifies chain and hostname and libpq only does that in verify-full; sslmode=disable stays off. Without strict, Prisma verifies nothing, so the CA is dropped and sslmode is kept as is. A URL that also carries sslkey is libpq's own client-certificate form and is left alone. Resolves LIT-9169 Co-authored-by: yassin <yassin@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 4758fce)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This reverts commit 1e80763.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
[High impact] The latest changes appear safe to merge, with no new blocking issue found SummaryBackports automatic builds for the two missing
Reviews (2) · Last reviewed commit: "fix(proxy): support PostgreSQL 10 reques..." · Reviewed by Greptile |
|
bugbot run |
Use the operator-class vector to count index keys across PostgreSQL versions and cover missing, equivalent and INCLUDE indexes with live catalog tests Type the backported tests, construct environments without mutation and inject startup dependencies while preserving automatic index builds Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 7085864. Configure here.
Handwritten 1-3 sentence description
Proxies on 1.104 with a large spend logs table never get the call ID index, so opening a request in the Logs page scans the whole table and times out. This backports the automatic, non-blocking index build that ships in 1.105 so those proxies build the index themselves after migrations
TLDR
Problem this solves:
SELECT 1, nothing builds themHow it solves it:
migrate deploy_filter_migration_job_owned_driftFinal, injected startup calls instead of patched class methods)User Flow
Before: an admin on 1.104 with a large spend logs table and no call ID index cannot open any request's details
After: the proxy builds the index in the background after migrations, so the drawer opens
Affected release
Regression in v1.103.0, still present on every 1.104.x
Pre-Submission checklist
Screenshots / Proof of Fix
Tests at the tip
7085864085, against local Postgres for the migration tests587 passedtests/proxy_migration_tests/test_request_log_indexes.pyandtest_invalid_index_repair.pyon Postgres 14,39 passed2 passed, 1 skipped(INCLUDE indexes need Postgres 11). The old SQL fails both cases there1 passedatd30a921dfeLive before/after against a large spend logs table has not been run yet, see Caveats
Type
🐛 Bug Fix
Caveats (if any)
Severe
Medium
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/b0bf3c680bdd430b98bc809296bc8168
Open in Devin Desktop: https://app.devin.ai/desktop/session/b0bf3c680bdd430b98bc809296bc8168?variant=devin
Requested by: @mateo-berri
Note
High Risk
Changes core database migration and online DDL paths for high-volume SpendLogs tables, including partitioned installs, advisory locking, and concurrent index builds that can run for a long time and need disk headroom.
Overview
LiteLLM_SpendLogs indexes declared in Prisma are no longer created in shipped migrations. The two affected migration files become inert (
SELECT 1), and a newrequest_log_indexesmodule buildsapi_key/startTimeandlitellm_call_idindexes afterprisma migrate deploy—concurrently on plain tables and per-partition on partitioned spend logs, under the migration coordinator lock with bounded lock waits.The migration Job and proxy startup paths are wired so the job runs
setup_databasethen waits for index builds (run_migration_job); a serving proxy that migrates on boot starts the same work on a daemon thread after readiness. Recovery can roll back a failed ledger row when this build ships an inert migration file, and drift filtering now treats these as migration-job-owned indexes. DATABASE_URL is translated for libpq/psycopg (Prisma TLS semantics), and invalid-index repair yields to the same advisory lock.Migration lint now flags
CREATE INDEXon request-log tables, with docs pointing new indexes atREQUEST_LOG_INDEXES.Reviewed by Cursor Bugbot for commit 7085864. Bugbot is set up for automated code reviews on this repo. Configure here.