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
fix: fix test
Krrish Dholakiaaa7839e4cbf6
diff --git a/tests/otel_tests/test_prometheus.py b/tests/otel_tests/test_prometheus.pyindex 3a9de555544..02de786d054 100644--- a/tests/otel_tests/test_prometheus.py+++ b/tests/otel_tests/test_prometheus.py@@ -109,12 +109,16 @@ async def test_proxy_failure_metrics():expected_metric_pattern = 'litellm_proxy_failed_requests_metric_total{api_key_alias="None",end_user="None",exception_class="Openai.RateLimitError",exception_status="429",hashed_api_key="88dc28d0f030c55ed4ab77ed8faf098196cb1c05df778539800c9f1243fe6b4b",requested_model="fake-azure-endpoint",route="/chat/completions",team="None",team_alias="None",user="default_user_id",user_email="None"}'# Check if the pattern is in metrics (this metric doesn't include user_email field)- assert any(expected_metric_pattern in line for line in metrics.split('\n')), f"Expected failure metric pattern not found in /metrics. Pattern: {expected_metric_pattern}"-+ assert any(+ expected_metric_pattern in line for line in metrics.split("\n")+ ), f"Expected failure metric pattern not found in /metrics. Pattern: {expected_metric_pattern}"+# Check total requests metric which includes user_emailtotal_requests_pattern = 'litellm_proxy_total_requests_metric_total{api_key_alias="None",end_user="None",hashed_api_key="88dc28d0f030c55ed4ab77ed8faf098196cb1c05df778539800c9f1243fe6b4b",requested_model="fake-azure-endpoint",route="/chat/completions",status_code="429",team="None",team_alias="None",user="default_user_id",user_email="None"}'- assert any(total_requests_pattern in line for line in metrics.split('\n')), f"Expected total requests metric pattern not found in /metrics. Pattern: {total_requests_pattern}"+ assert any(+ total_requests_pattern in line for line in metrics.split("\n")+ ), f"Expected total requests metric pattern not found in /metrics. Pattern: {total_requests_pattern}"@pytest.mark.asyncio@@ -378,7 +382,9 @@ async def test_team_budget_metrics():assert first_budget["total"] == 10.0, "Total budget metric is incorrect"print("first_budget['remaining_hours']", first_budget["remaining_hours"])# Budget should have positive remaining hours, up to 7 days- assert 0 < first_budget["remaining_hours"] <= 168, "Budget should have positive remaining hours, up to 7 days"+ assert (+ 0 < first_budget["remaining_hours"] <= 168+ ), "Budget should have positive remaining hours, up to 7 days"# Get team info and verify spend matches prometheus metricsteam_info = await get_team_info(session, team_id)@@ -510,7 +516,9 @@ async def test_key_budget_metrics():print("first_budget['remaining_hours']", first_budget["remaining_hours"])# The budget reset time is now standardized - for "7d" it resets on Monday at midnight# So we'll check if it's within a reasonable range (0-7 days depending on current day of week)- assert 0 <= first_budget["remaining_hours"] <= 168, "Budget remaining hours should be within a reasonable range (0-7 days depending on day of week)"+ assert (+ 0 <= first_budget["remaining_hours"] <= 168+ ), "Budget remaining hours should be within a reasonable range (0-7 days depending on day of week)"# Get key info and verify spend matches prometheus metricskey_info = await get_key_info(session, key)@@ -570,6 +578,7 @@ async def test_user_email_metrics():user_email in metrics_after_first), "user_email should be tracked correctly"+@pytest.mark.asyncioasync def test_user_email_in_all_required_metrics():"""@@ -579,7 +588,7 @@ async def test_user_email_in_all_required_metrics():- litellm_input_tokens_metric_total- litellm_output_tokens_metric_total- litellm_requests_metric_total- - litellm_spend_metric+ - litellm_spend_metric_total"""async with aiohttp.ClientSession() as session:# Create a user with user_email@@ -611,16 +620,21 @@ async def test_user_email_in_all_required_metrics():"litellm_input_tokens_metric_total","litellm_output_tokens_metric_total","litellm_requests_metric_total",- "litellm_spend_metric"+ "litellm_spend_metric_total",]import re+for metric_name in required_metrics_with_user_email:# Check that the metric exists and contains user_email label# Look for the metric with user_email in its labels- pattern = rf'{metric_name}{{[^}}]*user_email="{re.escape(user_email)}"[^}}]*}}'+ pattern = (+ rf'{metric_name}{{[^}}]*user_email="{re.escape(user_email)}"[^}}]*}}'+ )matches = re.findall(pattern, metrics_text)- assert len(matches) > 0, f"Metric {metric_name} should contain user_email={user_email} but was not found in metrics"+ assert (+ len(matches) > 0+ ), f"Metric {metric_name} should contain user_email={user_email} but was not found in metrics"# Also test failure metric by making a bad requesttry:@@ -639,4 +653,6 @@ async def test_user_email_in_all_required_metrics():# Check that failure metric also contains user_emailfailure_pattern = rf'litellm_proxy_failed_requests_metric_total{{[^}}]*user_email="{re.escape(user_email)}"[^}}]*}}'failure_matches = re.findall(failure_pattern, metrics_text)- assert len(failure_matches) > 0, f"litellm_proxy_failed_requests_metric_total should contain user_email={user_email}"\ No newline at end of file+ assert (+ len(failure_matches) > 0+ ), f"litellm_proxy_failed_requests_metric_total should contain user_email={user_email}"