mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
Added tests for ignoring 0 metrics when alerting
This commit is contained in:
parent
b490c289ca
commit
30332a6d68
1 changed files with 45 additions and 0 deletions
|
|
@ -359,3 +359,48 @@ async def test_send_llm_exception_to_slack():
|
|||
)
|
||||
|
||||
await asyncio.sleep(3)
|
||||
|
||||
|
||||
# test models with 0 metrics are ignored
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_daily_reports_ignores_zero_values():
|
||||
router = MagicMock()
|
||||
router.get_model_ids.return_value = ['model1', 'model2', 'model3']
|
||||
|
||||
slack_alerting = SlackAlerting(internal_usage_cache=MagicMock())
|
||||
# model1: failed=None, latency=0; model2: failed=0, latency=0; model3: failed=10, latency=None
|
||||
slack_alerting.internal_usage_cache.async_batch_get_cache = AsyncMock(return_value=[None, 0, 0, 0, 10, None])
|
||||
|
||||
router.get_model_info.side_effect = lambda x: {"litellm_params": {"model": x}}
|
||||
|
||||
with patch.object(slack_alerting, 'send_alert', new=AsyncMock()) as mock_send_alert:
|
||||
result = await slack_alerting.send_daily_reports(router)
|
||||
|
||||
# Check that the send_alert method was called
|
||||
mock_send_alert.assert_called_once()
|
||||
message = mock_send_alert.call_args[1]['message']
|
||||
|
||||
# Ensure the message includes only the non-zero, non-None metrics
|
||||
assert "model3" in message
|
||||
assert "model2" not in message
|
||||
assert "model1" not in message
|
||||
|
||||
assert result == True
|
||||
|
||||
|
||||
# test no alert is sent if all None or 0 metrics
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_daily_reports_all_zero_or_none():
|
||||
router = MagicMock()
|
||||
router.get_model_ids.return_value = ['model1', 'model2', 'model3']
|
||||
|
||||
slack_alerting = SlackAlerting(internal_usage_cache=MagicMock())
|
||||
slack_alerting.internal_usage_cache.async_batch_get_cache = AsyncMock(return_value=[None, 0, None, 0, None, 0])
|
||||
|
||||
with patch.object(slack_alerting, 'send_alert', new=AsyncMock()) as mock_send_alert:
|
||||
result = await slack_alerting.send_daily_reports(router)
|
||||
|
||||
# Check that the send_alert method was not called
|
||||
mock_send_alert.assert_not_called()
|
||||
|
||||
assert result == False
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue