mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(proxy): guard SlackAlerting periodic_flush start on repeated update_values
update_values(alerting=...) spawned a new periodic_flush task on every call, leaking one task per config reload cycle. Mirror the existing alerting_args guard so exactly one flush task runs per instance.
This commit is contained in:
parent
4123b4bc2b
commit
dca5e6c735
2 changed files with 17 additions and 2 deletions
|
|
@ -137,8 +137,9 @@ class SlackAlerting(CustomBatchLogger):
|
|||
):
|
||||
if alerting is not None:
|
||||
self.alerting = alerting
|
||||
asyncio.create_task(self.periodic_flush())
|
||||
self.periodic_started = True
|
||||
if not self.periodic_started:
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -179,6 +179,20 @@ class TestSlackAlerting(unittest.TestCase):
|
|||
self.slack_alerting.update_values(alerting_args={"slack_alerting": "True"})
|
||||
assert self.slack_alerting.periodic_started == True
|
||||
|
||||
@patch("asyncio.create_task")
|
||||
def test_update_values_alerting_does_not_restart_periodic_task(self, mock_create_task):
|
||||
mock_create_task.return_value = AsyncMock()
|
||||
|
||||
self.assertFalse(self.slack_alerting.periodic_started)
|
||||
|
||||
self.slack_alerting.update_values(alerting=["slack"])
|
||||
self.assertTrue(self.slack_alerting.periodic_started)
|
||||
assert mock_create_task.call_count == 1
|
||||
|
||||
self.slack_alerting.update_values(alerting=["slack"])
|
||||
self.slack_alerting.update_values(alerting=["slack"])
|
||||
assert mock_create_task.call_count == 1
|
||||
|
||||
@patch("litellm.integrations.SlackAlerting.slack_alerting.datetime")
|
||||
def test_alert_type_in_formatted_message(self, mock_datetime):
|
||||
# Setup mocks
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue