Skip to content

Commit d9539e5

Browse files
committedJul 24, 2024
build(docker-compose.yml): add prometheus scraper to docker compose
persists prometheus data across restarts
1 parent ac7f659 commit d9539e5

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed
 

‎docker-compose.yml

+18-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ services:
99
#########################################
1010
## Uncomment these lines to start proxy with a config.yaml file ##
1111
# volumes:
12-
# - ./proxy_server_config.yaml:/app/config.yaml
13-
# command: [ "--config", "./config.yaml", "--port", "4000"]
1412
###############################################
1513
ports:
1614
- "4000:4000" # Map the container port to the host, change the host port if necessary
@@ -33,5 +31,23 @@ services:
3331
interval: 1s
3432
timeout: 5s
3533
retries: 10
34+
35+
prometheus:
36+
image: prom/prometheus
37+
volumes:
38+
- prometheus_data:/prometheus
39+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
40+
ports:
41+
- "9090:9090"
42+
command:
43+
- '--config.file=/etc/prometheus/prometheus.yml'
44+
- '--storage.tsdb.path=/prometheus'
45+
- '--storage.tsdb.retention.time=15d'
46+
restart: always
47+
48+
volumes:
49+
prometheus_data:
50+
driver: local
51+
3652

3753
# ...rest of your docker-compose config if any

‎litellm/tests/test_completion.py

+47
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,53 @@ def test_completion_anyscale_with_functions():
25602560
# test_completion_anyscale_with_functions()
25612561

25622562

2563+
def test_completion_azure_extra_headers():
2564+
# this tests if we can pass api_key to completion, when it's not in the env.
2565+
# DO NOT REMOVE THIS TEST. No MATTER WHAT Happens!
2566+
# If you want to remove it, speak to Ishaan!
2567+
# Ishaan will be very disappointed if this test is removed -> this is a standard way to pass api_key + the router + proxy use this
2568+
from httpx import Client
2569+
from openai import AzureOpenAI
2570+
2571+
from litellm.llms.custom_httpx.httpx_handler import HTTPHandler
2572+
2573+
http_client = Client()
2574+
2575+
with patch.object(http_client, "send", new=MagicMock()) as mock_client:
2576+
client = AzureOpenAI(
2577+
azure_endpoint=os.getenv("AZURE_API_BASE"),
2578+
api_version=litellm.AZURE_DEFAULT_API_VERSION,
2579+
api_key=os.getenv("AZURE_API_KEY"),
2580+
http_client=http_client,
2581+
)
2582+
try:
2583+
response = completion(
2584+
model="azure/chatgpt-v-2",
2585+
messages=messages,
2586+
client=client,
2587+
extra_headers={
2588+
"Authorization": "my-bad-key",
2589+
"Ocp-Apim-Subscription-Key": "hello-world-testing",
2590+
"api-key": "my-bad-key",
2591+
},
2592+
)
2593+
print(response)
2594+
pytest.fail("Expected this to fail")
2595+
except Exception as e:
2596+
pass
2597+
2598+
mock_client.assert_called()
2599+
2600+
print(f"mock_client.call_args: {mock_client.call_args}")
2601+
request = mock_client.call_args[0][0]
2602+
print(request.method) # This will print 'POST'
2603+
print(request.url) # This will print the full URL
2604+
print(request.headers) # This will print the full URL
2605+
auth_header = request.headers.get("Authorization")
2606+
print(auth_header)
2607+
assert auth_header == "my-bad-key"
2608+
2609+
25632610
def test_completion_azure_key_completion_arg():
25642611
# this tests if we can pass api_key to completion, when it's not in the env.
25652612
# DO NOT REMOVE THIS TEST. No MATTER WHAT Happens!

‎prometheus.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
global:
2+
scrape_interval: 15s
3+
4+
scrape_configs:
5+
- job_name: 'litellm'
6+
static_configs:
7+
- targets: ['litellm:4000'] # Assuming Litellm exposes metrics at port 4000

0 commit comments

Comments
 (0)
Please sign in to comment.