mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
Fix Slack alerting not working if using a DB (#10370)
* Try to add prints
* more print
* fix print
* batch debugging
* Change batch size
* Revert "Change batch size"
This reverts commit af16d8635f.
* Look into periodic task problems
* Fix missing periodic in slack init
* Initialize periodic flush on startup
* Log update_values
* more logging
* Fix startup
* Cleanup change
* Add a unit test for the change
* Renamed and moved to standard
* Merging in with new test
* comment change
* Extend the timeout because normal runs are over 5 min
This commit is contained in:
parent
b8b78f1fde
commit
78c264d7a5
2 changed files with 18 additions and 1 deletions
|
|
@ -85,6 +85,7 @@ class SlackAlerting(CustomBatchLogger):
|
|||
self.alerting_args = SlackAlertingArgs(**alerting_args)
|
||||
self.default_webhook_url = default_webhook_url
|
||||
self.flush_lock = asyncio.Lock()
|
||||
self.periodic_started = False
|
||||
super().__init__(**kwargs, flush_lock=self.flush_lock)
|
||||
|
||||
def update_values(
|
||||
|
|
@ -99,12 +100,17 @@ class SlackAlerting(CustomBatchLogger):
|
|||
if alerting is not None:
|
||||
self.alerting = alerting
|
||||
asyncio.create_task(self.periodic_flush())
|
||||
self.periodic_started = True
|
||||
if alerting_threshold is not None:
|
||||
self.alerting_threshold = alerting_threshold
|
||||
if alert_types is not None:
|
||||
self.alert_types = alert_types
|
||||
if alerting_args is not None:
|
||||
self.alerting_args = SlackAlertingArgs(**alerting_args)
|
||||
if not self.periodic_started:
|
||||
asyncio.create_task(self.periodic_flush())
|
||||
self.periodic_started = True
|
||||
|
||||
if alert_to_webhook_url is not None:
|
||||
# update the dict
|
||||
if self.alert_to_webhook_url is None:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import os
|
|||
import sys
|
||||
import unittest
|
||||
from typing import List, Optional, Tuple
|
||||
from unittest.mock import ANY, MagicMock, Mock, patch
|
||||
from unittest.mock import ANY, AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../../..")
|
||||
|
|
@ -161,3 +161,14 @@ class TestSlackAlerting(unittest.TestCase):
|
|||
)
|
||||
self.assertEqual(event, "soft_budget_crossed")
|
||||
self.assertTrue("Total Soft Budget" in event_message)
|
||||
|
||||
# Calling update_values with alerting args should try to start the periodic task
|
||||
@patch("asyncio.create_task")
|
||||
def test_update_values_starts_periodic_task(self, mock_create_task):
|
||||
# Make it do nothing (or return a dummy future)
|
||||
mock_create_task.return_value = AsyncMock() # prevents awaiting errors
|
||||
|
||||
assert(self.slack_alerting.periodic_started == False)
|
||||
|
||||
self.slack_alerting.update_values(alerting_args={"slack_alerting": "True"})
|
||||
assert(self.slack_alerting.periodic_started == True)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue