mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(shared-state): rate-limit the loop's store error logs
A Redis outage logged one line per refresh and per failed write. The loop now logs at most one store error per 30 seconds, the interval the limiter already uses.
This commit is contained in:
@@ -324,3 +324,39 @@ func TestSharedStateIdleStopsDuringOutageAfterFailWindow(t *testing.T) {
|
||||
waitLoop(t, l, false)
|
||||
l.close()
|
||||
}
|
||||
|
||||
func TestSharedStateErrorLogsAreRateLimited(t *testing.T) {
|
||||
store, clk := sharedTestEnv()
|
||||
var mu sync.Mutex
|
||||
var lines []string
|
||||
l := newSharedStateLoop(store, nil, func(f string, a ...any) {
|
||||
mu.Lock()
|
||||
lines = append(lines, f)
|
||||
mu.Unlock()
|
||||
})
|
||||
l.nowFn = clk.now
|
||||
l.closed = true
|
||||
l.lossy = func(f func()) { f() }
|
||||
b := testBreaker(l)
|
||||
store.setFail(errors.New("redis down"))
|
||||
store.setFailIncr(errors.New("redis down"))
|
||||
count := func() int {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return len(lines)
|
||||
}
|
||||
for i := 0; i < 50; i++ {
|
||||
b.recordFailure("p")
|
||||
l.refresh()
|
||||
l.write([]counterIncr{{key: "k", delta: 1, ttl: time.Minute}})
|
||||
}
|
||||
if got := count(); got != 1 {
|
||||
t.Fatalf("%d error lines inside one interval, want 1", got)
|
||||
}
|
||||
clk.advance(sharedStateErrorLogEvery + time.Second)
|
||||
b.recordFailure("p")
|
||||
l.refresh()
|
||||
if got := count(); got != 2 {
|
||||
t.Errorf("%d error lines after the interval, want 2", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user