fix(alerts): repair detector tests and tracing

This commit is contained in:
moe-berri 2026-11-10 14:46:10 -08:00
parent 3d5320d3cb
commit a3482adecf
5 changed files with 28 additions and 23 deletions

View file

@ -261,6 +261,7 @@ _PRISMA_VIEWS: Final[frozenset[str]] = frozenset(
_PRISMA_MODELS: Final[frozenset[str]] = frozenset(
(
"LiteLLM_Alert",
"LiteLLM_PerformanceAlertState",
"LiteLLM_BudgetTable",
"LiteLLM_CredentialsTable",
"LiteLLM_ProxyModelTable",

View file

@ -11877,7 +11877,25 @@ class ProxyStartupEvent:
read_general_settings=_current_general_settings,
)
cls._initialize_performance_alerts_job(scheduler=scheduler, prisma_client=prisma_client)
from litellm.proxy.spend_tracking.performance_alerts import RUN_INTERVAL, run_performance_alerts
from litellm.repositories.performance_alert_repository import PerformanceAlertRepository
performance_alert_repository: Final = PerformanceAlertRepository(prisma_client)
async def run_performance_alerts_job() -> None:
if _current_general_settings().get("performance_alerts_enabled") is True:
await run_performance_alerts(performance_alert_repository)
scheduler.add_job( # pyright: ignore[reportUnknownMemberType] # APScheduler does not provide typed job methods
run_performance_alerts_job,
"interval",
seconds=RUN_INTERVAL.total_seconds(),
id="performance_alerts",
replace_existing=True,
max_instances=1,
coalesce=True,
misfire_grace_time=APSCHEDULER_MISFIRE_GRACE_TIME,
)
### PTU DAILY ROLLUP ###
from litellm.proxy.spend_tracking.ptu_feature_flag import (
@ -12255,28 +12273,6 @@ class ProxyStartupEvent:
"LITELLM_EXPIRED_UI_SESSION_KEY_CLEANUP_ENABLED=true to enable)"
)
@classmethod
def _initialize_performance_alerts_job(cls, scheduler: AsyncIOScheduler, prisma_client: PrismaClient) -> None:
from litellm.proxy.spend_tracking.performance_alerts import RUN_INTERVAL, run_performance_alerts
from litellm.repositories.performance_alert_repository import PerformanceAlertRepository
repository: Final = PerformanceAlertRepository(prisma_client)
async def run() -> None:
if _current_general_settings().get("performance_alerts_enabled") is True:
await run_performance_alerts(repository)
scheduler.add_job( # pyright: ignore[reportUnknownMemberType] # APScheduler does not provide typed job methods
run,
"interval",
seconds=RUN_INTERVAL.total_seconds(),
id="performance_alerts",
replace_existing=True,
max_instances=1,
coalesce=True,
misfire_grace_time=APSCHEDULER_MISFIRE_GRACE_TIME,
)
@classmethod
def _initialize_spend_capture_rate_check_job(
cls,

View file

@ -253,6 +253,7 @@ async def test_model_insights_reads_back_what_the_rollup_wrote() -> None:
"request_tags": '["task:debugging"]',
"custom_llm_provider": "openai",
"status": "success",
"request_duration_ms": None,
}
transactions = (

View file

@ -1656,6 +1656,7 @@ class MockPrisma:
self.database_url = database_url
self.proxy_logging_obj = proxy_logging_obj
self.http_client = http_client
self.writer_db = MagicMock()
async def connect(self):
pass

View file

@ -31397,6 +31397,12 @@ export interface components {
* @description If True (default), a locally-managed user's password must contain an uppercase letter.
*/
password_policy_require_uppercase?: boolean | null;
/**
* Performance Alerts Enabled
* @description Check yesterday's usage for the gateway, models, teams, users and keys against the week before, and save unusual spend, traffic, response time and failure rate changes as alerts. Off by default.
* @default false
*/
performance_alerts_enabled: boolean;
/**
* Plugins
* @description external services registered as embeddable UI plugins