Skip to content

Commit 61b609f

Browse files
authored
Merge pull request #9673 from BerriAI/litellm_qa_deadlock_fixes
[Reliability] - Ensure new Redis + DB architecture tracks spend accurately
2 parents 5965680 + 55763ae commit 61b609f

File tree

15 files changed

+512
-198
lines changed

15 files changed

+512
-198
lines changed

.circleci/config.yml

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ jobs:
14501450
command: |
14511451
pwd
14521452
ls
1453-
python -m pytest -s -vv tests/*.py -x --junitxml=test-results/junit.xml --durations=5 --ignore=tests/otel_tests --ignore=tests/pass_through_tests --ignore=tests/proxy_admin_ui_tests --ignore=tests/load_tests --ignore=tests/llm_translation --ignore=tests/llm_responses_api_testing --ignore=tests/mcp_tests --ignore=tests/image_gen_tests --ignore=tests/pass_through_unit_tests
1453+
python -m pytest -s -vv tests/*.py -x --junitxml=test-results/junit.xml --durations=5 --ignore=tests/otel_tests --ignore=tests/spend_tracking_tests --ignore=tests/pass_through_tests --ignore=tests/proxy_admin_ui_tests --ignore=tests/load_tests --ignore=tests/llm_translation --ignore=tests/llm_responses_api_testing --ignore=tests/mcp_tests --ignore=tests/image_gen_tests --ignore=tests/pass_through_unit_tests
14541454
no_output_timeout: 120m
14551455

14561456
# Store test results
@@ -1743,6 +1743,96 @@ jobs:
17431743
# Store test results
17441744
- store_test_results:
17451745
path: test-results
1746+
proxy_spend_accuracy_tests:
1747+
machine:
1748+
image: ubuntu-2204:2023.10.1
1749+
resource_class: xlarge
1750+
working_directory: ~/project
1751+
steps:
1752+
- checkout
1753+
- setup_google_dns
1754+
- run:
1755+
name: Install Docker CLI (In case it's not already installed)
1756+
command: |
1757+
sudo apt-get update
1758+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
1759+
- run:
1760+
name: Install Python 3.9
1761+
command: |
1762+
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh --output miniconda.sh
1763+
bash miniconda.sh -b -p $HOME/miniconda
1764+
export PATH="$HOME/miniconda/bin:$PATH"
1765+
conda init bash
1766+
source ~/.bashrc
1767+
conda create -n myenv python=3.9 -y
1768+
conda activate myenv
1769+
python --version
1770+
- run:
1771+
name: Install Dependencies
1772+
command: |
1773+
pip install "pytest==7.3.1"
1774+
pip install "pytest-asyncio==0.21.1"
1775+
pip install aiohttp
1776+
python -m pip install --upgrade pip
1777+
python -m pip install -r requirements.txt
1778+
- run:
1779+
name: Build Docker image
1780+
command: docker build -t my-app:latest -f ./docker/Dockerfile.database .
1781+
- run:
1782+
name: Run Docker container
1783+
# intentionally give bad redis credentials here
1784+
# the OTEL test - should get this as a trace
1785+
command: |
1786+
docker run -d \
1787+
-p 4000:4000 \
1788+
-e DATABASE_URL=$PROXY_DATABASE_URL \
1789+
-e REDIS_HOST=$REDIS_HOST \
1790+
-e REDIS_PASSWORD=$REDIS_PASSWORD \
1791+
-e REDIS_PORT=$REDIS_PORT \
1792+
-e LITELLM_MASTER_KEY="sk-1234" \
1793+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
1794+
-e LITELLM_LICENSE=$LITELLM_LICENSE \
1795+
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
1796+
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
1797+
-e USE_DDTRACE=True \
1798+
-e DD_API_KEY=$DD_API_KEY \
1799+
-e DD_SITE=$DD_SITE \
1800+
-e AWS_REGION_NAME=$AWS_REGION_NAME \
1801+
--name my-app \
1802+
-v $(pwd)/litellm/proxy/example_config_yaml/spend_tracking_config.yaml:/app/config.yaml \
1803+
my-app:latest \
1804+
--config /app/config.yaml \
1805+
--port 4000 \
1806+
--detailed_debug \
1807+
- run:
1808+
name: Install curl and dockerize
1809+
command: |
1810+
sudo apt-get update
1811+
sudo apt-get install -y curl
1812+
sudo wget https://github.com/jwilder/dockerize/releases/download/v0.6.1/dockerize-linux-amd64-v0.6.1.tar.gz
1813+
sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.6.1.tar.gz
1814+
sudo rm dockerize-linux-amd64-v0.6.1.tar.gz
1815+
- run:
1816+
name: Start outputting logs
1817+
command: docker logs -f my-app
1818+
background: true
1819+
- run:
1820+
name: Wait for app to be ready
1821+
command: dockerize -wait http://localhost:4000 -timeout 5m
1822+
- run:
1823+
name: Run tests
1824+
command: |
1825+
pwd
1826+
ls
1827+
python -m pytest -vv tests/spend_tracking_tests -x --junitxml=test-results/junit.xml --durations=5
1828+
no_output_timeout:
1829+
120m
1830+
# Clean up first container
1831+
- run:
1832+
name: Stop and remove first container
1833+
command: |
1834+
docker stop my-app
1835+
docker rm my-app
17461836
17471837
proxy_multi_instance_tests:
17481838
machine:
@@ -2553,6 +2643,12 @@ workflows:
25532643
only:
25542644
- main
25552645
- /litellm_.*/
2646+
- proxy_spend_accuracy_tests:
2647+
filters:
2648+
branches:
2649+
only:
2650+
- main
2651+
- /litellm_.*/
25562652
- proxy_multi_instance_tests:
25572653
filters:
25582654
branches:
@@ -2714,6 +2810,7 @@ workflows:
27142810
- installing_litellm_on_python
27152811
- installing_litellm_on_python_3_13
27162812
- proxy_logging_guardrails_model_info_tests
2813+
- proxy_spend_accuracy_tests
27172814
- proxy_multi_instance_tests
27182815
- proxy_store_model_in_db_tests
27192816
- proxy_build_from_pip_tests

litellm/proxy/_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,3 +2751,9 @@ class DBSpendUpdateTransactions(TypedDict):
27512751
team_list_transactions: Optional[Dict[str, float]]
27522752
team_member_list_transactions: Optional[Dict[str, float]]
27532753
org_list_transactions: Optional[Dict[str, float]]
2754+
2755+
2756+
class SpendUpdateQueueItem(TypedDict, total=False):
2757+
entity_type: Litellm_EntityType
2758+
entity_id: str
2759+
response_cost: Optional[float]

0 commit comments

Comments
 (0)