mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
test(observability): cover the shed counter's telemetry failure guard
The counting runs at the response boundary, so a metrics failure there would turn a served 429 into no response at all. The guard existed but nothing exercised it, which is the one uncovered line the patch report was pointing at.
This commit is contained in:
parent
792f120aef
commit
f9d4ef8e6f
1 changed files with 34 additions and 0 deletions
|
|
@ -205,3 +205,37 @@ def test_the_shed_metric_documents_exactly_the_statuses_it_counts(monkeypatch):
|
|||
documented = {int(value.strip()) for value in advertised.group(1).split(",")}
|
||||
|
||||
assert documented == set(_SHED_STATUSES)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_failure_counting_a_shed_response_still_returns_the_response():
|
||||
"""The counting rides the response boundary, so a metrics failure there would
|
||||
otherwise turn a served 429 into no response at all."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from litellm.proxy.common_utils.request_pressure_metrics import mark_request_shed_by_proxy
|
||||
from litellm.proxy.middleware.in_flight_requests_middleware import (
|
||||
InFlightRequestsMiddleware,
|
||||
)
|
||||
|
||||
sent = []
|
||||
|
||||
async def send(message):
|
||||
sent.append(message)
|
||||
|
||||
async def receive():
|
||||
return {"type": "http.request"}
|
||||
|
||||
async def app(scope, receive, send):
|
||||
mark_request_shed_by_proxy()
|
||||
await send({"type": "http.response.start", "status": 429, "headers": []})
|
||||
await send({"type": "http.response.body", "body": b""})
|
||||
|
||||
with patch(
|
||||
"litellm.integrations.prometheus.PrometheusLogger.get_instance",
|
||||
side_effect=RuntimeError("metrics down"),
|
||||
):
|
||||
await InFlightRequestsMiddleware(app)({"type": "http"}, receive, send)
|
||||
|
||||
assert [m["type"] for m in sent] == ["http.response.start", "http.response.body"]
|
||||
assert sent[0]["status"] == 429
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue