mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-22 06:06:59 +00:00
feat(admin): add events feed, fleet-wide rejections and span rankings
GET /admin/api/events returns recent failures, newest first. It covers rate limits, budget and unpriced-model refusals, upstream errors, timeouts and capacity rejections. Events go into an in-process ring of 200 entries and are copied to a Redis list (llmgw:events, LPUSH plus LTRIM to 200). The copy happens only on the error path, is throttled to 50 per second per replica, and never blocks a request. When Redis is absent or down, the feed falls back to this replica's ring. Messages are fixed strings or scrubbed provider errors. Fields are assigned one at a time, because Yaegi drops values from a multi-value assignment that contains a call. Rejections per day are counted per scope and in total, in the same store call that already rolls back a rejected request. /admin/api/usage returns them as rejectionsPerDay. /admin/api/usage/models accepts span, which sums that many buckets, and prefix, which filters model ids before the limit applies. The overview reports the replica id, the instance name and the warnings logged while the middleware was built. The failover and retry fan-out warning is now logged at WARN. Claude-Session: https://claude.ai/code/session_01V5jYJNxpDFdJkyyExpADrv
This commit is contained in:
@@ -1800,6 +1800,7 @@ func TestHandlePassthrough_UnpricedModelCostBudget_Returns402(t *testing.T) {
|
||||
wantCode int
|
||||
allowUnpricedWithCostBudget bool
|
||||
wantUpstreamCalled bool
|
||||
wantEvent bool // item 5, this round: the 402 refusal must reach the events feed
|
||||
}{
|
||||
{
|
||||
name: "unpriced model, cost budget configured: refused",
|
||||
@@ -1808,6 +1809,7 @@ func TestHandlePassthrough_UnpricedModelCostBudget_Returns402(t *testing.T) {
|
||||
costBudget: 5,
|
||||
wantCode: http.StatusPaymentRequired,
|
||||
wantUpstreamCalled: false,
|
||||
wantEvent: true,
|
||||
},
|
||||
{
|
||||
name: "unpriced model, no cost budget: passes",
|
||||
@@ -1881,6 +1883,22 @@ func TestHandlePassthrough_UnpricedModelCostBudget_Returns402(t *testing.T) {
|
||||
if upstreamCalled != tt.wantUpstreamCalled {
|
||||
t.Errorf("upstreamCalled = %v, want %v", upstreamCalled, tt.wantUpstreamCalled)
|
||||
}
|
||||
if tt.wantEvent {
|
||||
events := h.(*Gateway).events.ring.snapshot(eventRingCap)
|
||||
if len(events) == 0 {
|
||||
t.Fatal("want an event recorded for the 402 refusal, got none")
|
||||
}
|
||||
ev := events[0] // newest first
|
||||
if ev.Kind != eventKindUnpriced {
|
||||
t.Errorf("Kind = %q, want %q", ev.Kind, eventKindUnpriced)
|
||||
}
|
||||
if ev.Status != http.StatusPaymentRequired {
|
||||
t.Errorf("Status = %d, want %d", ev.Status, http.StatusPaymentRequired)
|
||||
}
|
||||
if ev.Route != routePassthrough {
|
||||
t.Errorf("Route = %q, want %q", ev.Route, routePassthrough)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user