The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Infra] Split slow proxy-db shards to hit 7m wall-clock target
Yuneng Jiange0201ece1ed8
diff --git a/.github/workflows/_test-unit-services-base.yml b/.github/workflows/_test-unit-services-base.ymlindex 9de3ac3cf5f..766516d266e 100644--- a/.github/workflows/_test-unit-services-base.yml+++ b/.github/workflows/_test-unit-services-base.yml@@ -37,6 +37,11 @@ on:required: falsetype: stringdefault: "loadscope"+ keyword:+ description: "Optional pytest -k expression to filter tests (e.g. 'test_a or test_c')"+ required: false+ type: string+ default: ""artifact-name:description: "Unique name for the coverage artifact (must be unique per run)"required: false@@ -130,8 +135,15 @@ jobs:WORKERS: ${{ inputs.workers }}RERUNS: ${{ inputs.reruns }}DIST: ${{ inputs.dist }}+ KEYWORD: ${{ inputs.keyword }}DATABASE_URL: ${{ inputs.enable-postgres && secrets.DATABASE_URL || '' }}run: |+ # Build optional -k filter as an array so expressions with spaces+ # (e.g. "test_a or test_b") stay a single argv entry to pytest.+ K_ARGS=()+ if [ -n "${KEYWORD}" ]; then+ K_ARGS=(-k "${KEYWORD}")+ fiif [ "${WORKERS}" = "0" ]; thenuv run --no-sync pytest ${TEST_PATH:?} \--tb=short -vv \@@ -141,7 +153,8 @@ jobs:--durations=20 \--cov=litellm \--cov-report=xml:coverage.xml \- --cov-config=pyproject.toml+ --cov-config=pyproject.toml \+ "${K_ARGS[@]}"elseuv run --no-sync pytest ${TEST_PATH:?} \--tb=short -vv \@@ -153,7 +166,8 @@ jobs:--durations=20 \--cov=litellm \--cov-report=xml:coverage.xml \- --cov-config=pyproject.toml+ --cov-config=pyproject.toml \+ "${K_ARGS[@]}"fi- name: Save coverage reportdiff --git a/.github/workflows/test-unit-proxy-db.yml b/.github/workflows/test-unit-proxy-db.ymlindex 0f2694984e0..b6b6fc0368f 100644--- a/.github/workflows/test-unit-proxy-db.yml+++ b/.github/workflows/test-unit-proxy-db.yml@@ -17,13 +17,20 @@ concurrency:# to whichever group it belongs to, not reshuffling slices.## Design targets:-# * Every shard runs in <= 7 minutes on a 4-core runner.+# * Every shard runs in <= 7 minutes of wall-clock on the default runner.+# Setup + xdist worker spawn + coverage teardown is ~3 minutes per shard,+# so each shard's pytest runtime must stay under ~4 minutes. That drives+# the split granularity: shards get subdivided when pytest call time+# exceeds ~4m or any single test exceeds ~3m (it pins one xdist worker).# * test_key_generate_prisma.py stays serial (workers=0) — it has event-loop# conflicts with the logging worker when run in parallel.-# * test_proxy_utils.py runs in its own shard with --dist=worksteal so xdist-# spreads its ~64 functions (many parametrized) across workers instead of-# pinning the whole file to a single worker (the default --dist=loadscope-# behavior for single-file targets).+# * test_proxy_utils.py is split into two -k-filtered shards (by first+# character of the test function name) so its 188 parametrized cases+# fan out across two runners rather than one. --dist=worksteal within+# each shard balances parametrized cases across xdist workers.+# * test_db_schema_migration.py is isolated because one test in it+# (test_aaaasschema_migration_check) takes ~170s — by itself it+# determines the shard's wall-clock floor.jobs:# Fast guard — fails the workflow if a test_*.py file under# tests/proxy_unit_tests/ is not referenced by any matrix entry below.@@ -42,7 +49,7 @@ jobs:- name: Assert every test_*.py is in a matrix shardrun: |python3 - <<'PY'- import pathlib, re, sys, yaml+ import pathlib, sys, yamlwf = yaml.safe_load(open(".github/workflows/test-unit-proxy-db.yml"))matrix = wf["jobs"]["proxy-db"]["strategy"]["matrix"]["include"]referenced = set()@@ -60,9 +67,7 @@ jobs:for o in orphans:print(f" - {o}")print()- print("Add each to whichever semantic shard (auth-and-jwt, proxy-server,")- print("logging-and-callbacks, db-and-spend, guardrails-budget-hooks,")- print("endpoints-and-responses, proxy-utils, key-generation) it belongs to.")+ print("Add each to whichever semantic shard it belongs to.")sys.exit(1)print(f"OK: all {len(actual)} files assigned to a shard.")PY@@ -82,12 +87,20 @@ jobs:test-path: "tests/proxy_unit_tests/test_key_generate_prisma.py"workers: 0dist: loadscope+ keyword: ""timeout: 20- - test-group: auth-and-jwt+ # ---- auth: split into 2 shards (was 1 at ~10.4m wall-clock) ----+ - test-group: auth-checkstest-path: >-tests/proxy_unit_tests/test_auth_checks.pytests/proxy_unit_tests/test_user_api_key_auth.py+ workers: 8+ dist: loadscope+ keyword: ""+ timeout: 15+ - test-group: jwt-and-keys+ test-path: >-tests/proxy_unit_tests/test_jwt.pytests/proxy_unit_tests/test_jwt_key_mapping.pytests/proxy_unit_tests/test_proxy_custom_auth.py@@ -95,16 +108,38 @@ jobs:tests/proxy_unit_tests/test_deployed_proxy_keygen.pyworkers: 8dist: loadscope+ keyword: ""timeout: 15- # Own shard, --dist=worksteal so parametrized cases fan out across workers.- - test-group: proxy-utils+ # ---- test_proxy_utils.py split into 2 by -k (was 1 at ~9.7m) ----+ # Same file, same --dist=worksteal, filtered by first char of test+ # function name. Keywords below cover all 63 test functions in the+ # file. If new functions are added, balance between the two shards.+ - test-group: proxy-utils-a-htest-path: "tests/proxy_unit_tests/test_proxy_utils.py"workers: 8dist: worksteal+ keyword: >-+ test_add or test_check or test_custom or test_during or+ test_dynamic or test_end_user or test_enforced or test_foward or+ test_get_admin or test_get_complete or test_get_docs or+ test_get_known or test_get_model_group or test_get_openapi or+ test_get_redoc or test_get_temp or test_get_user_info or+ test_handle or test_health+ timeout: 15+ - test-group: proxy-utils-i-z+ test-path: "tests/proxy_unit_tests/test_proxy_utils.py"+ workers: 8+ dist: worksteal+ keyword: >-+ test_is or test_litellm or test_merge or test_post_call or+ test_prepare or test_provider or test_proxy_config or+ test_reading or test_spend or test_team or test_traceparent or+ test_update or test_get_key or test_get_teamtimeout: 15- - test-group: proxy-server+ # ---- proxy server: split into 2 shards (was 1 at ~11.1m) ----+ - test-group: proxy-server-coretest-path: >-tests/proxy_unit_tests/test_proxy_server.pytests/proxy_unit_tests/test_proxy_server_keys.py@@ -112,6 +147,12 @@ jobs:tests/proxy_unit_tests/test_proxy_server_langfuse.pytests/proxy_unit_tests/test_proxy_server_spend.pytests/proxy_unit_tests/test_aproxy_startup.py+ workers: 8+ dist: loadscope+ keyword: ""+ timeout: 15+ - test-group: proxy-runtime+ test-path: >-tests/proxy_unit_tests/test_proxy_config_unit_test.pytests/proxy_unit_tests/test_proxy_routes.pytests/proxy_unit_tests/test_proxy_gunicorn.py@@ -120,25 +161,44 @@ jobs:tests/proxy_unit_tests/test_proxy_token_counter.pyworkers: 8dist: loadscope+ keyword: ""timeout: 15- - test-group: logging-and-callbacks+ # ---- logging: split into 2 shards (was 1 at ~10.1m) ----+ - test-group: custom-loggingtest-path: >-tests/proxy_unit_tests/test_custom_callback_input.pytests/proxy_unit_tests/test_custom_logger_s3_gcs.pytests/proxy_unit_tests/test_proxy_custom_logger.py+ workers: 8+ dist: loadscope+ keyword: ""+ timeout: 15+ - test-group: logging-misc+ test-path: >-tests/proxy_unit_tests/test_proxy_reject_logging.pytests/proxy_unit_tests/test_audit_logs_proxy.pytests/proxy_unit_tests/test_search_api_logging.pyworkers: 8dist: loadscope+ keyword: ""timeout: 15+ # ---- db-and-spend: split out the 170s schema-migration test ----+ # test_db_schema_migration.py has one test that runs ~170s; it+ # single-handedly pins one xdist worker and determined the whole+ # shard's 12.3m wall-clock. Isolated here so the other 45 tests+ # finish faster.+ - test-group: schema-migration+ test-path: "tests/proxy_unit_tests/test_db_schema_migration.py"+ workers: 8+ dist: loadscope+ keyword: ""+ timeout: 15- test-group: db-and-spendtest-path: >-tests/proxy_unit_tests/test_prisma_client_backoff_retry.pytests/proxy_unit_tests/test_db_schema_changes.py- tests/proxy_unit_tests/test_db_schema_migration.pytests/proxy_unit_tests/test_e2e_pod_lock_manager.pytests/proxy_unit_tests/test_skills_db.pytests/proxy_unit_tests/test_update_daily_tag_spend.py@@ -147,20 +207,30 @@ jobs:tests/proxy_unit_tests/test_proxy_encrypt_decrypt.pyworkers: 8dist: loadscope+ keyword: ""timeout: 15- - test-group: guardrails-budget-hooks+ # ---- guardrails + budget + hooks: split into 2 (was 1 at ~10.1m) ----+ - test-group: guardrails-hookstest-path: >-tests/proxy_unit_tests/test_proxy_setting_guardrails.pytests/proxy_unit_tests/test_banned_keyword_list.py+ tests/proxy_unit_tests/test_unit_test_proxy_hooks.py+ workers: 8+ dist: loadscope+ keyword: ""+ timeout: 15+ - test-group: budgets+ test-path: >-tests/proxy_unit_tests/test_default_end_user_budget_simple.pytests/proxy_unit_tests/test_unit_test_max_model_budget_limiter.pytests/proxy_unit_tests/test_zero_cost_model_budget_bypass.py- tests/proxy_unit_tests/test_unit_test_proxy_hooks.pyworkers: 8dist: loadscope+ keyword: ""timeout: 15+ # Already under 7m; left as a single shard.- test-group: endpoints-and-responsestest-path: >-tests/proxy_unit_tests/test_blog_posts_endpoint.py@@ -181,6 +251,7 @@ jobs:tests/proxy_unit_tests/test_model_response_typingworkers: 8dist: loadscope+ keyword: ""timeout: 15uses: ./.github/workflows/_test-unit-services-base.ymlwith:@@ -190,6 +261,7 @@ jobs:timeout-minutes: ${{ matrix.timeout }}enable-postgres: truedist: ${{ matrix.dist }}+ keyword: ${{ matrix.keyword }}artifact-name: proxy-db-${{ matrix.test-group }}secrets:DATABASE_URL: ${{ secrets.DATABASE_URL }}